'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

exports.default = function (testbed, messages) {
  describe('toggleEditing', function () {
    var notifyStub = sinon.stub();
    var switchOnEditingStub = sinon.stub();
    var saveQuizChange = sinon.stub();

    afterEach(function () {
      notifyStub.reset();
      switchOnEditingStub.reset();
      saveQuizChange.reset();
    });

    var toggleEditing = function toggleEditing() {
      return testbed.subject.toggleEditing ? testbed.subject.toggleEditing() : testbed.getRefs().composedComponent.toggleEditing();
    };

    context('isEditing is true', function () {
      it('calls the toggle saveQuizChange prop', function () {
        testbed.render({ saveQuizChange: saveQuizChange, isEditing: true });
        toggleEditing();

        expect(saveQuizChange.called).to.be.true();
      });

      it('notifies the screenreader if editing mode is turned off', function () {
        testbed.render({ screenreaderNotification: notifyStub, isEditing: true });
        toggleEditing();

        expect(notifyStub.calledWith(messages.turnedOff)).to.be.true();
      });
    });

    context('isEditing is false', function () {
      it('calls the toggle switchOnEditing prop', function () {
        testbed.render({ switchOnEditing: switchOnEditingStub, isEditing: false });
        toggleEditing();

        expect(switchOnEditingStub.called).to.be.true();
      });

      it('notifies the screenreader if editing mode is turned on', function () {
        testbed.render({ screenreaderNotification: notifyStub, isEditing: false });
        toggleEditing();

        expect(notifyStub.calledWith(messages.turnedOn)).to.be.true();
      });
    });
  });
};