2024-03-29 20:08:34 -04:00
|
|
|
//TeacherModeQuiz.test.tsx
|
2024-09-15 01:26:06 -04:00
|
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
2024-03-29 20:08:34 -04:00
|
|
|
import '@testing-library/jest-dom';
|
|
|
|
|
import { GIFTQuestion } from 'gift-pegjs';
|
|
|
|
|
|
|
|
|
|
import TeacherModeQuiz from '../../../../components/TeacherModeQuiz/TeacherModeQuiz';
|
2024-09-15 01:26:06 -04:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
describe('TeacherModeQuiz', () => {
|
|
|
|
|
const mockQuestion: GIFTQuestion = {
|
|
|
|
|
id: '1',
|
|
|
|
|
type: 'MC',
|
|
|
|
|
stem: { format: 'plain', text: 'Sample Question' },
|
|
|
|
|
title: 'Sample Question',
|
|
|
|
|
hasEmbeddedAnswers: false,
|
|
|
|
|
globalFeedback: null,
|
|
|
|
|
choices: [
|
|
|
|
|
{ text: { format: 'plain', text: 'Option A' }, isCorrect: true, weight: 1, feedback: null },
|
|
|
|
|
{ text: { format: 'plain', text: 'Option B' }, isCorrect: false, weight: 0, feedback: null },
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mockSubmitAnswer = jest.fn();
|
|
|
|
|
const mockDisconnectWebSocket = jest.fn();
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
render(
|
2024-09-15 01:26:06 -04:00
|
|
|
<MemoryRouter>
|
|
|
|
|
<TeacherModeQuiz
|
|
|
|
|
questionInfos={{ question: mockQuestion }}
|
|
|
|
|
submitAnswer={mockSubmitAnswer}
|
|
|
|
|
disconnectWebSocket={mockDisconnectWebSocket}
|
|
|
|
|
/>
|
|
|
|
|
</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();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('handles answer submission and displays wait text', () => {
|
|
|
|
|
fireEvent.click(screen.getByText('Option A'));
|
|
|
|
|
fireEvent.click(screen.getByText('Répondre'));
|
|
|
|
|
|
|
|
|
|
expect(mockSubmitAnswer).toHaveBeenCalledWith('Option A', '1');
|
|
|
|
|
expect(screen.getByText('En attente pour la prochaine question...')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('handles disconnect button click', () => {
|
2024-09-15 01:26:06 -04:00
|
|
|
fireEvent.click(screen.getByText('Quitter'));
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
expect(mockDisconnectWebSocket).toHaveBeenCalled();
|
|
|
|
|
});
|
2024-09-15 00:34:41 -04:00
|
|
|
});
|