import { fromJS } from 'immutable'

import createTestbed from '../../../../../../../tests/util/react-testbed'
import withContext from '../../../../../../../tests/util/withContext'
import Stimulus from '../../../../../records/Stimulus'
import StimulusShowInfo from '../index'
import QuizEntry from '../../../../../records/QuizEntry'

import styles from '../styles.css'

describe('StimulusShowInfo', () => {
  const editingStub = sinon.stub()
  const openDeleteStimulusModalStub = sinon.stub()

  const stimulus = new Stimulus({
    id: 55,
    title: 'Title',
    instructions: 'Instructions',
    body: '<em>Body</em>',
    sourceUrl: 'Source URL'
  })

  const defaultProps = {
    openDeleteStimulusModal: openDeleteStimulusModalStub,
    stimulus,
    switchOnEditing: editingStub,
    connectDragSource: (C) => C,
    quizEntries: fromJS([new QuizEntry(), new QuizEntry()]),
    quizEntry: new QuizEntry()
  }

  const testbed = createTestbed(withContext(StimulusShowInfo), defaultProps)

  afterEach(() => {
    editingStub.resetHistory()
    openDeleteStimulusModalStub.resetHistory()
  })

  it('renders the body as html', () => {
    testbed.render()
    const elem = testbed.findChildrenByClass(styles.body)[0]
    expect(elem.innerHTML).to.eq('<em>Body</em>')
  })

  describe('a11y tests', () => {
    it('should meet a11y standards', (done) => {
      testbed.render()
      testbed.checkA11yStandards(done, { ignores: ['label', 'label-title-only'] })
    })
  })
})
