import { List } from 'immutable'
import InteractionType from 'quiz-interactions/lib/records/InteractionType'
import Button from '@instructure/ui-buttons/lib/components/Button'

import InteractionTypes from '../presenter'

describe('InteractionTypes', () => {
  const addItemStub = sinon.stub()
  const addStimulusStub = sinon.stub()
  const testbed = createTestbed(InteractionTypes, {
    addItem: addItemStub,
    addStimulus: addStimulusStub,
    types: List([]),
    columns: 2,
    stimulusOn: true,
    stimulusBankingOn: true
  })
  const fakeInteractionType = (name = 'choice') => new InteractionType({name})

  const types = List([
    fakeInteractionType(),
    fakeInteractionType('multi-answer'),
    fakeInteractionType('hotspot')
  ])

  const ShallowTestbed = testbed.renderShallowly({
    allowStimulusCreation: false,
    types: types
  })

  it('should show one button per interactionType', () => {
    const buttons = ShallowTestbed.find(Button)
    expect(buttons.length).to.be.equal(3)
  })

  it('should pass fluidWidth to each button', () => {
    ShallowTestbed.find(Button).forEach((button) => {
      expect(button.prop('fluidWidth')).to.eq(true)
    })
  })

  it('should show a button when stimulus creation is allowed', () => {
    const ShallowTestbed = testbed.renderShallowly({
      allowStimulusCreation: true,
      types: types
    })
    const buttons = ShallowTestbed.find(Button)
    expect(buttons.length).to.be.equal(4)
  })

  it('should call add item on click', () => {
    const buttons = ShallowTestbed.find(Button)
    buttons.first().simulate('click')
    expect(addItemStub.called).to.be.true()
  })

  it('should call add stimulus on click', () => {
    const ShallowTestbed = testbed.renderShallowly({
      allowStimulusCreation: true,
      types: types
    })
    const buttons = ShallowTestbed.find(Button)
    buttons.last().simulate('click')
    expect(addStimulusStub.called).to.be.true()
  })
})
