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 = () => {
|
const isLoggedIn = () => {
|
||||||
return ApiService.isLogedIn();
|
return ApiService.isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
function App() {
|
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 '@testing-library/jest-dom';
|
||||||
import { MemoryRouter } from 'react-router-dom';
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import Dashboard from '../../../../pages/Teacher/Dashboard/Dashboard';
|
import Dashboard from '../../../../pages/Teacher/Dashboard/Dashboard';
|
||||||
|
import { act } from 'react';
|
||||||
|
|
||||||
const localStorageMock = (() => {
|
// const localStorageMock = (() => {
|
||||||
let store: Record<string, string> = {};
|
// let store: Record<string, string> = {};
|
||||||
return {
|
// return {
|
||||||
getItem: (key: string) => store[key] || null,
|
// getItem: (key: string) => store[key] || null,
|
||||||
setItem: (key: string, value: string) => (store[key] = value.toString()),
|
// setItem: (key: string, value: string) => (store[key] = value.toString()),
|
||||||
clear: () => (store = {}),
|
// clear: () => (store = {}),
|
||||||
};
|
// };
|
||||||
})();
|
// })();
|
||||||
Object.defineProperty(window, 'localStorage', { value: localStorageMock });
|
// Object.defineProperty(window, 'localStorage', { value: localStorageMock });
|
||||||
|
|
||||||
jest.mock('react-router-dom', () => ({
|
jest.mock('react-router-dom', () => ({
|
||||||
...jest.requireActual('react-router-dom'),
|
...jest.requireActual('react-router-dom'),
|
||||||
useNavigate: jest.fn(),
|
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', () => {
|
describe.skip('Dashboard Component', () => {
|
||||||
beforeEach(() => {
|
// beforeEach(() => {
|
||||||
localStorage.setItem('quizzes', JSON.stringify([]));
|
// localStorage.setItem('quizzes', JSON.stringify([]));
|
||||||
});
|
// });
|
||||||
|
|
||||||
test('renders Dashboard with default state', () => {
|
test('renders Dashboard with default state', () => {
|
||||||
render(
|
render(
|
||||||
|
|
@ -33,7 +35,7 @@ describe.skip('Dashboard Component', () => {
|
||||||
expect(screen.getByText(/Tableau de bord/i)).toBeInTheDocument();
|
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 = [
|
const mockQuizzes = [
|
||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
|
|
@ -52,17 +54,18 @@ describe.skip('Dashboard Component', () => {
|
||||||
expect(screen.getByText(/Sample Quiz/i)).toBeInTheDocument();
|
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(
|
render(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<Dashboard />
|
<Dashboard />
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
act(() => {
|
||||||
fireEvent.click(screen.getByText(/Importer/i));
|
fireEvent.click(screen.getByText(/Importer/i));
|
||||||
await waitFor(() => {
|
|
||||||
expect(screen.getByText(/Importation de quiz/i)).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(screen.getByText(/Importation de quiz/i)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ Object.defineProperty(window, 'localStorage', {
|
||||||
value: localStorageMock
|
value: localStorageMock
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// NOTE: this suite seems to be designed around local storage of quizzes (older version, before a database)
|
||||||
describe.skip('QuizService', () => {
|
describe.skip('QuizService', () => {
|
||||||
const mockQuizzes: QuizType[] = [
|
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') },
|
{ 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(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
if (!ApiService.isLogedIn()) {
|
if (!ApiService.isLoggedIn()) {
|
||||||
navigate("/teacher/login");
|
navigate("/teacher/login");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ const Share: React.FC = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ApiService.isLogedIn()) {
|
if (!ApiService.isLoggedIn()) {
|
||||||
window.alert(`Vous n'êtes pas connecté.\nVeuillez vous connecter et revenir à ce lien`);
|
window.alert(`Vous n'êtes pas connecté.\nVeuillez vous connecter et revenir à ce lien`);
|
||||||
navigate("/teacher/login");
|
navigate("/teacher/login");
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class ApiService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private constructRequestHeaders(): any {
|
private constructRequestHeaders(): any {
|
||||||
if (this.isLogedIn()) {
|
if (this.isLoggedIn()) {
|
||||||
return {
|
return {
|
||||||
Authorization: `Bearer ${this.getToken()}`,
|
Authorization: `Bearer ${this.getToken()}`,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|
@ -63,7 +63,7 @@ class ApiService {
|
||||||
return object.token;
|
return object.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public isLogedIn(): boolean {
|
public isLoggedIn(): boolean {
|
||||||
const token = this.getToken()
|
const token = this.getToken()
|
||||||
|
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ class WebSocketService {
|
||||||
private socket: Socket | null = null;
|
private socket: Socket | null = null;
|
||||||
|
|
||||||
connect(backendUrl: string): Socket {
|
connect(backendUrl: string): Socket {
|
||||||
console.log(backendUrl);
|
// console.log(backendUrl);
|
||||||
this.socket = io(`${backendUrl}`, {
|
this.socket = io(`${backendUrl}`, {
|
||||||
transports: ['websocket'],
|
transports: ['websocket'],
|
||||||
reconnectionAttempts: 1
|
reconnectionAttempts: 1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue