import { Map } from 'immutable'
import { expect } from 'chai'
import editingReducer from '../editing'
import { startEdit, endEdit } from '../../actions/editing'

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

    const action = startEdit('reactComponentUniq3')
    const nextState = editingReducer(initialState, action)

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

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

    const action = startEdit('reactComponentUniq2')
    const nextState = editingReducer(initialState, action)

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

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

    const action = endEdit('reactComponentUniq1')
    const nextState = editingReducer(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: 'something else'})
    const nextState = editingReducer(initialState, action)

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