import { mapStateToProps } from '../index'

import Item from '../../../../../../../common/records/Item'
import QuizEntry from '../../../../../../../common/records/QuizEntry'

describe('QuizEntryEditFooter', () => {
  const sandbox = sinon.createSandbox()

  const item = new Item({ id: '66' })
  const workingItem = new Item({
    id: '66',
    properties: {
      varyPointsByAnswer: false
    }
  })
  sandbox.stub(item, 'getWorkingInstance').returns(workingItem)

  const quizItemEntry = new QuizEntry({
    id: '55',
    entryType: 'Item',
    entryId: 66,
    pointsPossible: 12,
    position: 3
  })

  const quizBankEntry = new QuizEntry({
    id: '56',
    entryType: 'BankEntry',
    entryId: 77,
    pointsPossible: 12,
    position: 3
  })

  const quizStimulusEntry = new QuizEntry({
    id: '56',
    entryType: 'Stimulus',
    entryId: 88,
    pointsPossible: 12,
    position: 3
  })

  const workingQuizEntry = new QuizEntry({
    id: '55',
    pointsPossible: 3999
  })
  sandbox.stub(workingQuizEntry, 'getItem').returns(item)

  const defaultProps = {
    entry: item,
    workingQuizEntry
  }

  describe('mapStateToProps', () => {
    context('when quizEntry.isItem', () => {
      it('gets item from workingQuizEntry', () => {
        const mapped = mapStateToProps({}, {
          ...defaultProps,
          quizEntry: quizItemEntry
        })
        expect(mapped.workingEntry).to.equal(item)
      })
    })

    context('when quizEntry.isBankEntry', () => {
      it('gets item from workingQuizEntry', () => {
        const mapped = mapStateToProps({}, {
          ...defaultProps,
          quizEntry: quizBankEntry
        })
        expect(mapped.workingEntry).to.equal(item)
      })
    })

    context('when quizEntry is not an item or bank entry', () => {
      it('gets working instance from entry', () => {
        const mapped = mapStateToProps({}, {
          ...defaultProps,
          quizEntry: quizStimulusEntry
        })
        expect(mapped.workingEntry).to.equal(workingItem)
      })
    })
  })
})
