import { List } from 'immutable'

import CommonStimulus from '../../../../../../common/components/layout/sidebar/Stimulus'
import DragHandle from '../../../../../../common/components/shared/drag_and_drop/DragHandle'
import QuizEntry from '../../../../../../common/records/QuizEntry'
import Stimulus from '../presenter'

import StimulusRecord from '../../../../../../common/records/Stimulus'

describe('Stimulus Building Sidebar Presenter', () => {
  const props = {
    connectDropTarget: sinon.stub().returnsArg(0),
    displayPosition: 1,
    itemId: '1',
    sidebarOpen: true,
    stimulus: new StimulusRecord(),
    itemsCollectionSize: 1,
    quizEntry: new QuizEntry({position: 2, entryType: 'Stimulus', entry: new StimulusRecord()}),
    quizEntries: List([new QuizEntry(), new QuizEntry(), new QuizEntry()]),
    connectDragSource: (C) => C,
    connectDragPreview: (C) => C
  }

  const testbed = createTestbed(wrapInDragAndDropTestContext(withContext(Stimulus)), props)

  shouldRenderComponent(testbed, {}, Stimulus)

  it('renders common stimulus', () => {
    testbed.render()
    expect(testbed.findChildrenByType(CommonStimulus).length).to.eq(1)
  })

  it('should include a drag handle if draggable', () => {
    testbed.render()

    const dragHandles = testbed.findChildrenByType(DragHandle)
    expect(dragHandles).to.have.length(1)
  })

  it('should not include a drag handle not draggable', () => {
    testbed.render({sidebarOpen: false})

    const dragHandles = testbed.findChildrenByType(DragHandle)
    expect(dragHandles).to.have.length(0)
  })
})
