import {
  CLOSE_MODERATE_TRAY,
  MODERATE_TRAY_CLOSED,
  OPEN_MODERATE_TRAY
} from '@instructure/quiz-common/lib/constants'
import moderationReducer from '../moderation'

import { fromJS } from 'immutable'


describe('moderationReducer', () => {
  const state = fromJS({ key: 'value' })

  context('on receiving the CLOSE_MODERATE_TRAY action', () => {
    it('sets trayOpen to false', () => {
      const action = { type: CLOSE_MODERATE_TRAY }
      expect(moderationReducer(state, action).toJS()).to.deep.equal({ ...state.toJS(), trayOpen: false })
    })
  })

  context('on receiving the MODERATE_TRAY_CLOSED action', () => {
    it('clears selectedParticipantName', () => {
      const action = { type: MODERATE_TRAY_CLOSED }
      expect(moderationReducer(state.set('selectedParticipantName', 'Bob'), action).toJS()).to.deep.equal({
        ...state.toJS(),
        selectedParticipantName: null,
        selectedSessions: []
      })
    })
  })

  context('on receiving the OPEN_MODERATE_TRAY action', () => {
    const participant = { name: 'ohai', quizSessionIds: ['1'] }
    const action = { type: OPEN_MODERATE_TRAY, participant }

    it('sets trayOpen to true', () => {
      expect(moderationReducer(state, action).toJS()).to.deep.include({ ...state.toJS(), trayOpen: true })
    })

    it('sets selectedParticipantName', () => {
      expect(moderationReducer(state, action).get('selectedParticipantName')).to.equal(participant.name)
    })

    it('sets selectedSessions', () => {
      expect(moderationReducer(state, action).get('selectedSessions').toJS()).to.deep.equal(['1'])
    })
  })
})
