import { fromJS, Map } from 'immutable'

import BankEntryRow from '../index'

import BankEntryRecord from '../../../../common/records/BankEntry'
import { setFakeStore, unsetFakeStore } from '../../../../reduxStore'
import { withTestFeatures } from '../../../../common/util/featureCheck'

describe('connected BankEntryRow', () => {
  const fakeState = fromJS({
    items: { 1: { id: '1', itemBody: 'First entry' } }
  })

  const bankEntry = new BankEntryRecord({
    id: '123',
    updatedAt: new Date(),
    entryType: 'Item',
    entry: Map({ id: '1', schema: 'Item' })
  })
  const connectedTestbed = createTestbed(
    withContext(BankEntryRow, {
      ui: {
        BANK_ENTRY_123_EXPANDED: true
      },
      tagAssociations: {
        'Item': {
          '1': [{
            id: '1',
            tag_id: '1',
            tag_value: 'tagme'
          }]
        }
      }
    }),
    {
      navigateToBankEntry: () => {},
      bankEntry
    }
  )

  before(() => setFakeStore(fakeState))

  after(() => unsetFakeStore())

  it('gets expanded state', () => {
    connectedTestbed.render()
    expect(connectedTestbed.getText()).to.include('Last Update')
  })

  describe('with tagging', () => {
    withTestFeatures(['item_bank_tagging'])

    it('renders tags', () => {
      connectedTestbed.render()
      expect(connectedTestbed.getText()).to.include('tagme')
    })
  })

  describe('a11y tests', () => {
    it('should meet a11y standards', (done) => {
      connectedTestbed.render()
      connectedTestbed.checkA11yStandards(done)
    })
  })
})
