import { Map } from 'immutable'

import QuizEntryBankShow from '../index'
import Bank from '../../../../../../../common/records/Bank'
import QuizEntry from '../../../../../../../common/records/QuizEntry'
import BankEntry from '../../../../../../../common/records/BankEntry'

describe('QuizEntryBankShow', () => {
  const quizEntryBankProps = {
    entry: new Bank(),
    quizEntry: new QuizEntry()
  }
  const testbed = createTestbed(QuizEntryBankShow, quizEntryBankProps)
  const shallowtestbed = testbed.renderShallowly()

  describe('QuizEntryBankShow', () => {
    it('renders the quiz entry bank', () => {
      const text = shallowtestbed.find('Text').render().text()
      expect(text).to.include('All questions pulled from bank:')
    })

    it('renders the quiz entry bank with number of questions pulled and points possible', () => {
      const bankTestbed = testbed.renderShallowly(
        {
          quizEntry: new QuizEntry({pointsPossible: 5, properties: Map({sampleNum: 2})})
        })
      const text = bankTestbed.find('Text').last().render().text()
      expect(text).to.include('2 questions pulled randomly from bank:  5 points per question')
    })

    it('renders sampleNum errors', () => {
      const bankTestbed = testbed.renderShallowly({
        quizEntry: new QuizEntry({pointsPossible: 5, properties: Map({sampleNum: 2})}),
        entry: new Bank({entryCount: 1})
      })
      const alertText = bankTestbed.find('Alert').last().render().text()
      expect(alertText).to.include('Max number of bank questions exceeded!')
    })

    it('renders deleted errors', () => {
      const bankTestbed = testbed.renderShallowly({
        quizEntry: new QuizEntry(),
        entry: new BankEntry({ archived: true })
      })
      const alertText = bankTestbed.find('Alert').last().render().text()
      expect(alertText).to.include('Item bank no longer exists!')
    })
  })
})
