import { fromJS, List } from 'immutable'
import BanksList, { mapStateToProps } from '../index'

describe('connected BanksList', () => {
  const fakeState = fromJS({ banks: {
    1: { id: '1', title: 'B', updatedAt: Date.now() },
    2: { id: '2', title: 'A', updatedAt: Date.now() }
  } })

  describe('mapStateToProps', () => {
    it('maps recordIds to banks state', () => {
      const props = mapStateToProps(fakeState, { recordIds: ['2', '1'] })
      expect(props.banks.map((b) => b.title).toJS()).to.eql(['A', 'B'])
    })
  })

  describe('BanksList Container', () => {
    const ConnectedBanksList = withContext(BanksList)
    const testbed = createTestbed(ConnectedBanksList, {
      setUi: sinon.stub(),
      openModal: sinon.stub(),
      navigateToBank: sinon.stub(),
      banks: new List(),
      recordIds: []
    })
    useFakeFetching({dispatchStub: sinon.stub(),
      getStateStub: sinon.stub(),
      fetchStub: sinon.stub()}
    )

    shouldRenderComponent(testbed, {}, BanksList)
  })
})
