From 8b486cf1c8c966685f94fbe5dc7dc69912936b8c Mon Sep 17 00:00:00 2001 From: "C. Fuhrman" Date: Sun, 15 Sep 2024 21:56:48 -0400 Subject: [PATCH] typos (rename), remove console.log messages, document skipped tests --- client/src/App.tsx | 2 +- .../Teacher/Dashboard/Dashboard.test.tsx | 39 ++++++++++--------- .../__tests__/services/QuizService.test.tsx | 1 + .../src/pages/Teacher/Dashboard/Dashboard.tsx | 2 +- client/src/pages/Teacher/Share/Share.tsx | 2 +- client/src/services/ApiService.tsx | 4 +- client/src/services/WebsocketService.tsx | 2 +- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 3f65f00..ab9ddff 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -27,7 +27,7 @@ const handleLogout = () => { } const isLoggedIn = () => { - return ApiService.isLogedIn(); + return ApiService.isLoggedIn(); } function App() { diff --git a/client/src/__tests__/pages/Teacher/Dashboard/Dashboard.test.tsx b/client/src/__tests__/pages/Teacher/Dashboard/Dashboard.test.tsx index 7c450dd..97500a7 100644 --- a/client/src/__tests__/pages/Teacher/Dashboard/Dashboard.test.tsx +++ b/client/src/__tests__/pages/Teacher/Dashboard/Dashboard.test.tsx @@ -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 = {}; - 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 = {}; +// 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( ); - 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(); }); }); diff --git a/client/src/__tests__/services/QuizService.test.tsx b/client/src/__tests__/services/QuizService.test.tsx index 5806e14..10ed28d 100644 --- a/client/src/__tests__/services/QuizService.test.tsx +++ b/client/src/__tests__/services/QuizService.test.tsx @@ -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') }, diff --git a/client/src/pages/Teacher/Dashboard/Dashboard.tsx b/client/src/pages/Teacher/Dashboard/Dashboard.tsx index 5595cfb..e30e497 100644 --- a/client/src/pages/Teacher/Dashboard/Dashboard.tsx +++ b/client/src/pages/Teacher/Dashboard/Dashboard.tsx @@ -43,7 +43,7 @@ const Dashboard: React.FC = () => { useEffect(() => { const fetchData = async () => { - if (!ApiService.isLogedIn()) { + if (!ApiService.isLoggedIn()) { navigate("/teacher/login"); return; } diff --git a/client/src/pages/Teacher/Share/Share.tsx b/client/src/pages/Teacher/Share/Share.tsx index dc45035..d8efcd2 100644 --- a/client/src/pages/Teacher/Share/Share.tsx +++ b/client/src/pages/Teacher/Share/Share.tsx @@ -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; diff --git a/client/src/services/ApiService.tsx b/client/src/services/ApiService.tsx index 76adf23..55dccb7 100644 --- a/client/src/services/ApiService.tsx +++ b/client/src/services/ApiService.tsx @@ -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) { diff --git a/client/src/services/WebsocketService.tsx b/client/src/services/WebsocketService.tsx index 88a2df1..3c3db74 100644 --- a/client/src/services/WebsocketService.tsx +++ b/client/src/services/WebsocketService.tsx @@ -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