import { fromJS, Map } from 'immutable'

import Bank from '../../../../common/records/Bank'

import AddToBankModal, { mapStateToProps } from '../index'

describe('AddToBankModal Container', () => {
  const ConnectedAddToBankModal = withContext(AddToBankModal, {banks: {1: {}}})
  const testbed = createTestbed(ConnectedAddToBankModal, {
    modalOpen: true,
    temporaryBank: {},
    errorsShowing: Map(),
    createBank: sinon.stub(),
    changeBank: sinon.stub(),
    clearModifications: sinon.stub(),
    errorShowingActions: {},
    closeModal: sinon.stub()
  })

  useFakeFetching({dispatchStub: sinon.stub(),
    getStateStub: sinon.stub(),
    fetchStub: sinon.stub()})

  shouldRenderComponent(testbed, {}, AddToBankModal)

  it('should map open modal to its entry', () => {
    const props = mapStateToProps(
      fromJS({ modal: { isOpen: 'ADD_TO_BANK_MODAL:Item:1' } }),
      { entryId: '1', entryType: 'Item' }
    )
    expect(props.modalOpen).to.be.true()
  })

  it('should map modal selection state to Bank record', () => {
    const props = mapStateToProps(fromJS({
      banks: { 2: { title: 'Excellent Bank' } },
      ui: { ADD_TO_BANK_MODAL_BANK_SELECTION: '2' }
    }), {})
    expect(props.selectedBank).to.be.an.instanceof(Bank)
    expect(props.selectedBank.title).to.eq('Excellent Bank')
  })
})
