diff --git a/client/src/__tests__/components/DownloadQuizModal/DownloadQuizModal.test.tsx b/client/src/__tests__/components/DownloadQuizModal/DownloadQuizModal.test.tsx
new file mode 100644
index 0000000..68fc39d
--- /dev/null
+++ b/client/src/__tests__/components/DownloadQuizModal/DownloadQuizModal.test.tsx
@@ -0,0 +1,72 @@
+import React from 'react';
+import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+import '@testing-library/jest-dom';
+import DownloadQuizModal from '../../../components/DownloadQuizModal/DownloadQuizModal';
+import ApiService from '../../../services/ApiService';
+import { QuizType } from '../../../Types/QuizType';
+
+jest.mock('../../../services/ApiService');
+jest.mock('jspdf', () => {
+ return jest.fn().mockImplementation(() => ({
+ addImage: jest.fn(),
+ save: jest.fn(),
+ addPage: jest.fn(),
+ }));
+});
+jest.mock('html2canvas', () => jest.fn(() => Promise.resolve(document.createElement('canvas'))));
+jest.mock('dompurify', () => ({
+ sanitize: jest.fn((input) => input),
+}));
+
+const mockQuiz: QuizType = {
+ _id: '123',
+ title: 'Sample Quiz',
+ content: ['::Question 1:: What is 2+2? {=4 ~3 ~5}'],
+ folderId: 'folderId',
+ folderName: 'folderName',
+ userId: 'userId',
+ created_at: new Date(),
+ updated_at: new Date(),
+};
+
+describe('DownloadQuizModal', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ (ApiService.getQuiz as jest.Mock).mockResolvedValue(mockQuiz);
+ jest.spyOn(console, 'error').mockImplementation(() => {});
+ });
+
+ it('renders without crashing', () => {
+ render();
+ expect(screen.getByRole('button', { name: /télécharger quiz/i })).toBeInTheDocument();
+ });
+
+ it('opens modal when download button is clicked', () => {
+ render();
+ fireEvent.click(screen.getByRole('button', { name: /télécharger quiz/i }));
+ expect(screen.getByText(/choisissez un format de téléchargement/i)).toBeInTheDocument();
+ });
+
+ it('closes modal when a format button is clicked', async () => {
+ render();
+ fireEvent.click(screen.getByRole('button', { name: /télécharger quiz/i }));
+ fireEvent.click(screen.getByRole('button', { name: /gift/i }));
+ await waitFor(() =>
+ expect(screen.queryByText(/choisissez un format de téléchargement/i)).not.toBeInTheDocument()
+ );
+ });
+
+ it('handles error when quiz API fails', async () => {
+ (ApiService.getQuiz as jest.Mock).mockRejectedValue(new Error('Quiz not found'));
+ render();
+ fireEvent.click(screen.getByRole('button', { name: /télécharger quiz/i }));
+ fireEvent.click(screen.getByRole('button', { name: /gift/i }));
+ await waitFor(() => {
+ expect(console.error).toHaveBeenCalledWith(
+ expect.any(String),
+ expect.objectContaining({ message: expect.stringContaining("Quiz not found") })
+ );
+ });
+ });
+
+});
diff --git a/client/src/components/DownloadQuizModal/preview.html b/client/src/components/DownloadQuizModal/preview.html
deleted file mode 100644
index 8c166a2..0000000
--- a/client/src/components/DownloadQuizModal/preview.html
+++ /dev/null
@@ -1,461 +0,0 @@
-
-
-
- (Sans titre)
-
-
- Réponse courte
-
-
-
-
-
-
- Avec quoi ouvre-t-on une porte?
-
-
-
-
-
- Réponse:
-
-
-
-
- (Sans titre)
-
-
- Numérique
-
-
-
-
-
-
- Quel est un nombre de 1 à 5 ?
-
-
-
-
-
-
- (Sans titre)
-
-
- Numérique
-
-
-
-
-
-
- Quel est un nombre de 1 à 5 ?
-
-
-
-
-
-
- (Sans titre)
-
-
- Numérique
-
-
-
-
-
-
- Quand est né Ulysses S. Grant ?
-
-
-
-
\ No newline at end of file