import { fromJS } from 'immutable'

import QuizAnalysis from '../../../../common/records/QuizAnalysis'

import QuizAnalysisOverview from '../QuizAnalysisOverview'
import Distribution from '../../charts/CentileDistribution'

describe('QuizAnalysisOverview', () => {
  const quizId = '1'
  const getQuizAnalysisStub = sinon.stub()
  const standardQuizAnalysis = new QuizAnalysis(fromJS({
    quizId: quizId,
    quizAnalysis: {
      centile: Array.from({length: 100}, () => Math.floor(Math.random() * 5)),
      decile: Array.from({length: 10}, () => Math.floor(Math.random() * 5)),
      scoreInfo: {
        resultSum: 5,
        resultCount: 1
      }
    },
    batchTimestamp: new Date()
  }))

  const testbed = createTestbed(QuizAnalysisOverview, {
    getQuizAnalysis: getQuizAnalysisStub,
    quizAnalysis: standardQuizAnalysis,
    quizId: quizId,
    quizTitle: 'Title'
  })

  shouldRenderComponent(testbed, {}, QuizAnalysisOverview)
  shouldRenderComponent(testbed, {}, Distribution)

  it('should render the quiz title', () => {
    testbed.render()
    expect(testbed.getText()).to.include('Title')
  })

  it('should render the score info', () => {
    testbed.render()
    const output = testbed.getText()
    expect(output).to.include('Mean Score')
    expect(output).to.include('High Score')
    expect(output).to.include('Low Score')
    expect(output).to.include('Standard Deviation')
    expect(output).to.include('Mean Elapsed Time')
    expect(output).to.include('Cronbach\'s Alpha')
  })

  it('renders last updated date', () => {
    testbed.render()
    const output = testbed.getText()
    expect(output).to.include('Data Last Updated')
  })
})
