import AddContentButton from '../index'

describe('AddContentButton', () => {
  const onClickStub = sinon.stub()

  const defaultProps = {
    isEditing: false,
    onClick: onClickStub,
    position: 33,
    useStimulusTrigger: false
  }

  beforeEach(() => {
    onClickStub.resetHistory()
  })

  const testbed = createTestbed(AddContentButton, defaultProps)

  it('renders correctly for a non-stimulus', () => {
    testbed.render()
    expect(testbed.rootNode.innerHTML.match(/Add Content/)).to.exist()
    expect(testbed.rootNode.innerHTML.match(/Attach Question/)).to.not.exist()
  })

  it('renders correctly for a stimulus', () => {
    testbed.render({useStimulusTrigger: true})
    expect(testbed.rootNode.innerHTML.match(/Add Content/)).to.not.exist()
    expect(testbed.rootNode.innerHTML.match(/Attach Question/)).to.exist()
  })

  it('calls the onClick handler', () => {
    testbed.render()
    testbed.findChildrenByTagName('button')[0].click()
    expect(onClickStub.called).to.be.true()
  })
})
