import { Map } from 'immutable'
import { shouldFocus } from '../index'
import { DELETED_QUIZ_ENTRY } from '@instructure/quiz-common/lib/constants'

describe('#shouldFocus', () => {
  const shared = (expected, deletedQuizEntry, props) => {
    const fakeState = Map({ui: Map({[DELETED_QUIZ_ENTRY]: deletedQuizEntry})})
    expect(shouldFocus(fakeState, props)).to.equal(expected)
  }

  it('returns true when position matches and both in stimulus', () => {
    shared(true,
      { position: 3, inStimulus: true },
      { position: 3, stimulusId: '4' }
    )
  })

  it('returns true when position matches and neither in stimulus', () => {
    shared(true,
      { position: 3, inStimulus: false },
      { position: 3 }
    )
  })

  it('returns true if position is zero and first question was deleted', () => {
    shared(true,
      { position: 1, inStimulus: false },
      { position: 0 }
    )
  })

  it('returns false if positions do not match', () => {
    shared(false,
      { position: 4, inStimulus: false },
      { position: 3 }
    )
  })

  it('returns false if stimulus does not match', () => {
    shared(false,
      { position: 3, inStimulus: false },
      { position: 3, stimulusId: '5' }
    )
  })
})
