import { fromJS } from 'immutable'
import Select from '@instructure/ui-forms/lib/components/Select'

import BankSelection from '../presenter'
import Bank from '../../../../records/Bank'

describe('BankSelection', () => {
  const bankSelectionProps = {
    banks: fromJS([new Bank({ id: '1' }), new Bank({ id: '2' })]),
    selectedBank: new Bank({ id: '1' })
  }
  const testbed = createTestbed(BankSelection, bankSelectionProps)
  const shallowtestbed = testbed.renderShallowly()

  it('renders the Select component', () => {
    expect(shallowtestbed.find(Select).length).to.equal(1)
  })

  it('passes the label properly', () => {
    const labelRender = testbed.renderShallowly({
      label: 'Whatsit'
    })
    expect(labelRender.find(Select).props().label).to.equal('Whatsit')
  })

  it('passes additional parameters properly', () => {
    const labelRender = testbed.renderShallowly({
      foo: 'bar'
    })
    expect(labelRender.find(Select).props().foo).to.equal('bar')
  })

  it('renders all the banks as options', () => {
    const autocomplete = shallowtestbed.find(Select)
    const options = autocomplete.find('option')
    expect(options.length).to.equal(2)
  })

  it('renders errors if the selected bank is archived', () => {
    const errorRender = testbed.renderShallowly({
      selectedBank: new Bank({ archived: true })
    })
    const autocomplete = errorRender.find(Select)
    expect(autocomplete.prop('messages').length).to.eq(1)
    expect(autocomplete.prop('messages')[0].type).to.eq('error')
    expect(autocomplete.prop('messages')[0].text).to.include('Please select a valid bank')
  })
})
