export default (testbed, messages) => {
  describe('toggleEditing', () => {
    const notifyStub = sinon.stub()
    const switchOnEditingStub = sinon.stub()
    const saveQuizChange = sinon.stub()

    afterEach(() => {
      notifyStub.reset()
      switchOnEditingStub.reset()
      saveQuizChange.reset()
    })

    const toggleEditing = () => {
      return testbed.subject.toggleEditing
        ? testbed.subject.toggleEditing()
        : testbed.getRefs().composedComponent.toggleEditing()
    }

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

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

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

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

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

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

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

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