2024-03-29 20:08:34 -04:00
|
|
|
//TeacherModeQuiz.test.tsx
|
2025-01-11 02:22:14 -05:00
|
|
|
import React from 'react';
|
2024-09-15 21:41:24 -04:00
|
|
|
import { render, fireEvent, act } from '@testing-library/react';
|
|
|
|
|
import { screen } from '@testing-library/dom';
|
2024-03-29 20:08:34 -04:00
|
|
|
import '@testing-library/jest-dom';
|
2024-09-15 21:41:24 -04:00
|
|
|
import { parse } from 'gift-pegjs';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2025-01-16 12:37:07 -05:00
|
|
|
import TeacherModeQuiz from 'src/components/TeacherModeQuiz/TeacherModeQuiz';
|
2024-09-15 01:26:06 -04:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2024-09-15 21:41:24 -04:00
|
|
|
// import { mock } from 'node:test';
|
|
|
|
|
|
|
|
|
|
const mockGiftQuestions = parse(
|
|
|
|
|
`::Sample Question:: Sample Question {=Option A ~Option B}`);
|
|
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
describe('TeacherModeQuiz', () => {
|
2024-09-15 21:41:24 -04:00
|
|
|
const mockQuestion = mockGiftQuestions[0];
|
|
|
|
|
mockQuestion.id = '1';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
const mockSubmitAnswer = jest.fn();
|
|
|
|
|
const mockDisconnectWebSocket = jest.fn();
|
|
|
|
|
|
2024-09-15 21:41:24 -04:00
|
|
|
beforeEach(async () => {
|
2024-03-29 20:08:34 -04:00
|
|
|
render(
|
2024-09-15 01:26:06 -04:00
|
|
|
<MemoryRouter>
|
|
|
|
|
<TeacherModeQuiz
|
|
|
|
|
questionInfos={{ question: mockQuestion }}
|
|
|
|
|
submitAnswer={mockSubmitAnswer}
|
2024-09-15 21:41:24 -04:00
|
|
|
disconnectWebSocket={mockDisconnectWebSocket} />
|
2024-09-15 01:26:06 -04:00
|
|
|
</MemoryRouter>
|
2024-03-29 20:08:34 -04:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('renders the initial question', () => {
|
|
|
|
|
expect(screen.getByText('Question 1')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Sample Question')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Option A')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Option B')).toBeInTheDocument();
|
2024-09-15 01:26:06 -04:00
|
|
|
expect(screen.getByText('Quitter')).toBeInTheDocument();
|
2024-03-29 20:08:34 -04:00
|
|
|
expect(screen.getByText('Répondre')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-24 19:56:47 -04:00
|
|
|
test('handles answer submission and displays feedback', () => {
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2024-09-15 21:41:24 -04:00
|
|
|
act(() => {
|
|
|
|
|
fireEvent.click(screen.getByText('Option A'));
|
|
|
|
|
});
|
|
|
|
|
act(() => {
|
|
|
|
|
fireEvent.click(screen.getByText('Répondre'));
|
|
|
|
|
});
|
2024-09-26 00:34:30 -04:00
|
|
|
expect(mockSubmitAnswer).toHaveBeenCalledWith('Option A', 1);
|
2024-09-24 19:56:47 -04:00
|
|
|
expect(screen.getByText('Votre réponse est "Option A".')).toBeInTheDocument();
|
2024-03-29 20:08:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('handles disconnect button click', () => {
|
2024-09-15 21:41:24 -04:00
|
|
|
act(() => {
|
|
|
|
|
fireEvent.click(screen.getByText('Quitter'));
|
|
|
|
|
});
|
2024-03-29 20:08:34 -04:00
|
|
|
expect(mockDisconnectWebSocket).toHaveBeenCalled();
|
|
|
|
|
});
|
2024-09-15 00:34:41 -04:00
|
|
|
});
|