Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ANT-2712_unit_test_study_provider #75

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions src/hooks/test/useFetchTrajectoriesFromDB.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { renderHook, waitFor } from '@testing-library/react';
import { TRAJECTORY_TYPE } from '@/shared/enum/trajectory.ts';
import { useFetchTrajectoriesFromDB } from '@/hooks/useFetchTrajectoriesFromDB.ts';
import { mockResponseTrajectoriesDB } from '@/mocks/data/list/trajectory.ts';

const mockFetch = vi.fn();
global.fetch = mockFetch;
Expand All @@ -15,25 +16,6 @@ vi.mock('@/envVariables', () => ({
getEnvVariables: vi.fn(() => 'https://mockapi.com'),
}));

const mockResponseTrajectoriesDB = [
{
id: 1,
trajectory_name: 'area_PB_2024',
type: TRAJECTORY_TYPE.AREA,
version: 3,
user_name: 'mouad',
creation_date: '2024-07-22 15:13:56.860045' as unknown as Date,
},
{
id: 2,
trajectory_name: 'area_PB_2026',
type: TRAJECTORY_TYPE.AREA,
version: 3,
user_name: 'mouad',
creation_date: '2026-08-22 15:13:56.860045' as unknown as Date,
},
];

describe('useFetchTrajectoriesFromDB', () => {
beforeEach(() => {
global.fetch = vi.fn().mockResolvedValueOnce({
Expand Down
48 changes: 1 addition & 47 deletions src/hooks/test/useHandlePinnedProjectList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,7 @@ import { fetchPinnedProjects, pinProject } from '@/shared/services/pinnedProject
import { v4 as uuidv4 } from 'uuid';
import { notifyToast } from '@/shared/notification/notification.tsx';
import { PROJECT_ACTION } from '@/shared/enum/project.ts';

const mockProjectsApiResponse = [
{
id: '1',
name: 'Bilan previsionnel 2027',
createdBy: 'MOUAD Paris test',
creationDate: '2024-07-25T10:09:41',
studies: [1, 2, 3],
tags: ['gaz', 'elec', 'antares', 'misc', 'tag2 antares', 'area link'],
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
projectId: '1',
pinned: true,
},
{
id: '2',
name: 'Bilan previsionnel 2023',
createdBy: 'Taher benjelloun amine',
creationDate: '2024-07-25T10:09:41',
studies: [6, 5, 9],
tags: ['bilan 22'],
description: 'description2023',
projectId: '2',
pinned: true,
},
{
id: '3',
name: 'Bilan previsionnel 2025',
createdBy: 'zayd guillaume pegase',
creationDate: '2024-07-25T10:09:41',
studies: [7, 8],
tags: ['figma', 'config', 'modal'],
description: 'In the world of software development, achieving perfection is a journey rather than a destination.',
projectId: '3',
pinned: true,
},
];
import { mockPinProjectResponse, mockProjectsApiResponse } from '@/mocks/data/list/projects.ts';

vi.mock('@/envVariables', () => ({
getEnvVariables: vi.fn(() => 'https://mockapi.com'),
Expand Down Expand Up @@ -115,17 +80,6 @@ describe('useHandlePinnedProjectList', () => {

it('should call handlePinProject that calls pinProject and dispatch and update pinned project list correctly', async () => {
const mockPinProject = pinProject as Mock;
const mockPinProjectResponse = {
id: '3',
name: 'Bilan previsionnel 2025',
createdBy: 'zayd guillaume pegase',
creationDate: '2024-07-25T10:09:41',
studies: [7, 8],
tags: ['figma', 'config', 'modal'],
description: 'In the world of software development, achieving perfection is a journey rather than a destination.',
projectId: '3',
pinned: true,
};
mockPinProject.mockResolvedValueOnce(mockPinProjectResponse);

mockUsePinnedProjectDispatch.mockReturnValue(mockDispatch);
Expand Down
21 changes: 2 additions & 19 deletions src/hooks/test/useStudyNavigation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,8 @@ import { act, Queries, renderHook, RenderHookOptions } from '@testing-library/re
import { useStudyNavigation } from '@/hooks/useStudyNavigation.ts';
import { Router, useNavigate } from 'react-router-dom';
import { ReactNode } from 'react';

const mockNavigator = {
createHref: vi.fn(),
go: vi.fn(),
push: vi.fn(),
replace: vi.fn(),
};

const mockStudy = {
id: 1,
name: 'BP_ref_1',
createdBy: 'Isaac Asimov',
creationDate: new Date('Janvier 18'),
keywords: ['covid', 'silence'],
project: 'Bilan previsionnel 2027',
status: 'missing',
horizon: '2020_2024',
trajectoryIds: [2],
};
import { mockStudy } from '@/mocks/data/list/study.ts';
import { mockNavigator } from '@/mocks/data/router.ts';

vi.mock('react-router-dom', async (importOriginal) => {
const actual: Mock = await importOriginal();
Expand Down
47 changes: 47 additions & 0 deletions src/mocks/data/list/projects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export const mockProjectsApiResponse = [
{
id: '1',
name: 'Bilan previsionnel 2027',
createdBy: 'MOUAD Paris test',
creationDate: '2024-07-25T10:09:41',
studies: [1, 2, 3],
tags: ['gaz', 'elec', 'antares', 'misc', 'tag2 antares', 'area link'],
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
projectId: '1',
pinned: true,
},
{
id: '2',
name: 'Bilan previsionnel 2023',
createdBy: 'Taher benjelloun amine',
creationDate: '2024-07-25T10:09:41',
studies: [6, 5, 9],
tags: ['bilan 22'],
description: 'description2023',
projectId: '2',
pinned: true,
},
{
id: '3',
name: 'Bilan previsionnel 2025',
createdBy: 'zayd guillaume pegase',
creationDate: '2024-07-25T10:09:41',
studies: [7, 8],
tags: ['figma', 'config', 'modal'],
description: 'In the world of software development, achieving perfection is a journey rather than a destination.',
projectId: '3',
pinned: true,
},
];

export const mockPinProjectResponse = {
id: '3',
name: 'Bilan previsionnel 2025',
createdBy: 'zayd guillaume pegase',
creationDate: '2024-07-25T10:09:41',
studies: [7, 8],
tags: ['figma', 'config', 'modal'],
description: 'In the world of software development, achieving perfection is a journey rather than a destination.',
projectId: '3',
pinned: true,
};
68 changes: 68 additions & 0 deletions src/mocks/data/list/study.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

const STUDY_NAME: string[] = [
'CreaCode',
'PixelArt',
'TechGenie',
'InnoCréa',
'WebMerveille',
'DataMagique',
'AppMagicien',
'ByteCréatif',
'PixelGénial',
'TechCréation',
'InnoCréatif',
'WebCréateur',
'DataCréatif',
'AppArchitecte',
'ByteBrillant',
'PixelChemin',
'TechTonique',
'InnoÉtincelle',
'WebRapide',
];

export default STUDY_NAME;

export const mockStudy = {
id: 1,
name: 'BP_ref_1',
createdBy: 'Isaac Asimov',
creationDate: new Date('Janvier 18'),
keywords: ['covid', 'silence'],
project: 'Bilan previsionnel 2027',
status: 'missing',
horizon: '2020_2024',
trajectoryIds: [2],
};

export const mockResponseGetStudyApi = {
content: [
{
id: 1,
name: 'Project 1',
createdBy: 'User A',
creationDate: '2023-10-01',
keywords: ['Keyword1', 'Keyword2'],
project: '1',
status: 'IN_PROGRESS',
horizon: '2030-2031',
trajectoryIds: [1, 7],
},
],
totalElements: 1,
};

export const mockResponseSaveStudyApi = {
id: 1,
name: 'Project 1',
createdBy: 'User A',
keywords: ['Keyword1', 'Keyword2'],
project: '1',
horizon: '2030-2031',
trajectoryIds: [1, 7],
};
29 changes: 0 additions & 29 deletions src/mocks/data/list/studyName.ts

This file was deleted.

59 changes: 59 additions & 0 deletions src/mocks/data/list/trajectory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { DbTrajectory } from '@/shared/types';
import { TRAJECTORY_TYPE } from '@/shared/enum/trajectory.ts';

export const mockResponseTrajectoryListFS = [
{
trajectoryName: 'area_BP_2028',
type: TRAJECTORY_TYPE.AREA,
lastModifiedDate: '2026-08-22 15:13:56.860045' as unknown as Date,
},
{
trajectoryName: 'area_BP_2027',
type: TRAJECTORY_TYPE.AREA,
lastModifiedDate: '2026-08-22 15:13:56.860045' as unknown as Date,
},
{
trajectoryName: 'area_BP_2030_2050',
type: TRAJECTORY_TYPE.AREA,
lastModifiedDate: '2026-08-22 15:13:56.860045' as unknown as Date,
},
];

export const mockResponseTrajectoryDB: DbTrajectory = {
id: 1,
trajectoryName: 'area_BP_23_v6',
type: TRAJECTORY_TYPE.AREA,
version: 6,
userName: 'mouad',
creationDate: '2024-07-22 15:13:56.860045' as unknown as Date,
};

export const mockResponseGetTrajectoryFromStudy: DbTrajectory[] = [
{
id: 2,
trajectoryName: 'area_BP_23_v6',
type: TRAJECTORY_TYPE.AREA,
version: 6,
userName: 'mouad',
creationDate: '2024-07-22 15:13:56.860045' as unknown as Date,
},
];

export const mockResponseTrajectoriesDB = [
{
id: 1,
trajectoryName: 'area_PB_2024',
type: TRAJECTORY_TYPE.AREA,
version: 3,
userName: 'mouad',
creationDate: '2024-07-22 15:13:56.860045' as unknown as Date,
},
{
id: 2,
trajectoryName: 'area_PB_2026',
type: TRAJECTORY_TYPE.AREA,
version: 3,
userName: 'mouad',
creationDate: '2026-08-22 15:13:56.860045' as unknown as Date,
},
];
17 changes: 0 additions & 17 deletions src/mocks/data/list/trajectoryFS.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/mocks/data/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { vi } from 'vitest';

export const mockNavigator = {
createHref: vi.fn(),
go: vi.fn(),
push: vi.fn(),
replace: vi.fn(),
};
2 changes: 1 addition & 1 deletion src/pages/pegase/home/components/MainContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const MainContent = () => {
<Route
path="/study/:studyName"
element={
<StudyProvider initialValue={{ isStudyGenerated: false }}>
<StudyProvider>
<StudyDetails />
</StudyProvider>
}
Expand Down
Loading
Loading