Skip to content
Snippets Groups Projects
QuizQuestionContent.spec.tsx 1.78 KiB
Newer Older
  • Learn to ignore specific revisions
  • Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { render, screen } from '@testing-library/react'
    import { userEvent } from '@testing-library/user-event'
    
    import React from 'react'
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    import { Provider } from 'react-redux'
    
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    import QuizQuestionContent from './QuizQuestionContent'
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    
    
    const mockedNavigate = jest.fn()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    jest.mock('react-router-dom', () => ({
      ...jest.requireActual('react-router-dom'),
    
      useNavigate: () => mockedNavigate,
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    }))
    
    jest.mock('services/quiz.service', () => {
    
      return jest.fn(() => ({
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        updateUserQuiz: jest.fn(),
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    })
    
    jest.mock('services/challenge.service', () => {
    
      return jest.fn(() => ({
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        updateUserChallenge: jest.fn(),
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    })
    
    describe('QuizQuestionContent component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      it('should be rendered correctly', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        render(
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          <Provider store={store}>
            <QuizQuestionContent
              userChallenge={userChallengeData[0]}
              setIsCustomQuest={() => false}
    
              goBack={mockedNavigate('/challenges')}
    
    Yoan VALLET's avatar
    Yoan VALLET committed
            />
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(
          screen.getByText(userChallengeData[0].quiz.questions[0].questionLabel)
        ).toBeInTheDocument()
        expect(screen.getAllByRole('radio').length).toBe(3)
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      })
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      it('should redirect to challenge on click on btn-back', async () => {
        render(
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          <Provider store={store}>
            <QuizQuestionContent
              userChallenge={userChallengeData[0]}
              setIsCustomQuest={() => false}
    
              goBack={mockedNavigate('/challenges')}
    
    Yoan VALLET's avatar
    Yoan VALLET committed
            />
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        await userEvent.click(screen.getAllByRole('button')[0])
    
        expect(mockedNavigate).toHaveBeenCalledWith('/challenges')
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      })
    })