import LearnosityCalculator from '../../../../LearnosityCalculator'
import Calculator from '../index'
import withContext from '../../../../../../../tests/util/withContext'
import {setFakeStore, unsetFakeStore} from '../../../../../../reduxStore'
import {fromJS} from 'immutable'

describe('Calculator', () => {
  const calculatorType = 'basic'
  const activeQuizId = '42'
  const quizSessionId = 24
  const activeCalculatorId = 'abc'
  const state = {
    quizzes: {
      activeQuizId,
      [activeQuizId]: {
        id: activeQuizId,
        calculatorType
      }
    },
    quizSessions: {
      activeQuizSessionId: quizSessionId
    },
    ui: {
      activeCalculatorId
    }
  }

  const testbed = createTestbed(withContext(Calculator, state))

  beforeEach(() => {
    setFakeStore(fromJS(state))
  })

  afterEach(() => {
    unsetFakeStore()
  })

  it('correctly maps props from state', async () => {
    testbed.render()

    const learnosityCalculator = testbed.findChildByType(LearnosityCalculator)
    expect(learnosityCalculator.props).to.contain({
      activeCalculatorId,
      calculatorType,
      quizSessionId
    })
  })
})
