Skip to content
Snippets Groups Projects
QuizQuestion.spec.tsx 1.76 KiB
Newer Older
  • Learn to ignore specific revisions
  • Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { render, waitFor } from '@testing-library/react'
    
    import { UserQuestionState } from 'enums'
    
    import React from 'react'
    import { Provider } from 'react-redux'
    
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    
    import QuizQuestion from './QuizQuestion'
    
    jest.mock('services/quiz.service', () => {
      return jest.fn(() => {
        return {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          getCustomQuestion: jest.fn(),
    
    jest.mock(
      'components/Quiz/QuizQuestion/QuizQuestionContentCustom',
    
      () => 'mock-customQuestion'
    )
    jest.mock(
      'components/Quiz/QuizQuestion/QuizQuestionContent',
      () => 'mock-question'
    
    
    describe('QuizQuestion component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
      it('should be rendered correctly with question', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
          <Provider store={store}>
            <QuizQuestion userChallenge={userChallengeData[0]} />
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(container.getElementsByTagName('mock-question').length).toBeTruthy()
        expect(
          container.getElementsByTagName('mock-customQuestion').length
        ).toBeFalsy()
    
      it('should be rendered correctly with customQuestion', async () => {
    
        const updateUserChallengeData = {
          ...userChallengeData[0],
        }
    
        updateUserChallengeData.quiz.questions.forEach(
          answer => (answer.result = UserQuestionState.CORRECT)
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
          <Provider store={store}>
            <QuizQuestion userChallenge={updateUserChallengeData} />
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        await waitFor(() => null, { container })
        expect(container.getElementsByTagName('mock-question').length).toBeFalsy()
        expect(
          container.getElementsByTagName('mock-customQuestion').length
        ).toBeTruthy()