
import DragAndDropZone from '../index'

import styles from '../styles.css'

describe('DragAndDropZone', () => {
  const testbed = createTestbed(DragAndDropZone, {})

  shouldRenderComponent(
    testbed,
    {},
    DragAndDropZone
  )

  describe('#shouldRender', () => {
    it('does not render when in sidebar if not open', () => {
      testbed.render({
        inSidebar: true,
        sidebarOpen: false
      })
      const dndZone = testbed.findChildrenByClass(styles.hide)
      expect(dndZone).to.not.be.empty()
    })

    context('in stimulus', () => {
      it('renders above when supposed to', () => {
        testbed.render({
          location: 'above',
          inStimulus: true,
          draggingOver: true,
          draggingAboveHalf: true,
          dropIntoEmptyStimulus: false
        })
        const dndZone = testbed.findChildrenByClass(styles.hide)
        expect(dndZone).to.be.empty()
      })

      it('does not render above when not supposed to', () => {
        testbed.render({
          location: 'above',
          inStimulus: true,
          draggingOver: false,
          draggingAboveHalf: true,
          dropIntoEmptyStimulus: false
        })
        const dndZone = testbed.findChildrenByClass(styles.hide)
        expect(dndZone).to.not.be.empty()
      })

      it('renders below when supposed to', () => {
        testbed.render({
          location: 'below',
          inStimulus: true,
          draggingOver: true,
          draggingAboveHalf: false,
          dropIntoEmptyStimulus: false
        })
        const dndZone = testbed.findChildrenByClass(styles.hide)
        expect(dndZone).to.be.empty()
      })

      it('does not render below when not supposed to', () => {
        testbed.render({
          location: 'below',
          inStimulus: true,
          draggingOver: false,
          draggingAboveHalf: true,
          dropIntoEmptyStimulus: false
        })
        const dndZone = testbed.findChildrenByClass(styles.hide)
        expect(dndZone).to.not.be.empty()
      })

      it('renders in when supposed to', () => {
        testbed.render({
          location: 'in',
          inStimulus: true,
          draggingOver: true,
          dropIntoEmptyStimulus: true
        })
        const dndZone = testbed.findChildrenByClass(styles.hide)
        expect(dndZone).to.be.empty()
      })

      it('does not render in when not supposed to', () => {
        testbed.render({
          location: 'in',
          inStimulus: true,
          draggingOver: true,
          dropIntoEmptyStimulus: false
        })
        const dndZone = testbed.findChildrenByClass(styles.hide)
        expect(dndZone).to.not.be.empty()
      })
    })

    context('not in stimulus', () => {
      it('renders above when supposed to', () => {
        testbed.render({
          location: 'above',
          draggingOver: true,
          draggingAboveHalf: true
        })
        const dndZone = testbed.findChildrenByClass(styles.hide)
        expect(dndZone).to.be.empty()
      })

      it('does not render above when not supposed to', () => {
        testbed.render({
          location: 'above',
          draggingOver: false,
          draggingAboveHalf: true
        })
        const dndZone = testbed.findChildrenByClass(styles.hide)
        expect(dndZone).to.not.be.empty()
      })

      it('renders below when supposed to', () => {
        testbed.render({
          location: 'below',
          draggingOver: true,
          draggingAboveHalf: false
        })
        const dndZone = testbed.findChildrenByClass(styles.hide)
        expect(dndZone).to.be.empty()
      })

      it('does not render below when not supposed to', () => {
        testbed.render({
          location: 'below',
          draggingOver: false,
          draggingAboveHalf: true
        })
        const dndZone = testbed.findChildrenByClass(styles.hide)
        expect(dndZone).to.not.be.empty()
      })
    })
  })

  describe('a11y tests', () => {
    it('should meet a11y standards', (done) => {
      testbed.render()
      testbed.checkA11yStandards(done, { ignores: ['label', 'label-title-only'] })
    })
  })
})
