import { fromJS } from 'immutable'
import * as taking from '../sessionItems'

const testState = fromJS({
  quizSessions: {
    activeQuizSessionId: 3
  },
  sessionItems: {
    '5': {
      position: 1,
      quizSessionId: 6,
      id: 5
    },
    '3': {
      position: 2,
      quizSessionId: 3,
      id: 3
    },
    '1': {
      position: 7,
      quizSessionId: 3,
      id: 1
    },
    '4': {
      position: 1,
      quizSessionId: 3,
      id: 4
    }
  }
})

describe('session item selectors', () => {
  describe('getItemByPosition', () => {
    it('defaults to null', () => {
      const result = taking.getItemByPosition(testState, 0)
      expect(result).to.eq(null)
    })

    it('gets the correct item', () => {
      const result = taking.getItemByPosition(testState, 7)
      expect(result.get('id')).to.eq(1)
    })

    it('ignores non-active session items', () => {
      const result = taking.getItemByPosition(testState, 1)
      expect(result.get('id')).to.eq(4)
    })
  })
})