mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Compare commits
2 commits
5cdf4abd92
...
58da59c632
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58da59c632 | ||
|
|
b0cbb7af39 |
2 changed files with 30 additions and 37 deletions
|
|
@ -1,62 +1,55 @@
|
|||
import React from 'react';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import QuizForm from '../../../../pages/Teacher/EditorQuiz/EditorQuiz';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
|
||||
// Mock localStorage with proper TypeScript types
|
||||
const localStorageMock = (() => {
|
||||
let store: Record<string, string> = {};
|
||||
return {
|
||||
getItem: (key: string) => store[key] || null,
|
||||
setItem: (key: string, value: string) => (store[key] = value.toString()),
|
||||
clear: () => (store = {}),
|
||||
getItem: (key: string): string | null => store[key] || null,
|
||||
setItem: (key: string, value: string): void => {
|
||||
store[key] = value.toString();
|
||||
},
|
||||
clear: (): void => {
|
||||
store = {};
|
||||
},
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(window, 'localStorage', { value: localStorageMock });
|
||||
|
||||
// Mock react-router-dom
|
||||
const mockNavigate = jest.fn();
|
||||
jest.mock('react-router-dom', () => ({
|
||||
...jest.requireActual('react-router-dom'),
|
||||
useNavigate: jest.fn(),
|
||||
useNavigate: () => mockNavigate,
|
||||
useParams: () => ({ id: 'new' }), // Simulate the "new" route
|
||||
}));
|
||||
|
||||
// Mock ApiService
|
||||
jest.mock('../../../../services/ApiService', () => ({
|
||||
getUserFolders: jest.fn(() => Promise.resolve([])), // Mock empty folder list
|
||||
getQuiz: jest.fn(),
|
||||
createQuiz: jest.fn(),
|
||||
updateQuiz: jest.fn(),
|
||||
uploadImage: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('QuizForm Component', () => {
|
||||
test('renders QuizForm with default state for a new quiz', () => {
|
||||
test('renders QuizForm with default state for a new quiz', async () => {
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/teacher/editor-quiz/new']}>
|
||||
<QuizForm />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(screen.queryByText('Éditeur de quiz')).toBeInTheDocument();
|
||||
// expect(screen.queryByText('Éditeur')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Prévisualisation')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test.skip('renders QuizForm for a new quiz', async () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter initialEntries={['/teacher/editor-quiz']}>
|
||||
<QuizForm />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(screen.getByText(/Éditeur de quiz/i)).toBeInTheDocument();
|
||||
|
||||
// find the 'editor' text area
|
||||
const editorTextArea = container.querySelector('textarea.editor');
|
||||
fireEvent.change(editorTextArea!, { target: { value: 'Sample question?' } });
|
||||
|
||||
// Wait for the component to render the title
|
||||
await waitFor(() => {
|
||||
const sampleQuestionElements = screen.queryAllByText(/Sample question\?/i);
|
||||
expect(sampleQuestionElements.length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('Éditeur de Quiz')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
const saveButton = screen.getByText(/Enregistrer/i);
|
||||
fireEvent.click(saveButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/Sauvegarder le questionnaire/i)).toBeInTheDocument();
|
||||
// Check for other expected elements
|
||||
expect(screen.getByText('Prévisualisation')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -21,7 +21,7 @@ const GIFTTemplatePreview: React.FC<GIFTTemplatePreviewProps> = ({
|
|||
useEffect(() => {
|
||||
try {
|
||||
const previewItems: string[] = [];
|
||||
questions.forEach((giftQuestion, index) => {
|
||||
questions.forEach((giftQuestion) => {
|
||||
try {
|
||||
const question = parse(giftQuestion);
|
||||
const html = Template(question[0], {
|
||||
|
|
|
|||
Loading…
Reference in a new issue