import { fromJS, Map } from 'immutable'

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

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

describe('CopyMoveBankEntryModal Container', () => {
  const ConnectedCopyMoveBankEntryModal = withContext(CopyMoveBankEntryModal, {banks: {1: {}}})
  const testbed = createTestbed(ConnectedCopyMoveBankEntryModal, {
    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, {}, CopyMoveBankEntryModal)

  it('should map open modal to its entry', () => {
    const props = mapStateToProps(
      fromJS({ modal: { isOpen: 'COPY_MOVE_BANK_ENTRY_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: { COPY_MOVE_BANK_ENTRY_MODAL_BANK_SELECTION: '2' }
    }), {})
    expect(props.selectedBank).to.be.an.instanceof(Bank)
    expect(props.selectedBank.title).to.eq('Excellent Bank')
  })
})
