EvalueTonSavoir/client/src/__tests__/pages/Teacher/Dashboard/Dashboard.test.tsx

69 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-09-15 01:26:06 -04:00
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
2024-03-29 20:08:34 -04:00
import '@testing-library/jest-dom';
import { MemoryRouter } from 'react-router-dom';
import Dashboard from '../../../../pages/Teacher/Dashboard/Dashboard';
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 = {}),
};
})();
Object.defineProperty(window, 'localStorage', { value: localStorageMock });
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: jest.fn(),
}));
2024-09-15 01:26:06 -04:00
describe.skip('Dashboard Component', () => {
2024-03-29 20:08:34 -04:00
beforeEach(() => {
localStorage.setItem('quizzes', JSON.stringify([]));
});
test('renders Dashboard with default state', () => {
render(
<MemoryRouter>
<Dashboard />
</MemoryRouter>
);
expect(screen.getByText(/Tableau de bord/i)).toBeInTheDocument();
});
test('adds a quiz and checks if it is displayed', () => {
const mockQuizzes = [
{
id: '1',
title: 'Sample Quiz',
questions: ['Question 1?', 'Question 2?'],
},
];
localStorage.setItem('quizzes', JSON.stringify(mockQuizzes));
render(
<MemoryRouter>
<Dashboard />
</MemoryRouter>
);
expect(screen.getByText(/Sample Quiz/i)).toBeInTheDocument();
});
2024-09-15 01:26:06 -04:00
test('opens ImportModal when "Importer" button is clicked', async () => {
2024-03-29 20:08:34 -04:00
render(
<MemoryRouter>
<Dashboard />
</MemoryRouter>
);
fireEvent.click(screen.getByText(/Importer/i));
2024-09-15 01:26:06 -04:00
await waitFor(() => {
expect(screen.getByText(/Importation de quiz/i)).toBeInTheDocument();
});
2024-03-29 20:08:34 -04:00
});
});