import { Map } from 'immutable'
import errorsShowingReducer from '../errorsShowing'
import {
  clearErrorsShowing,
  showError,
  hideError
} from '../../actions/errorsShowing'

describe('errorsShowing reducer', () => {
  it('clears the errors showing', () => {
    const initialState = Map({
      reactComponentUniq1: true,
      reactComponentUniq2: false
    })

    const action = clearErrorsShowing()
    const nextState = errorsShowingReducer(initialState, action)

    expect(nextState.equals(Map())).to.equal(true)
  })

  it('adds a component to the list when SHOW_ERROR', () => {
    const initialState = Map({
      reactComponentUniq1: true,
      reactComponentUniq2: false
    })

    const action = showError('reactComponentUniq3')
    const nextState = errorsShowingReducer(initialState, action)

    expect(nextState.get('reactComponentUniq3')).to.equal(true)
  })

  it('adds changes a false to true with SHOW_ERROR', () => {
    const initialState = Map({
      reactComponentUniq1: true,
      reactComponentUniq2: false
    })

    const action = showError('reactComponentUniq2')
    const nextState = errorsShowingReducer(initialState, action)

    expect(nextState.get('reactComponentUniq2')).to.equal(true)
  })

  it('sets a component to false with HIDE_ERROR', () => {
    const initialState = Map({
      reactComponentUniq1: true,
      reactComponentUniq2: false
    })

    const action = hideError('reactComponentUniq1')
    const nextState = errorsShowingReducer(initialState, action)

    expect(nextState.get('reactComponentUniq1')).to.equal(false)
  })

  it('returns the original state with bad action', () => {
    const initialState = Map({reactComponentUniq1: true})
    const action = Map({type: 'SOME_OTHER_TYPE'})
    const nextState = errorsShowingReducer(initialState, action)

    expect(nextState).to.equal(initialState)
  })
})
