import InteractionType from 'quiz-interactions/lib/records/InteractionType'
import ChoiceEditComponent from 'quiz-interactions/lib/components/multiple_choice/Edit'

import createTestbed from '../../../../../../../tests/util/react-testbed'
import ItemOverride from '../presenter'
import withContext from '../../../../../../../tests/util/withContext'

import Item from '../../../../../records/Item'
import QuizEntry from '../../../../../records/QuizEntry'

describe('Item Override', () => {
  const ItemWithContext = withContext(ItemOverride)
  const type = new InteractionType({ name: 'Multiple Choice', slug: 'choice' })
  const item = new Item({
    id: '333',
    title: 'Difficult Question',
    interactionData: {
      choices: [
        { id: 'id1', itemBody: 'George Washington', position: 1 },
        { id: 'id2', itemBody: 'Alexander Hamilton.', position: 2 }
      ]
    },
    itemBody: 'body',
    scoringData: {
      value: 'id1'
    }
  })
  const quizEntry = new QuizEntry({ id: '222' })
  sinon.stub(item, 'getInteractionType').returns(type)
  const changePropertiesStub = sinon.stub()

  const testbed = createTestbed(ItemWithContext, {
    changeQuizEntryProperties: changePropertiesStub,
    entry: item,
    guid: '333',
    quizEntry
  })

  it('renders interaction in override mode', () => {
    testbed.render()
    const interaction = testbed.findChildByType(ChoiceEditComponent)
    expect(interaction.props.overrideEditableForItem).to.be.true()
    expect(
      testbed.findChildrenBySelector('input[type="radio"][aria-disabled="true"]'),
      'Expected choice buttons to be disabled'
    ).to.have.length(2)
  })

  it('passes the correct oneQuestionAtATime value to the interaction', () => {
    testbed.render({
      oneQuestionAtATime: true
    })
    const component = testbed.findChildByType(ChoiceEditComponent)
    expect(component.props.oneQuestionAtATime).to.be.true()
  })
})
