mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
typos (rename), remove console.log messages, document skipped tests
This commit is contained in:
parent
c0e95f2a0d
commit
8b486cf1c8
7 changed files with 28 additions and 24 deletions
|
|
@ -27,7 +27,7 @@ const handleLogout = () => {
|
|||
}
|
||||
|
||||
const isLoggedIn = () => {
|
||||
return ApiService.isLogedIn();
|
||||
return ApiService.isLoggedIn();
|
||||
}
|
||||
|
||||
function App() {
|
||||
|
|
|
|||
|
|
@ -1,28 +1,30 @@
|
|||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import Dashboard from '../../../../pages/Teacher/Dashboard/Dashboard';
|
||||
import { act } from 'react';
|
||||
|
||||
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 });
|
||||
// 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(),
|
||||
}));
|
||||
|
||||
// NOTE: these tests are for an old version that kept quizzes in local storage and had no login
|
||||
|
||||
describe.skip('Dashboard Component', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.setItem('quizzes', JSON.stringify([]));
|
||||
});
|
||||
// beforeEach(() => {
|
||||
// localStorage.setItem('quizzes', JSON.stringify([]));
|
||||
// });
|
||||
|
||||
test('renders Dashboard with default state', () => {
|
||||
render(
|
||||
|
|
@ -33,7 +35,7 @@ describe.skip('Dashboard Component', () => {
|
|||
expect(screen.getByText(/Tableau de bord/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('adds a quiz and checks if it is displayed', () => {
|
||||
test.skip('adds a quiz and checks if it is displayed', () => {
|
||||
const mockQuizzes = [
|
||||
{
|
||||
id: '1',
|
||||
|
|
@ -52,17 +54,18 @@ describe.skip('Dashboard Component', () => {
|
|||
expect(screen.getByText(/Sample Quiz/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('opens ImportModal when "Importer" button is clicked', async () => {
|
||||
test.skip('opens ImportModal when "Importer" button is clicked', async () => {
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<Dashboard />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByText(/Importer/i));
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/Importation de quiz/i)).toBeInTheDocument();
|
||||
act(() => {
|
||||
fireEvent.click(screen.getByText(/Importer/i));
|
||||
});
|
||||
|
||||
expect(screen.getByText(/Importation de quiz/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ Object.defineProperty(window, 'localStorage', {
|
|||
value: localStorageMock
|
||||
});
|
||||
|
||||
// NOTE: this suite seems to be designed around local storage of quizzes (older version, before a database)
|
||||
describe.skip('QuizService', () => {
|
||||
const mockQuizzes: QuizType[] = [
|
||||
{ folderId: 'test', userId: 'user', _id: 'quiz1', title: 'Quiz One', content: ['Q1', 'Q2'], created_at: new Date('2024-09-15'), updated_at: new Date('2024-09-15') },
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ const Dashboard: React.FC = () => {
|
|||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
if (!ApiService.isLogedIn()) {
|
||||
if (!ApiService.isLoggedIn()) {
|
||||
navigate("/teacher/login");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ const Share: React.FC = () => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!ApiService.isLogedIn()) {
|
||||
if (!ApiService.isLoggedIn()) {
|
||||
window.alert(`Vous n'êtes pas connecté.\nVeuillez vous connecter et revenir à ce lien`);
|
||||
navigate("/teacher/login");
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class ApiService {
|
|||
}
|
||||
|
||||
private constructRequestHeaders(): any {
|
||||
if (this.isLogedIn()) {
|
||||
if (this.isLoggedIn()) {
|
||||
return {
|
||||
Authorization: `Bearer ${this.getToken()}`,
|
||||
'Content-Type': 'application/json'
|
||||
|
|
@ -63,7 +63,7 @@ class ApiService {
|
|||
return object.token;
|
||||
}
|
||||
|
||||
public isLogedIn(): boolean {
|
||||
public isLoggedIn(): boolean {
|
||||
const token = this.getToken()
|
||||
|
||||
if (token == null) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class WebSocketService {
|
|||
private socket: Socket | null = null;
|
||||
|
||||
connect(backendUrl: string): Socket {
|
||||
console.log(backendUrl);
|
||||
// console.log(backendUrl);
|
||||
this.socket = io(`${backendUrl}`, {
|
||||
transports: ['websocket'],
|
||||
reconnectionAttempts: 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue