import { List } from 'immutable'

import ItemRecord from '../../../../common/records/Item'
import BankEntryRecord from '../../../../common/records/BankEntry'
import BankEntriesList from '../presenter'
import BankEntryRow from '../../BankEntryRow'

describe('BankEntriesList', () => {
  const navigateToBankEntryStub = sinon.stub()
  const bankEntries = List([
    new BankEntryRecord({ entry: new ItemRecord({ id: 1, itemBody: 'First entry' }) }),
    new BankEntryRecord({ entry: new ItemRecord({ id: 2, itemBody: 'Second item' }) })
  ])
  const testbed = createTestbed(BankEntriesList, {
    bankEntries,
    navigateToBankEntry: navigateToBankEntryStub
  })

  it('renders bank entries', () => {
    const output = testbed.renderShallowly()
    const rows = output.find(BankEntryRow)
    expect(rows.length).to.eq(2)
  })

  it('navigates to bank entry', () => {
    const output = testbed.renderShallowly()
    const rows = output.find(BankEntryRow)
    rows.first().props().navigateToBankEntry()
    expect(navigateToBankEntryStub).to.be.calledOnce()
  })
})
