import { List } from 'immutable'
import InteractionType from 'quiz-interactions/lib/records/InteractionType'

import { honorsSidebarProps } from '../../../../../../tests/util/sharedExamples/honorsSidebarProps'

import { wrapInDragAndDropTestContext } from '../../../../../../tests/util/dndTestUtils'
import Item from '../../../../../common/records/Item'
import QuizEntry from '../../../../../common/records/QuizEntry'

import Sidebar, { mapStateToProps, mapDispatchToProps } from '../index'

describe('Building Index Sidebar', () => {
  const intType = new InteractionType({})
  const itemA = new Item({id: '5', position: 4})
  const itemB = new Item({id: '6', position: 8})
  sinon.stub(itemA, 'getInteractionType').returns(intType)
  sinon.stub(itemB, 'getInteractionType').returns(intType)
  const quizEntryA = new QuizEntry({id: '3'})
  const quizEntryB = new QuizEntry({id: '8'})
  sinon.stub(quizEntryA, 'getEntry').returns(itemA)
  sinon.stub(quizEntryB, 'getEntry').returns(itemB)
  const quizEntries = List([
    quizEntryA, quizEntryB
  ])
  const moveQuizEntryStub = sinon.stub()
  const moveTemporaryQuizEntryStub = sinon.stub()
  const newHoverPositionStub = sinon.stub()
  const scrollToItemStub = sinon.stub()

  const props = {
    connectDropTarget: (Component) => (Component), // inserted by React DnD
    isOver: false, // inserted by React DnD
    moveQuizEntry: moveQuizEntryStub, // Used for DND
    moveTemporaryQuizEntry: moveTemporaryQuizEntryStub, // Used for DND
    newHoverPosition: newHoverPositionStub, // Used for DND
    quizId: '1', // Used for DND
    scrollToItem: scrollToItemStub,
    sidebarOpen: true,
    quizEntries
  }

  const ConnectedSidebar = wrapInDragAndDropTestContext(withContext(Sidebar))

  const testbed = createTestbed(ConnectedSidebar, props)

  shouldRenderComponent(testbed, {}, Sidebar)

  honorsSidebarProps(mapStateToProps, mapDispatchToProps)
})
