import { fromJS } from 'immutable'

import Item from '../../../../common/records/Item'
import QuizSessionEvent from '../../../../common/records/QuizSessionEvent'

import Event from '../Event'
import ResponseEvent from '../ResponseEvent'
import SessionStartEvent from '../SessionStartEvent'

describe('Event', () => {
  describe('for a response event', () => {
    // testrail test_id:  C2954598, C2954599
    const event = new QuizSessionEvent({
      createdAt: '2016-09-28T18:45:27.700Z|232982772',
      eventType: 'RESPONSE'
    })
    const i = new Item({
      interactionData: {choices: {}}
    })

    sinon.stub(event, 'getItem').returns(i)

    const testbed = createTestbed(Event, {
      event: event,
      startTime: new Date()
    })

    shouldRenderComponent(testbed, {}, Event)

    it('should render a ResponseEvent', () => {
      testbed.render()
      const responseEventComponent = testbed.findChildrenByType(ResponseEvent)[0]
      expect(responseEventComponent).to.not.be.undefined()
    })
  })

  describe('for a session started/resumed event', () => {
    // testrail test_id: C2954596, C2954597
    const event = new QuizSessionEvent(fromJS({
      createdAt: '2016-09-28T18:45:27.700Z|232982772',
      eventData: {},
      eventType: 'SESSION_STARTED_OR_RESUMED_EVENT'
    }))

    const testbed = createTestbed(Event, {
      event: event,
      startTime: new Date()
    })

    shouldRenderComponent(testbed, {}, Event)

    it('should render a SessionStartEvent', () => {
      testbed.render()
      const sessionStartEventComponent = testbed.findChildrenByType(SessionStartEvent)[0]
      expect(sessionStartEventComponent).to.not.be.undefined()
    })
  })
})
