import { fromJS } from 'immutable'
import { mapStateToProps } from '../index'

describe('connected PaginatedCollection', () => {
  const fakeState = fromJS({ ui: {
    COMPONENT_KEY: { total: 2, current: 1, contents: { 1: [1, 2, 3] } }
  } })
  const fakeProps = {
    stateKey: 'COMPONENT_KEY'
  }

  describe('mapStateToProps', () => {
    it('maps stateKey to pagination data', () => {
      const props = mapStateToProps(fakeState, fakeProps)
      expect(props.totalPages).to.eq(2)
      expect(props.currentPage).to.eq(1)
      expect(props.contents.toJS()).to.eql({ 1: [1, 2, 3] })
    })

    it('has reasonable defaults when pagination data is not present', () => {
      const props = mapStateToProps(fakeState, 'ANOTHER_KEY')
      expect(props.totalPages).to.eq(0)
      expect(props.currentPage).to.eq(1)
      expect(props.contents.toJS()).to.eql({})
    })
  })
})
