import { Map } from 'immutable'
import scrollingReducer from '../scrolling'

import {
  scrollToItem,
  clearsScrolledComponentKey
} from '../../actions/scrolling'

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

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

  it('handles SCROLL_TO_COMPONENT without scrollingFocus', () => {
    const initialState = Map({scrolledComponentKey: '3'})
    const action = scrollToItem('5')
    const nextState = scrollingReducer(initialState, action)

    expect(nextState.get('scrolledComponentKey')).to.equal('5')
    expect(nextState.get('scrollingFocus')).to.equal(true)
  })

  it('handles SCROLL_TO_COMPONENT with scrollingFocus false', () => {
    const initialState = Map({scrolledComponentKey: '3'})
    const action = scrollToItem('5', false)
    const nextState = scrollingReducer(initialState, action)

    expect(nextState.get('scrolledComponentKey')).to.equal('5')
    expect(nextState.get('scrollingFocus')).to.equal(false)
  })

  it('handles CLEAR_SCROLLED_COMPONENT', () => {
    const initialState = Map({scrolledComponentKey: '3'})
    const action = clearsScrolledComponentKey()
    const nextState = scrollingReducer(initialState, action)

    expect(nextState.get('scrolledComponentKey')).to.equal(null)
    expect(nextState.get('scrollingFocus')).to.equal(null)
  })
})
