import { fromJS } from 'immutable'
import { expect } from 'chai'

import InteractionType from 'quiz-interactions/lib/records/InteractionType'

import interactionTypesReducer from '../interactionTypes'
import {
  addInteractionTypes
} from '../../actions/addInteractionTypes'

describe('interaction types reducer', () => {
  it('should add new types with ADD_INTERACTION_TYPES action', () => {
    const initialState = fromJS({})
    const action = addInteractionTypes([{id: 1, slug: 'qi'}])
    const nextState = interactionTypesReducer(initialState, action)

    const nextItem = nextState.get('1').get('slug')
    expect(nextItem).to.equal('qi')
  })

  it('should replace types with ADD_INTERACTION_TYPES action', () => {
    const initialState = fromJS({
      1: new InteractionType({id: 1, slug: 'initial'})
    })
    const action = addInteractionTypes([
      {id: 1, slug: 'nextOne'},
      {id: 2, slug: 'nextTwo'}
    ])
    const nextState = interactionTypesReducer(initialState, action)

    const nextItemOne = nextState.get('1').get('slug')
    expect(nextItemOne).to.equal('nextOne')

    const nextItemTwo = nextState.get('2').get('slug')
    expect(nextItemTwo).to.equal('nextTwo')
  })
})
