import QuizEntry from '../index'
import InteractionType from 'quiz-interactions/lib/records/interactions/multiple_choice'

import { fromJS } from 'immutable'
import BankEntry from '../../../../../../common/records/BankEntry'
import Item from '../../../../../../common/records/Item'
import QuizEntryRecord from '../../../../../../common/records/QuizEntry'
import { withTestFeatures } from '../../../../../../common/util/featureCheck'
import { wrapInDragAndDropTestContext } from '../../../../../../../tests/util/dndTestUtils'

describe('connected QuizEntry', () => {
  const intType = new InteractionType({})
  const item = new Item({id: '100', itemBody: '<div>first</div>&amp;<div>second</div>'})
  const bankEntry = new BankEntry({id: '11', 'entryType': 'Item'})
  const quizEntry = new QuizEntryRecord({
        id: '99',
        position: 1,
        entryType: 'BankEntry'
  })
  sinon.stub(quizEntry, 'getEntry').returns(bankEntry)
  sinon.stub(quizEntry, 'getWorkingInstance').returns(quizEntry)
  sinon.stub(quizEntry, 'getItem').returns(item)
  sinon.stub(bankEntry, 'getEntry').returns(item)
  sinon.stub(item, 'getInteractionType').returns(intType)

  const connectedTestbed = createTestbed(
    withContext(wrapInDragAndDropTestContext(QuizEntry), {
      tagAssociations: { Item: { 100: fromJS([{ id: 1, tag_value: 'waldo' }]) } }
    }), {
      connectDropTarget: (Component) => (Component), // inserted by React DnD
      quizEntry: quizEntry,
      quizEntries: {
      }
    })

  describe('without tagging', () => {
    it('does not render tag', () => {
      connectedTestbed.render()
      expect(connectedTestbed.getText()).not.to.include('waldo')
    })
  })

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

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