mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Fix ManageRoom tests
This commit is contained in:
parent
fc69a37e53
commit
3855eca6c6
1 changed files with 37 additions and 33 deletions
|
|
@ -35,7 +35,7 @@ const mockQuiz: QuizType = {
|
|||
folderName: 'folder-name',
|
||||
userId: 'user-id',
|
||||
created_at: new Date(),
|
||||
updated_at: new Date()
|
||||
updated_at: new Date(),
|
||||
};
|
||||
|
||||
const mockStudents: StudentType[] = [
|
||||
|
|
@ -58,12 +58,12 @@ describe('ManageRoom', () => {
|
|||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(useNavigate as jest.Mock).mockReturnValue(navigate);
|
||||
useParamsMock.mockReturnValue({ id: 'test-quiz-id' });
|
||||
useParamsMock.mockReturnValue({ quizId: 'test-quiz-id', roomName: 'Test Room' });
|
||||
(ApiService.getQuiz as jest.Mock).mockResolvedValue(mockQuiz);
|
||||
(webSocketService.connect as jest.Mock).mockReturnValue(mockSocket);
|
||||
(useRooms as jest.Mock).mockReturnValue({
|
||||
selectedRoom: { id: '1', title: 'Test Room' },
|
||||
setSelectedRoom: mockSetSelectedRoom
|
||||
setSelectedRoom: mockSetSelectedRoom,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -96,7 +96,10 @@ describe('ManageRoom', () => {
|
|||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Test Quiz')).toBeInTheDocument();
|
||||
expect(screen.getByText(/Salle\s*:\s*Test Room/i)).toBeInTheDocument();
|
||||
|
||||
const roomHeader = document.querySelector('h1');
|
||||
expect(roomHeader).toHaveTextContent('Salle : Test Room');
|
||||
|
||||
expect(screen.getByText('0/60')).toBeInTheDocument();
|
||||
expect(screen.getByText('Question 1/2')).toBeInTheDocument();
|
||||
});
|
||||
|
|
@ -113,11 +116,11 @@ describe('ManageRoom', () => {
|
|||
|
||||
await act(async () => {
|
||||
const createSuccessCallback = (mockSocket.on as jest.Mock).mock.calls.find(call => call[0] === 'create-success')[1];
|
||||
createSuccessCallback('test-room-name');
|
||||
createSuccessCallback('Test Room');
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/Salle\s*:\s*test-room-name/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Salle\s*:\s*Test Room/i)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -132,7 +135,7 @@ describe('ManageRoom', () => {
|
|||
|
||||
await act(async () => {
|
||||
const createSuccessCallback = (mockSocket.on as jest.Mock).mock.calls.find(call => call[0] === 'create-success')[1];
|
||||
createSuccessCallback('test-room-name');
|
||||
createSuccessCallback('Test Room');
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
|
|
@ -172,7 +175,7 @@ describe('ManageRoom', () => {
|
|||
|
||||
await act(async () => {
|
||||
const createSuccessCallback = (mockSocket.on as jest.Mock).mock.calls.find(call => call[0] === 'create-success')[1];
|
||||
createSuccessCallback('test-room-name');
|
||||
createSuccessCallback('Test Room');
|
||||
});
|
||||
|
||||
const launchButton = screen.getByText('Lancer');
|
||||
|
|
@ -195,7 +198,9 @@ describe('ManageRoom', () => {
|
|||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(consoleSpy).toHaveBeenCalledWith('Received answer from Student 1 for question 1: Answer1');
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
'Received answer from Student 1 for question 1: Answer1'
|
||||
);
|
||||
});
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
|
|
@ -212,19 +217,20 @@ describe('ManageRoom', () => {
|
|||
|
||||
await act(async () => {
|
||||
const createSuccessCallback = (mockSocket.on as jest.Mock).mock.calls.find(call => call[0] === 'create-success')[1];
|
||||
createSuccessCallback('test-room-name');
|
||||
createSuccessCallback('Test Room');
|
||||
});
|
||||
|
||||
const launchButton = screen.getByText('Lancer');
|
||||
fireEvent.click(launchButton);
|
||||
fireEvent.click(screen.getByText('Lancer'));
|
||||
fireEvent.click(screen.getByText('Rythme du professeur'));
|
||||
fireEvent.click(screen.getAllByText('Lancer')[1]);
|
||||
|
||||
const rythmeButton = screen.getByText('Rythme du professeur');
|
||||
fireEvent.click(rythmeButton);
|
||||
await waitFor(() => {
|
||||
screen.debug();
|
||||
});
|
||||
|
||||
const secondLaunchButton = screen.getAllByText('Lancer');
|
||||
fireEvent.click(secondLaunchButton[1]);
|
||||
const nextQuestionButton = await screen.findByRole('button', { name: /Prochaine question/i });
|
||||
expect(nextQuestionButton).toBeInTheDocument();
|
||||
|
||||
const nextQuestionButton = screen.getByText('Prochaine question');
|
||||
fireEvent.click(nextQuestionButton);
|
||||
|
||||
await waitFor(() => {
|
||||
|
|
@ -243,7 +249,7 @@ describe('ManageRoom', () => {
|
|||
|
||||
await act(async () => {
|
||||
const createSuccessCallback = (mockSocket.on as jest.Mock).mock.calls.find(call => call[0] === 'create-success')[1];
|
||||
createSuccessCallback('test-room-name');
|
||||
createSuccessCallback('Test Room');
|
||||
});
|
||||
|
||||
const disconnectButton = screen.getByText('Quitter');
|
||||
|
|
@ -312,7 +318,7 @@ describe('ManageRoom', () => {
|
|||
|
||||
await act(async () => {
|
||||
const createSuccessCallback = (mockSocket.on as jest.Mock).mock.calls.find(call => call[0] === 'create-success')[1];
|
||||
createSuccessCallback('test-room-name');
|
||||
createSuccessCallback('Test Room');
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
|
|
@ -330,6 +336,4 @@ describe('ManageRoom', () => {
|
|||
expect(screen.queryByText('Student 1')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue