From 2de7671666b0d150f5436ed4119ec03349425cf1 Mon Sep 17 00:00:00 2001 From: "C. Fuhrman" Date: Sun, 2 Feb 2025 12:42:05 -0500 Subject: [PATCH] =?UTF-8?q?Corriger=20des=20tests=20et=20auto-fix=20des=20?= =?UTF-8?q?probl=C3=A8mes=20de=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/babel.config.cjs | 2 +- client/jest.config.cjs | 2 +- client/jest.setup.cjs | 2 +- .../src/__tests__/Types/StudentType.test.tsx | 2 +- .../GiftTemplate/GIFTTemplatePreview.test.tsx | 75 ++++++++++++------- .../components/GiftTemplate/TextType.test.ts | 4 +- .../GiftTemplate/constants/styles.test.tsx | 2 +- .../StudentModeQuiz/StudentModeQuiz.tsx | 2 +- .../StudentWaitPage/StudentWaitPage.tsx | 2 +- .../TeacherModeQuiz/TeacherModeQuiz.tsx | 2 +- .../src/pages/Teacher/Dashboard/Dashboard.tsx | 3 +- .../pages/Teacher/EditorQuiz/EditorQuiz.tsx | 3 +- .../pages/Teacher/ManageRoom/ManageRoom.tsx | 1 - 13 files changed, 58 insertions(+), 44 deletions(-) diff --git a/client/babel.config.cjs b/client/babel.config.cjs index 2bda178..eae7944 100644 --- a/client/babel.config.cjs +++ b/client/babel.config.cjs @@ -1,4 +1,4 @@ -/* eslint-disable no-undef */ + module.exports = { presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'] }; diff --git a/client/jest.config.cjs b/client/jest.config.cjs index 6c635c8..b2d35cc 100644 --- a/client/jest.config.cjs +++ b/client/jest.config.cjs @@ -1,4 +1,4 @@ -/* eslint-disable no-undef */ + /** @type {import('ts-jest').JestConfigWithTsJest} */ module.exports = { diff --git a/client/jest.setup.cjs b/client/jest.setup.cjs index 30fd66a..3b56b65 100644 --- a/client/jest.setup.cjs +++ b/client/jest.setup.cjs @@ -1,3 +1,3 @@ -/* eslint-disable no-undef */ + process.env.VITE_BACKEND_URL = 'http://localhost:4000/'; process.env.VITE_BACKEND_SOCKET_URL = 'https://ets-glitch-backend.glitch.me/'; diff --git a/client/src/__tests__/Types/StudentType.test.tsx b/client/src/__tests__/Types/StudentType.test.tsx index 4e7c849..2f9efbe 100644 --- a/client/src/__tests__/Types/StudentType.test.tsx +++ b/client/src/__tests__/Types/StudentType.test.tsx @@ -12,6 +12,6 @@ describe('StudentType', () => { expect(user.name).toBe('Student'); expect(user.id).toBe('123'); - expect(user.answers.length).toBe(0); + expect(user.answers).toHaveLength(0); }); }); diff --git a/client/src/__tests__/components/GiftTemplate/GIFTTemplatePreview.test.tsx b/client/src/__tests__/components/GiftTemplate/GIFTTemplatePreview.test.tsx index 586c8d1..967d33c 100644 --- a/client/src/__tests__/components/GiftTemplate/GIFTTemplatePreview.test.tsx +++ b/client/src/__tests__/components/GiftTemplate/GIFTTemplatePreview.test.tsx @@ -5,47 +5,64 @@ import GIFTTemplatePreview from 'src/components/GiftTemplate/GIFTTemplatePreview describe('GIFTTemplatePreview Component', () => { test('renders error message when questions contain invalid syntax', () => { - render(); - const errorMessage = screen.findByText(/Erreur inconnue/i, {}, { timeout: 5000 }); - expect(errorMessage).resolves.toBeInTheDocument(); + render(); + const errorMessage = screen.getByText(/Title ::, Category, Description, or Question formatted stem but ":" found./i); + expect(errorMessage).toBeInTheDocument(); }); + test('renders preview when valid questions are provided', () => { const questions = [ - 'Question 1 { A | B | C }', - 'Question 2 { D | E | F }', + 'Stem1 {=ans1 ~ans2 ~ans3}', ]; render(); const previewContainer = screen.getByTestId('preview-container'); expect(previewContainer).toBeInTheDocument(); + // const question1 = screen.getByText('Stem1'); + const mcQuestion1 = screen.getByText('Stem1'); + const ans1 = screen.getByText('ans1'); + const ans2 = screen.getByText('ans2'); + const ans3 = screen.getByText('ans3'); + expect(mcQuestion1).toBeInTheDocument(); + expect(ans1).toBeInTheDocument(); + expect(ans2).toBeInTheDocument(); + expect(ans3).toBeInTheDocument(); + + // each answer should have a radio button before it + const radioButtons = screen.getAllByRole('radio'); + expect(radioButtons).toHaveLength(3); + // ans1 should be the