Newer
Older
import { render, screen } from '@testing-library/react'
import { Provider } from 'react-redux'
import { questionEntity } from 'tests/__mocks__/quizData.mock'
import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
import QuizQuestionContentCustom from './QuizQuestionContentCustom'
const mockHistoryPush = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
push: mockHistoryPush,
}),
}))
const mockUpdateUserQuiz = jest.fn()
jest.mock('services/quiz.service', () => {
return jest.fn(() => ({
updateUserQuiz: mockUpdateUserQuiz,
const mockUpdateUserChallenge = jest.fn()
jest.mock('services/challenge.service', () => {
updateUserChallenge: mockUpdateUserChallenge,
})
describe('QuizCustomQuestionContent component', () => {
userChallenge={userChallengeData[0]}
goBack={mockHistoryPush('/challenges')}
/>
</Provider>
)
await userEvent.click(screen.getAllByRole('button')[0])
expect(mockHistoryPush).toHaveBeenCalledWith('/challenges')
expect(screen.getByText(questionEntity.questionLabel)).toBeInTheDocument()
expect(screen.getAllByRole('radio').length).toBe(3)
it('should display QuizExplanationModal when click on Button', async () => {
mockUpdateUserChallenge.mockResolvedValue(userChallengeData[0])
userChallenge={userChallengeData[0]}
goBack={mockHistoryPush('/challenges')}
/>
</Provider>
)
await userEvent.click(screen.getAllByRole('radio')[0])
await userEvent.click(screen.getByText('quiz.button_validate'))
expect(mockUpdateUserQuiz).toHaveBeenCalledWith(
userChallengeData[0].quiz,
questionEntity.answers[0].isTrue
)