import ReactTestUtils from 'react-dom/test-utils'
import { fromJS } from 'immutable'

import Stimulus from '../../../../../records/Stimulus'
import StimulusShow from '../index'
import QuizEntry from '../../../../../records/QuizEntry'

import styles from '../styles.css'

describe('StimulusShow', () => {
  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 = {
    displayPosition: 1,
    openDeleteStimulusModal: openDeleteStimulusModalStub,
    stimulus,
    switchOnEditing: editingStub,
    connectDragSource: (C) => C,
    quizEntries: fromJS([new QuizEntry(), new QuizEntry()]),
    quizEntry: new QuizEntry()
  }

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

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

  it('switches to editing mode on click', () => {
    testbed.render()
    const button = testbed.findChildrenByClass(styles.stimulusContent)[0]
    ReactTestUtils.Simulate.click(button)
    expect(editingStub.called).to.be.true()
  })

  it('opens the delete stimulus modal on click', () => {
    testbed.render()
    const button = testbed.findChildrenByTagNameAndAttribute('div', 'role', 'button')[2]
    ReactTestUtils.Simulate.click(button)
    expect(openDeleteStimulusModalStub.called).to.be.true()
  })

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