import { List } from 'immutable'

import QuizSessionResultHeader from '../index'
import QuizSession from '../../../../../records/QuizSession'
import SessionItemResultRecord from '../../../../../records/SessionItemResult'

describe('QSRHeader', () => {
  const qs = new QuizSession()
  const usersName = 'David Davidson'
  sinon.stub(qs, 'userDisplayName').returns(usersName) // Still relevant?

  const testbed = createTestbed(QuizSessionResultHeader, {
    quizSession: qs
  })

  shouldRenderComponent(testbed, {}, QuizSessionResultHeader)

  it('shows the users name', () => {
    testbed.render()
    expect(testbed.getText()).to.include(usersName)
  })

  it('includes the consumer provided subtitle (w/ user name) if provided', () => {
    testbed.render({ studentDescription: 'Clark Kent' })

    expect(testbed.getText()).to.include('Clark Kent')
  })

  it('shows regrade alert if there are regradedSessionItemResults', () => {
    const regradedSessionItemResults = List([
      new SessionItemResultRecord({position: '1', id: 1, regradeInfo: {regraded: true}}),
      new SessionItemResultRecord({position: '2', id: 2, regradeInfo: {regraded: true}})
    ])
    testbed.render({ regradedSessionItemResults })

    expect(testbed.getText()).to.include('This assessment has been regraded.')
  })

  it('shows regraded items by position', () => {
    const regradedSessionItemResults = List([
      new SessionItemResultRecord({position: '2', id: 1, regradeInfo: {regraded: true}}),
      new SessionItemResultRecord({position: '3', id: 2, regradeInfo: {regraded: true}}),
      new SessionItemResultRecord({position: '5', id: 3, regradeInfo: {regraded: true}}),
      new SessionItemResultRecord({position: '8', id: 4, regradeInfo: {regraded: true}})
    ])
    testbed.render({ regradedSessionItemResults })

    expect(testbed.getText()).to.include('2, 3, 5, 8')
  })

  it('shows singular version of alert if there is only one regraded item', () => {
    const regradedSessionItem = List([
      new SessionItemResultRecord({position: '1', id: 1, regradeInfo: {regraded: true}})
    ])
    testbed.render({ regradedSessionItem })

    expect(testbed.getText()).to.not.include('Questions')
  })
})
