import Button from '@instructure/ui-buttons/lib/components/Button'

import ExpandButton from '../index'
import styles from '../styles.css'

describe('ExpandButton', () => {
  const clickStub = sinon.stub()

  const testbed = createTestbed(ExpandButton, {
    isExpanded: false,
    title: 'omg',
    onClick: clickStub
  })

  shouldRenderComponent(testbed, {}, Button)

  it('should read title text', () => {
    testbed.render()
    expect(testbed.getText()).to.eq('omg')
  })

  it('triggers onClick', () => {
    testbed.render()
    const icon = testbed.findChildrenByTagName('button')[0]
    icon.click()
    expect(clickStub).to.be.calledOnce()
  })

  it('should render a flippy icon', () => {
    testbed.render()
    expect(testbed.findChildrenByClass(styles.iconOpened).length).to.eq(0)
    testbed.render({ isExpanded: true })
    expect(testbed.findChildrenByClass(styles.iconOpened).length).to.eq(1)
  })

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