import { fromJS } from 'immutable'

import reducer from '../reporting'

import * as actions from '../../actions/reporting'

describe('reporting reducer', () => {
  describe('addItemAnalyses', () => {
    it('updates state correctly', () => {
      const initialState = fromJS({})
      const action = actions.addItemAnalyses([{itemId: '1', points: 1}])
      const nextState = reducer(initialState, action)

      const nextAnalysisState = nextState.getIn(['item_analysis', '1']).get('points')
      expect(nextAnalysisState).to.equal(1)
    })
  })

  describe('addQuizAnalysis', () => {
    it('updates state correctly', () => {
      const initialState = fromJS({})
      const action = actions.addQuizAnalysis([{quizId: '1', points: 2}])
      const nextState = reducer(initialState, action)

      const nextAnalysisState = nextState.getIn(['quiz_analysis', '1']).get('points')
      expect(nextAnalysisState).to.equal(2)
    })
  })

  describe('QuizAnalysisNotFound', () => {
    it('updates state correctly', () => {
      const initialState = fromJS({})
      const action = actions.markQuizAnalysisNotFound('1')
      const nextState = reducer(initialState, action)

      const nextAnalysisState = nextState.getIn(['quiz_analysis', '1']).get('notFound')
      expect(nextAnalysisState).to.equal(true)
    })
  })

  describe('ItemAnalysisNotFound', () => {
    it('updates state correctly', () => {
      const initialState = fromJS({})
      const action = actions.markItemAnalysisNotFound('1')
      const nextState = reducer(initialState, action)

      const nextAnalysisState = nextState.getIn(['item_analysis', '1']).get('notFound')
      expect(nextAnalysisState).to.equal(true)
    })
  })

  describe('toggleItemAnalysisRow', () => {
    it('updates state correctly', () => {
      const initialState = fromJS({item_analysis_row_open: {1: {isOpen: true}}})
      const action = actions.toggleItemAnalysisRowExpanded('1')
      const nextState = reducer(initialState, action)

      const nextAnalysisState = nextState.getIn(['item_analysis_row_open', '1'])
      expect(nextAnalysisState).to.equal(false)
    })
  })
})
