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

import itemsReducer from '../items'
import { addItems } from '../../actions/items'

import Item from '../../records/Item'

describe('items reducer', () => {
  describe('addItem', () => {
    it('should add new items with ADD_ITEMS action', () => {
      const initialState = fromJS({})
      const action = addItems([{id: '1', itemBody: 'qi'}])
      const nextState = itemsReducer(initialState, action)

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

    it('should replace items with ADD_ITEMS action', () => {
      const initialState = fromJS({
        1: new Item({id: '1', itemBody: 'initial'})
      })
      const action = addItems([
        {id: '1', itemBody: 'nextOne'},
        {id: '2', itemBody: 'nextTwo'}
      ])
      const nextState = itemsReducer(initialState, action)

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

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