
import styles from '../styles.css'
import FileSelector from '../FileSelector'

describe('FileSelector', () => {
  const testbed = createTestbed(FileSelector, {
    acceptAttribute: '.zip',
    content: 'Content'
  })

  shouldRenderComponent(
    testbed, {}, FileSelector
  )

  describe('#onDrop', () => {
    it('calls the fileHandler with the list of files', () => {
      const fileHandlerStub = sinon.stub()
      testbed.render({fileHandler: fileHandlerStub})
      testbed.subject.onDrop(['testfile1', 'testfile2'])
      const filesList = fileHandlerStub.getCall(0).args[0].toJS()
      expect(filesList[0]).to.eq('testfile1')
      expect(filesList[1]).to.eq('testfile2')
    })
  })

  describe('rendering', () => {
    it('should render a file selection box', () => {
      testbed.render({})

      const dropzones = testbed.findChildrenByClass(styles.dropzone)
      expect(dropzones.length).to.be.equal(1)
    })

    it('should render an input', () => {
      testbed.render({})

      const input = testbed.rootNode.getElementsByTagName('input')[0]
      expect(input.type).to.be.equal('file')
      expect(input.accept).to.be.equal('.zip')
      expect(testbed.getText()).to.be.equal('Content')
    })
  })

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