import {fromJS} from 'immutable'
import { expect } from 'chai'
import alertsReducer from '../alerts'
import {
  ADD_ALERT,
  REMOVE_ALERT
} from '@instructure/quiz-common/lib/constants'

describe('alerts reducer', () => {
  it('adds an alert by its uuid', () => {
    const initialState = fromJS({})
    const alertID = '123454321'
    const alertPayload = {
      uuid: alertID,
      otherAttr: 'bar'
    }

    const action = {
      type: ADD_ALERT,
      payload: alertPayload
    }
    const nextState = alertsReducer(initialState, action)

    expect(nextState.get(alertID).equals(fromJS(alertPayload))).to.be.true()
  })

  it('removes an alert by uuid', () => {
    const initialState = fromJS({aaa: 1, bbb: 2})
    const action = {
      type: REMOVE_ALERT,
      payload: {uuid: 'bbb'}
    }
    const nextState = alertsReducer(initialState, action)

    expect(nextState.equals(fromJS({aaa: 1}))).to.be.true()
  })
})
