Skip to content

Commit ffe0dee

Browse files
committed
front: improve page object structure and optimize project language handling for e2e tests
Signed-off-by: maymanaf <med.aymen.naf@gmail.com>
1 parent ecb261f commit ffe0dee

30 files changed

+379
-361
lines changed

front/tests/001-home-page.spec.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { expect } from '@playwright/test';
22

3+
import test from './logging-fixture';
34
import HomePage from './pages/home-page-model';
4-
import test from './test-logger';
5+
import { getTranslations } from './utils';
56
import enTranslations from '../public/locales/en/home/home.json';
67
import frTranslations from '../public/locales/fr/home/home.json';
78

89
test.describe('Home page OSRD', () => {
910
let homePage: HomePage;
10-
let OSRDLanguage: string;
11+
1112
test.beforeEach('Navigate to the home page', async ({ page }) => {
1213
homePage = new HomePage(page);
1314
await homePage.goToHomePage();
14-
OSRDLanguage = await homePage.getOSRDLanguage();
1515
});
1616

1717
test.afterEach('Returns to the home page', async () => {
@@ -20,8 +20,11 @@ test.describe('Home page OSRD', () => {
2020

2121
/** *************** Test 1 **************** */
2222
test('Verify the links for different pages in Home Page', async () => {
23-
// Determine the correct translations based on the selected language
24-
const translations = OSRDLanguage === 'English' ? enTranslations : frTranslations;
23+
const PROJECT_LANGUAGE = process.env.PROJECT_LANGUAGE || '';
24+
const translations = getTranslations(PROJECT_LANGUAGE, {
25+
en: enTranslations,
26+
fr: frTranslations,
27+
});
2528

2629
// List of expected links on the home page
2730
const expectedLinks = [

front/tests/002-project-management.spec.ts

+13-26
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import type { Project } from 'common/api/osrdEditoastApi';
22

33
import projectData from './assets/operationStudies/project.json';
4-
import HomePage from './pages/home-page-model';
4+
import test from './logging-fixture';
55
import ProjectPage from './pages/project-page-model';
6-
import test from './test-logger';
76
import { generateUniqueName } from './utils';
87
import { createProject } from './utils/setup-utils';
98
import { deleteProject } from './utils/teardown-utils';
109

1110
test.describe('Validate the Operational Study Project workflow', () => {
1211
let project: Project;
12+
let projectPage: ProjectPage;
1313

14-
/** *************** Test 1 **************** */
15-
test('Create a new project', async ({ page }) => {
16-
const projectPage = new ProjectPage(page);
17-
18-
// Navigate to the Operational Studies projects page
14+
test.beforeEach('Navigate to the projects page', async ({ page }) => {
15+
projectPage = new ProjectPage(page);
16+
// Create a project
17+
project = await createProject(generateUniqueName(projectData.name));
1918
await page.goto('/operational-studies/projects');
19+
});
2020

21+
/** *************** Test 1 **************** */
22+
test('Create a new project', async () => {
2123
// Define a unique project name for the test
2224
const projectName = generateUniqueName(projectData.name);
2325

@@ -46,15 +48,7 @@ test.describe('Validate the Operational Study Project workflow', () => {
4648
});
4749

4850
/** *************** Test 2 **************** */
49-
test('Update an existing project', async ({ page }) => {
50-
// Create a project
51-
project = await createProject(generateUniqueName(projectData.name));
52-
53-
// Navigate to the Operational Studies projects page
54-
await page.goto('/operational-studies/projects');
55-
56-
const homePage = new HomePage(page);
57-
const projectPage = new ProjectPage(page);
51+
test('Update an existing project', async () => {
5852
// Open the created project by name using the project page model
5953
await projectPage.openProjectByTestId(project.name);
6054

@@ -69,8 +63,8 @@ test.describe('Validate the Operational Study Project workflow', () => {
6963
});
7064

7165
// Navigate back to the Operational Studies page via the home page
72-
await homePage.goToHomePage();
73-
await homePage.goToOperationalStudiesPage();
66+
await projectPage.goToHomePage();
67+
await projectPage.goToOperationalStudiesPage();
7468

7569
// Reopen the updated project and validate the updated data
7670
await projectPage.openProjectByTestId(`${project.name} (updated)`);
@@ -87,14 +81,7 @@ test.describe('Validate the Operational Study Project workflow', () => {
8781
});
8882

8983
/** *************** Test 3 **************** */
90-
test('Delete a project', async ({ page }) => {
91-
// Create a project
92-
project = await createProject(generateUniqueName(projectData.name));
93-
94-
// Navigate to the Operational Studies projects page
95-
await page.goto('/operational-studies/projects');
96-
97-
const projectPage = new ProjectPage(page);
84+
test('Delete a project', async () => {
9885
// Find the project by name and delete it using the page model
9986
await projectPage.openProjectByTestId(project.name);
10087
await projectPage.deleteProject(project.name);

front/tests/003-study-management.spec.ts

+15-19
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@ import { v4 as uuidv4 } from 'uuid';
33
import type { Project, Study } from 'common/api/osrdEditoastApi';
44

55
import studyData from './assets/operationStudies/study.json';
6-
import HomePage from './pages/home-page-model';
6+
import test from './logging-fixture';
77
import StudyPage from './pages/study-page-model';
8-
import test from './test-logger';
9-
import { formatDateToDayMonthYear, generateUniqueName } from './utils';
8+
import { formatDateToDayMonthYear, generateUniqueName, getTranslations } from './utils';
109
import { getProject } from './utils/api-setup';
1110
import { createStudy } from './utils/setup-utils';
1211
import { deleteStudy } from './utils/teardown-utils';
1312
import enTranslations from '../public/locales/en/operationalStudies/study.json';
1413
import frTranslations from '../public/locales/fr/operationalStudies/study.json';
1514

1615
test.describe('Validate the Study creation workflow', () => {
16+
let studyPage: StudyPage;
1717
let project: Project;
1818
let study: Study;
19-
let OSRDLanguage: string;
20-
test.beforeAll(' Retrieve a project', async () => {
19+
let translations: typeof enTranslations | typeof frTranslations;
20+
let PROJECT_LANGUAGE: string;
21+
test.beforeAll(' Retrieve a project and the translation', async () => {
2122
project = await getProject();
23+
PROJECT_LANGUAGE = process.env.PROJECT_LANGUAGE || '';
24+
translations = getTranslations(PROJECT_LANGUAGE, {
25+
en: enTranslations,
26+
fr: frTranslations,
27+
});
2228
});
23-
24-
test.beforeEach('Create a new study linked to the project', async ({ page }) => {
25-
const homePage = new HomePage(page);
26-
await homePage.goToHomePage();
27-
OSRDLanguage = await homePage.getOSRDLanguage();
29+
test.beforeEach(async ({ page }) => {
30+
studyPage = new StudyPage(page);
2831
});
2932

3033
/** *************** Test 1 **************** */
3134
test('Create a new study', async ({ page }) => {
32-
const studyPage = new StudyPage(page);
3335
// Navigate to project page
3436
await page.goto(`/operational-studies/projects/${project.id}`);
35-
3637
// Set translations based on the language
37-
const translations = OSRDLanguage === 'English' ? enTranslations : frTranslations;
3838
const studyName = `${studyData.name} ${uuidv4()}`; // Unique study name
3939
const todayDateISO = new Date().toISOString().split('T')[0]; // Get today's date in ISO format
40-
const expectedDate = formatDateToDayMonthYear(todayDateISO, OSRDLanguage);
40+
const expectedDate = formatDateToDayMonthYear(todayDateISO, PROJECT_LANGUAGE);
4141
// Create a new study using the study page model
4242
await studyPage.createStudy({
4343
name: studyName,
@@ -72,14 +72,12 @@ test.describe('Validate the Study creation workflow', () => {
7272

7373
/** *************** Test 2 **************** */
7474
test('Update an existing study', async ({ page }) => {
75-
const studyPage = new StudyPage(page);
7675
// Create a study
7776
study = await createStudy(project.id, generateUniqueName(studyData.name));
7877
// Navigate to study page
7978
await page.goto(`/operational-studies/projects/${project.id}/studies/${study.id}`);
80-
const translations = OSRDLanguage === 'English' ? enTranslations : frTranslations;
8179
const tomorrowDateISO = new Date(Date.now() + 86400000).toISOString().split('T')[0]; // Get tomorrow's date in ISO format
82-
const expectedDate = formatDateToDayMonthYear(tomorrowDateISO, OSRDLanguage);
80+
const expectedDate = formatDateToDayMonthYear(tomorrowDateISO, PROJECT_LANGUAGE);
8381
// Update the study with new values
8482
await studyPage.updateStudy({
8583
name: `${study.name} (updated)`,
@@ -122,8 +120,6 @@ test.describe('Validate the Study creation workflow', () => {
122120
// Create a study
123121
study = await createStudy(project.id, generateUniqueName(studyData.name));
124122

125-
const studyPage = new StudyPage(page);
126-
127123
// Navigate to the list of studies for the project
128124
await page.goto(`/operational-studies/projects/${project.id}`);
129125

front/tests/004-scenario-management.spec.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import type { ElectricalProfileSet, Project, Scenario, Study } from 'common/api/
44

55
import scenarioData from './assets/operationStudies/scenario.json';
66
import { infrastructureName } from './assets/project-const';
7+
import test from './logging-fixture';
78
import ScenarioPage from './pages/scenario-page-model';
8-
import test from './test-logger';
99
import { generateUniqueName } from './utils';
1010
import { deleteApiRequest, getProject, getStudy, setElectricalProfile } from './utils/api-setup';
1111
import createScenario from './utils/scenario';
1212
import { deleteScenario } from './utils/teardown-utils';
1313

1414
test.describe('Validate the Scenario creation workflow', () => {
15+
let scenarioPage: ScenarioPage;
1516
let project: Project;
1617
let study: Study;
1718
let scenario: Scenario;
@@ -27,10 +28,12 @@ test.describe('Validate the Scenario creation workflow', () => {
2728
await deleteApiRequest(`/api/electrical_profile_set/${electricalProfileSet.id}/`);
2829
});
2930

31+
test.beforeEach(async ({ page }) => {
32+
scenarioPage = new ScenarioPage(page);
33+
});
34+
3035
/** *************** Test 1 **************** */
3136
test('Create a new scenario', async ({ page }) => {
32-
const scenarioPage = new ScenarioPage(page);
33-
3437
// Navigate to the study page for the selected project
3538
await page.goto(`/operational-studies/projects/${project.id}/studies/${study.id}`);
3639

@@ -59,8 +62,6 @@ test.describe('Validate the Scenario creation workflow', () => {
5962
// Set up a scenario
6063
({ project, study, scenario } = await createScenario());
6164

62-
const scenarioPage = new ScenarioPage(page);
63-
6465
// Navigate to the specific scenario page
6566
await page.goto(`/operational-studies/projects/${project.id}/studies/${study.id}`);
6667
await scenarioPage.openScenarioByTestId(scenario.name);
@@ -98,8 +99,6 @@ test.describe('Validate the Scenario creation workflow', () => {
9899
// Set up a scenario
99100
({ project, study, scenario } = await createScenario());
100101

101-
// Navigate to the specific scenario page
102-
const scenarioPage = new ScenarioPage(page);
103102
// Navigate to the specific scenario page
104103
await page.goto(`/operational-studies/projects/${project.id}/studies/${study.id}`);
105104
await scenarioPage.openScenarioByTestId(scenario.name);

front/tests/005-operational-studies.spec.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ import type {
99
} from 'common/api/osrdEditoastApi';
1010

1111
import { electricRollingStockName } from './assets/project-const';
12+
import test from './logging-fixture';
1213
import RoutePage from './pages/op-route-page-model';
1314
import OperationalStudiesPage from './pages/operational-studies-page-model';
1415
import RollingStockSelectorPage from './pages/rollingstock-selector-page-model';
15-
import test from './test-logger';
1616
import { waitForInfraStateToBeCached } from './utils';
1717
import { getInfra, getRollingStock } from './utils/api-setup';
1818
import createScenario from './utils/scenario';
1919
import { deleteScenario } from './utils/teardown-utils';
2020

2121
test.describe('Verify simulation configuration in operational studies', () => {
2222
test.slow();
23+
24+
let rollingstockPage: RollingStockSelectorPage;
25+
let operationalStudiesPage: OperationalStudiesPage;
26+
let routePage: RoutePage;
2327
let project: Project;
2428
let study: Study;
2529
let scenario: Scenario;
@@ -31,7 +35,13 @@ test.describe('Verify simulation configuration in operational studies', () => {
3135
infra = await getInfra();
3236
});
3337

34-
test.beforeEach('Set up the project, study, and scenario', async () => {
38+
test.beforeEach('Set up the project, study, and scenario', async ({ page }) => {
39+
[rollingstockPage, operationalStudiesPage, routePage] = [
40+
new RollingStockSelectorPage(page),
41+
new OperationalStudiesPage(page),
42+
new RoutePage(page),
43+
];
44+
3545
({ project, study, scenario } = await createScenario());
3646
});
3747

@@ -42,11 +52,6 @@ test.describe('Verify simulation configuration in operational studies', () => {
4252
/** *************** Test **************** */
4353
test('Pathfinding with rolling stock and composition code', async ({ page }) => {
4454
// Page models
45-
const [rollingstockPage, operationalStudiesPage, routePage] = [
46-
new RollingStockSelectorPage(page),
47-
new OperationalStudiesPage(page),
48-
new RoutePage(page),
49-
];
5055

5156
// Navigate to the scenario page for the given project and study
5257
await page.goto(

0 commit comments

Comments
 (0)