import ReactDOM from 'react-dom'
import ReactTestUtils from 'react-dom/test-utils'

import EditButton from '../EditButton'

describe('Quiz Info EditButton', () => {
  const testbed = createTestbed(withContext(EditButton), {
    onClick: () => {}
  })

  shouldRenderComponent(
    testbed, {}, EditButton
  )

  describe('actions', () => {
    const clickStub = sinon.stub()
    it('should call onClick when clicked', () => {
      testbed.render({
        onClick: clickStub
      })

      const btn = ReactDOM.findDOMNode(testbed.subject)
      ReactTestUtils.Simulate.click(btn)

      expect(clickStub.called).to.be.true()
    })
  })

  describe('a11y tests', () => {
    it('should meet a11y standards', (done) => {
      testbed.render()
      testbed.checkA11yStandards(done, {})
    })

    describe('screenreader text', () => {
      it('should render default screenreader text', () => {
        testbed.render()
        expect(testbed.getText()).to.include('Edit')
      })

      it('should render screenreader text if prop passed in', () => {
        testbed.render({
          screenreaderText: 'Custom'
        })
        expect(testbed.getText()).to.include('Custom')
        expect(testbed.getText()).not.to.include('Edit')
      })
    })
  })
})
