import { fromJS } from 'immutable'
import Stimulus, {mapStateToProps} from '../index'

import QuizEntryRecord from '../../../../../records/QuizEntry'
import StimulusRecord from '../../../../../records/Stimulus'

describe('Common Stimulus Sidebar Index', () => {
  const stimulusParent = new QuizEntryRecord()
  sinon.stub(stimulusParent, 'getEntry').returns(new StimulusRecord())

  const testbed = createTestbed(withContext(Stimulus),
    {
      displayPosition: 1,
      isOver: false,
      isDragging: false,
      isShowingItems: false,
      renderSidebarItem: () => {},
      sidebarOpen: true,
      stimulusParent: stimulusParent
    }
  )

  shouldRenderComponent(
    testbed, {}, Stimulus
  )

  describe('#mapStateToProps', () => {
    it('gets isShowingItems from state', () => {
      const state = fromJS({sidebar: {1: true}})
      const stimulusParent = new QuizEntryRecord()
      sinon.stub(stimulusParent, 'getEntry').returns({id: '1'})
      expect(mapStateToProps(state, {stimulusParent}).isShowingItems).to.be.true()
    })

    it('sets default of isShowingItems to false if not found in state', () => {
      const state = fromJS({sidebar: {2: true}})
      const stimulusParent = new QuizEntryRecord()
      sinon.stub(stimulusParent, 'getEntry').returns({id: '1'})
      expect(mapStateToProps(state, {stimulusParent}).isShowingItems).to.be.false()
    })
  })
})
