Skip to content

Commit 19912ba

Browse files
committed
front: add import trains e2e tests
1 parent 1b14ae3 commit 19912ba

24 files changed

+1162
-154
lines changed

front/src/modules/study/components/StudyCardEmpty.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function StudyCard() {
1212

1313
return (
1414
<div
15-
data-testid="addStudy"
15+
data-testid="add-study-button"
1616
className="study-card empty"
1717
role="button"
1818
tabIndex={0}

front/src/modules/trainschedule/components/TimetableV2/TimetableToolbar.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const TimetableToolbar = ({
179179
</>
180180
)}
181181
</div>
182-
<div>
182+
<div data-testid="train-count">
183183
{trainSchedules.length > 0
184184
? t(
185185
'trainCount',
@@ -208,6 +208,7 @@ const TimetableToolbar = ({
208208
)}
209209

210210
<button
211+
data-testid="timetable-filter-button"
211212
aria-label={t('timetable.toggleFilters')}
212213
onClick={toggleFilterPanel}
213214
type="button"

front/src/modules/trainschedule/components/TimetableV2/TimetableTrainCardV2.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const TimetableTrainCardV2 = ({
169169
return (
170170
<div className="scenario-timetable-train-with-right-bar">
171171
<div
172+
data-testid="scenario-timetable-train"
172173
className={cx(
173174
'scenario-timetable-train with-colored-border',
174175
`colored-border-${intervalPosition}`,
@@ -189,6 +190,7 @@ const TimetableTrainCardV2 = ({
189190
/>
190191
)}
191192
<div
193+
data-testid="scenario-timetable-train-button"
192194
className="scenario-timetable-train-container"
193195
role="button"
194196
tabIndex={0}

front/src/modules/trainschedule/components/TimetableV2/TimetableV2.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ const TimetableV2 = ({
175175
{timetableHasInvalidTrain(displayedTrainSchedules) && (
176176
<div className="invalid-trains">
177177
<Alert size="lg" variant="fill" />
178-
<span className="flex-grow-1">{t('timetable.invalidTrains')}</span>
178+
<span data-testid="invalid-trains-message" className="flex-grow-1">
179+
{t('timetable.invalidTrains')}
180+
</span>
179181
</div>
180182
)}
181183
{conflicts && (

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import projectData from './assets/operationStudies/project.json';
77
import CommonPage from './pages/common-page-model';
88
import HomePage from './pages/home-page-model';
99
import ProjectPage from './pages/project-page-model';
10-
import { deleteApiRequest, getApiRequest, postApiRequest } from './utils/index';
10+
import { deleteApiRequest, getApiRequest, postApiRequest } from './utils/api-setup';
1111

1212
let project: Project;
1313

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import studyData from './assets/operationStudies/study.json';
77
import CommonPage from './pages/common-page-model';
88
import HomePage from './pages/home-page-model';
99
import StudyPage from './pages/study-page-model';
10-
import { getProject, postApiRequest } from './utils/index';
10+
import { getProject, postApiRequest } from './utils/api-setup';
1111

1212
let project: Project;
1313
let study: Study;
@@ -33,7 +33,7 @@ test.describe('Test if operationnal study: study creation workflow is working pr
3333

3434
await page.goto(`/operational-studies/projects/${project.id}`);
3535

36-
expect(studyPage.getAddStudyBtn).toBeVisible();
36+
await expect(studyPage.getAddStudyBtn).toBeVisible();
3737
await studyPage.openStudyCreationModal();
3838

3939
const studyName = `${studyData.name} ${uuidv4()}`;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import scenarioData from './assets/operationStudies/scenario.json';
1313
import CommonPage from './pages/common-page-model';
1414
import HomePage from './pages/home-page-model';
1515
import ScenarioPage from './pages/scenario-page-model';
16-
import { getInfra, getProject, getStudy, postApiRequest } from './utils/index';
16+
import { getInfra, getProject, getStudy, postApiRequest } from './utils/api-setup';
1717

1818
let smallInfra: Infra;
1919
let project: Project;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import scenarioData from './assets/operationStudies/scenario.json';
1414
import HomePage from './pages/home-page-model';
1515
import RollingStockSelectorPage from './pages/rollingstock-selector-page';
1616
import ScenarioPage from './pages/scenario-page-model';
17-
import { getInfra, getProject, getRollingStock, getStudy, postApiRequest } from './utils/index';
17+
import { getProject, getStudy, getRollingStock, postApiRequest, getInfra } from './utils/api-setup';
1818

1919
let smallInfra: Infra;
2020
let project: Project;

front/tests/007-op-rollingstock-tab.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import scenarioData from './assets/operationStudies/scenario.json';
1414
import OperationalStudiesPage from './pages/operational-studies-page-model';
1515
import RollingStockSelectorPage from './pages/rollingstock-selector-page';
1616
import ScenarioPage from './pages/scenario-page-model';
17-
import { getInfra, getProject, getRollingStock, getStudy, postApiRequest } from './utils/index';
17+
import { getProject, getStudy, getRollingStock, postApiRequest, getInfra } from './utils/api-setup';
1818

1919
let smallInfra: Infra;
2020
let project: Project;
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { test } from '@playwright/test';
2+
3+
import type { Scenario, Study, Project } from 'common/api/osrdEditoastApi';
4+
5+
import HomePage from './pages/home-page-model';
6+
import OperationalStudiesTimetablePage from './pages/op-timetable-page-model';
7+
import ScenarioPage from './pages/scenario-page-model';
8+
import { readJsonFile } from './utils';
9+
import setupScenario from './utils/scenario';
10+
import { postSimulation, sendTrainSchedules } from './utils/trainSchedule';
11+
12+
let selectedLanguage: string;
13+
let project: Project;
14+
let study: Study;
15+
let scenario: Scenario;
16+
17+
const trainSchedulesJson = readJsonFile('./tests/assets/trainSchedule/train_schedules.json');
18+
19+
test.beforeAll(async () => {
20+
({ project, study, scenario } = await setupScenario());
21+
22+
// Post train schedule import and simulation
23+
const response = await sendTrainSchedules(scenario.timetable_id, trainSchedulesJson);
24+
await postSimulation(response, scenario.infra_id);
25+
});
26+
27+
test.beforeEach(async ({ page }) => {
28+
const homePage = new HomePage(page);
29+
await homePage.goToHomePage();
30+
selectedLanguage = await homePage.getOSRDLanguage();
31+
32+
// Navigate to the created scenario page
33+
await page.goto(
34+
`/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}`
35+
);
36+
});
37+
38+
test.describe('Verifying that all elements in the train schedule are loaded correctly', () => {
39+
test('should accurately load the trains with their corresponding simulation results', async ({
40+
page,
41+
}) => {
42+
test.setTimeout(120000);
43+
const scenarioPage = new ScenarioPage(page);
44+
const opTimetablePage = new OperationalStudiesTimetablePage(page);
45+
46+
// Check if the infrastructure is loaded
47+
await scenarioPage.checkInfraLoaded();
48+
49+
// Verify the train count and various elements on the timetable page
50+
await opTimetablePage.verifyTrainCount(20, selectedLanguage);
51+
await opTimetablePage.verifyInvalidTrainsMessageVisibility(selectedLanguage);
52+
await opTimetablePage.checkSelectedTimetableTrain();
53+
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Valid', 16);
54+
await opTimetablePage.verifyEachTrainSimulation();
55+
});
56+
57+
test('should accurately filter the imported trains', async ({ page }) => {
58+
test.setTimeout(120000);
59+
const scenarioPage = new ScenarioPage(page);
60+
const opTimetablePage = new OperationalStudiesTimetablePage(page);
61+
62+
// Check if the infrastructure is loaded
63+
await scenarioPage.checkInfraLoaded();
64+
65+
// Verify the train count and apply various filters
66+
await opTimetablePage.verifyTrainCount(20, selectedLanguage);
67+
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Invalid', 4);
68+
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'All', 20);
69+
await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'Honored', 12);
70+
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Valid', 12);
71+
await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'Not honored', 4);
72+
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Invalid', 0);
73+
await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'All', 4);
74+
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'All', 20);
75+
76+
// Define the composition filters and verify each filter
77+
const compositionFilters = [
78+
{ code: 'MA100', count: 7 },
79+
{ code: 'HLP', count: 3 },
80+
{ code: 'E32C', count: 1 },
81+
{ code: 'Without code', count: 9 },
82+
];
83+
84+
await compositionFilters.reduce(async (promise, filter) => {
85+
await promise;
86+
return opTimetablePage.clickCodeCompoTrainFilterButton(
87+
selectedLanguage,
88+
filter.code,
89+
filter.count
90+
);
91+
}, Promise.resolve());
92+
});
93+
});

front/tests/009-rollingstock-editor.spec.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import fs from 'fs';
1+
/* eslint-disable no-restricted-syntax, no-await-in-loop */
22
import path from 'path';
33

44
import { test, expect } from '@playwright/test';
55

66
import RollingstockEditorPage from './pages/rollingstock-editor-page-model';
77
import RollingStockSelectorPage from './pages/rollingstock-selector-page';
88
import {
9-
findAndDeleteRollingStocks,
109
generateUniqueName,
1110
verifyAndCheckInputById,
1211
fillAndCheckInputById,
12+
readJsonFile,
1313
} from './utils/index';
14+
import { findAndDeleteRollingStocksByName } from './utils/rollingStock';
1415

1516
// Correct path to load rolling stock details from JSON
1617
const rollingstockDetailsPath = path.resolve(
1718
__dirname,
1819
'../tests/assets/rollingStock/rollingstockDetails.json'
1920
);
2021

21-
const rollingstockDetails = JSON.parse(fs.readFileSync(rollingstockDetailsPath, 'utf-8'));
22+
const rollingstockDetails = readJsonFile(rollingstockDetailsPath);
2223
const dualModeRollingStockName = 'dual-mode_rollingstock_test_e2e';
2324
const electricRollingStockName = 'rollingstock_1500_25000_test_e2e';
2425

@@ -33,7 +34,7 @@ test.describe('Rollingstock editor page', () => {
3334
uniqueDeletedRollingStockName = await generateUniqueName('D_RSN');
3435

3536
// Check and delete the specified rolling stocks if they exist
36-
await findAndDeleteRollingStocks([
37+
await findAndDeleteRollingStocksByName([
3738
uniqueRollingStockName,
3839
uniqueUpdatedRollingStockName,
3940
uniqueDeletedRollingStockName,
@@ -42,7 +43,7 @@ test.describe('Rollingstock editor page', () => {
4243

4344
test.afterEach(async () => {
4445
// Clean up by deleting the created or updated rolling stock
45-
await findAndDeleteRollingStocks([
46+
await findAndDeleteRollingStocksByName([
4647
uniqueRollingStockName,
4748
uniqueUpdatedRollingStockName,
4849
uniqueDeletedRollingStockName,

front/tests/010-op-route-tab.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import scenarioData from './assets/operationStudies/scenario.json';
1313
import HomePage from './pages/home-page-model';
1414
import OperationalStudiesPage from './pages/operational-studies-page-model';
1515
import ScenarioPage from './pages/scenario-page-model';
16-
import { getInfra, getProject, getStudy, postApiRequest } from './utils/index';
16+
import { getProject, getStudy, postApiRequest, getInfra } from './utils/api-setup';
1717

1818
let smallInfra: Infra;
1919
let project: Project;

0 commit comments

Comments
 (0)