import React from 'react'

import ItemWarningWrapper from '../index'

import styles from '../styles.css'

describe('Item Warning Wrapper', () => {
  const cancelActionCallback = sinon.stub()
  const defaultActionCallback = sinon.stub()
  const testbed = createTestbed(ItemWarningWrapper, {
    cancelActionCallback,
    children: <button />,
    defaultActionCallback,
    description: 'description',
    hideActions: true,
    showAlert: true
  })

  describe('#render', () => {
    it('renders the wrapper', () => {
      const shallowTestbed = testbed.renderShallowly()
      const alert = shallowTestbed.find('Alert')
      expect(alert).to.have.length(1)
    })

    it('renders the children content', () => {
      const shallowTestbed = testbed.renderShallowly()
      const button = shallowTestbed.find('button')
      expect(button).to.have.length(1)
    })

    it('renders the action buttons', () => {
      const shallowTestbed = testbed.renderShallowly({hideActions: false})
      const button = shallowTestbed.find('Button')
      expect(button).to.have.length(2)
    })

    it('hides children', () => {
      const shallowTestbed = testbed.renderShallowly({disableChildren: true})
      const overlay = shallowTestbed.find(styles.disabledChildren)
      expect(overlay).to.not.be.undefined()
    })

    it('hides alert', () => {
      const shallowTestbed = testbed.renderShallowly({showAlert: false})
      const alert = shallowTestbed.find('Alert')
      expect(alert).to.have.length(0)
    })

    it('sets focus on first interactive element', () => {
      testbed.render({hideActions: false})
      expect(document.activeElement.tagName).to.equal('BUTTON')
    })
  })
})
