import { Map, fromJS } from 'immutable'
import { expect } from 'chai'
import sideBarReducer from '../sidebar'

import {
  toggleSidebar,
  setSidebarStimulusIsShowing
} from '../../actions/sidebar'

describe('sidebar reducer', () => {
  it('handles TOGGLE_SIDEBAR with isOpen false', () => {
    const initialState = Map({isOpen: false})
    const action = toggleSidebar()
    const nextState = sideBarReducer(initialState, action)

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

  it('handles TOGGLE_SIDEBAR with isOpen true', () => {
    const initialState = Map({isOpen: true})
    const action = toggleSidebar()
    const nextState = sideBarReducer(initialState, action)

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

  it('returns the original state with bad action', () => {
    const initialState = Map({isOpen: false})
    const action = Map({type: 'something else'})
    const nextState = sideBarReducer(initialState, action)

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

  it('handles SET_SIDEBAR_STIMULUS_IS_SHOWING', () => {
    const initialState = fromJS({3: true})
    const action = setSidebarStimulusIsShowing('3', false)
    const nextState = sideBarReducer(initialState, action)

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