Skip to content

Commit 8d3db3d

Browse files
committed
front: add stdcm simulation sheet e2e test
Signed-off-by: maymanaf <med.aymen.naf@gmail.com>
1 parent e3af230 commit 8d3db3d

15 files changed

+524
-79
lines changed

front/package-lock.json

+37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"maplibre-gl": "^4.0.0",
7070
"openapi-typescript-codegen": "^0.29.0",
7171
"party-js": "^2.2.0",
72+
"pdf-parse": "^1.1.1",
7273
"prop-types": "^15.8.1",
7374
"rc-slider": "^11.1.8",
7475
"react": "^18.2.0",
@@ -112,6 +113,7 @@
112113
"@types/jest": "^29.5.14",
113114
"@types/lodash": "^4.17.14",
114115
"@types/node": "^22",
116+
"@types/pdf-parse": "^1.1.4",
115117
"@types/react": "^18.2.53",
116118
"@types/react-beautiful-dnd": "^13.1.8",
117119
"@types/react-dom": "^18.2.18",

front/src/assets/rollingStock/freightRollingStocks.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ export const FREIGHT_ROLLING_STOCKS = [
107107
'Y8000AG',
108108
'Y8000AP',
109109
'Y9000US',
110-
'electric_rolling_stock_test_e2e',
111-
// TODO Find a better solution for injecting test data.
112-
'FAST_ROLLING_STOCK_TEST_E2E',
110+
// TODO: Find a better solution for injecting e2e test data.
111+
'ELECTRIC_RS_E2E',
112+
'FAST_RS_E2E',
113113
];
114114

115115
export const ALLOWED_TOWED_ROLLING_STOCKS = [
@@ -125,5 +125,6 @@ export const ALLOWED_TOWED_ROLLING_STOCKS = [
125125
'ME200SER',
126126
'MEPA',
127127
'TRAINLOC',
128+
// TODO: Find a better solution for injecting e2e test data.
128129
'TOWED-TEST-E2E',
129130
];

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ test.describe('Verify simulation configuration in operational studies', () => {
6969
await expect(rollingstockPage.rollingStockSelectorModal).toBeVisible();
7070

7171
// Test rolling stock search with normalization (spaces and capital letters)
72-
await rollingstockPage.searchRollingstock(' electric_rolling_stock_test_E2E ');
72+
await rollingstockPage.searchRollingstock(' electric__Rs_E2e ');
7373

7474
// Select the rolling stock card based on the test ID
7575
const rollingstockCard = rollingstockPage.getRollingstockCardByTestID(

front/tests/006-stdcm.spec.ts

+2-39
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test.use({
1212
slowMo: 500, // Give the interface time to update between actions
1313
},
1414
});
15-
test.describe('Verify train schedule elements and filters', () => {
15+
test.describe('Verify stdcm simulation page', () => {
1616
test.slow(); // Mark test as slow due to multiple steps
1717

1818
test.use({ viewport: { width: 1920, height: 1080 } });
@@ -55,7 +55,7 @@ test.describe('Verify train schedule elements and filters', () => {
5555
await homePage.goToHomePage();
5656
OSRDLanguage = await homePage.getOSRDLanguage();
5757
await page.goto('/stdcm');
58-
await page.waitForLoadState('load', { timeout: 30 * 1000 });
58+
await page.waitForLoadState('domcontentloaded', { timeout: 30_000 });
5959
await homePage.removeViteOverlay();
6060

6161
// Wait for infra to be in 'CACHED' state before proceeding
@@ -99,43 +99,6 @@ test.describe('Verify train schedule elements and filters', () => {
9999
});
100100

101101
/** *************** Test 3 **************** */
102-
test('Verify STDCM stops and simulation sheet', async ({ page, browserName }) => {
103-
// Populate STDCM page with origin, destination, and via details
104-
const stdcmPage = new STDCMPage(page);
105-
await stdcmPage.fillAndVerifyConsistDetails(
106-
consistDetails,
107-
tractionEnginePrefilledValues.tonnage,
108-
tractionEnginePrefilledValues.length,
109-
tractionEnginePrefilledValues.maxSpeed
110-
);
111-
await stdcmPage.fillOriginDetailsLight();
112-
await stdcmPage.fillDestinationDetailsLight();
113-
await stdcmPage.fillAndVerifyViaDetails({
114-
viaNumber: 1,
115-
ciSearchText: 'mid_west',
116-
});
117-
// Verify input map markers in Chromium
118-
if (browserName === 'chromium') {
119-
await stdcmPage.mapMarkerVisibility();
120-
}
121-
// Launch simulation and verify output data matches expected results
122-
await stdcmPage.launchSimulation();
123-
// Verify map results markers in Chromium
124-
if (browserName === 'chromium') {
125-
await stdcmPage.mapMarkerResultVisibility();
126-
}
127-
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithoutAllVia.json');
128-
await stdcmPage.displayAllOperationalPoints();
129-
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithAllVia.json');
130-
await stdcmPage.retainSimulation();
131-
await stdcmPage.downloadSimulation(browserName);
132-
// Reset and verify empty fields
133-
await stdcmPage.startNewQuery();
134-
// TODO: Uncomment the check when the bug #9533 is fixed
135-
// await stdcmPage.verifyAllFieldsEmpty();
136-
});
137-
138-
/** *************** Test 4 **************** */
139102
test('Launch simulation with and without capacity for towed rolling stock', async ({ page }) => {
140103
const towedConsistDetails: ConsistFields = {
141104
tractionEngine: fastRollingStockName,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import fs from 'fs';
2+
3+
import pdfParse from 'pdf-parse';
4+
5+
import type { Infra } from 'common/api/osrdEditoastApi';
6+
7+
import { electricRollingStockName } from './assets/project-const';
8+
import simulationSheetDetails from './assets/simulation-sheet-const';
9+
import HomePage from './pages/home-page-model';
10+
import STDCMPage, { type ConsistFields } from './pages/stdcm-page-model';
11+
import test from './test-logger';
12+
import { waitForInfraStateToBeCached } from './utils';
13+
import { getInfra } from './utils/api-setup';
14+
import { findFirstPdf, verifySimulationContent, type Simulation } from './utils/simulationSheet';
15+
16+
test.use({
17+
launchOptions: {
18+
slowMo: 500, // Give the interface time to update between actions
19+
},
20+
});
21+
test.describe('Verify stdcm simulation page', () => {
22+
test.describe.configure({ mode: 'serial' }); // Configure this block to run serially
23+
test.slow(); // Mark test as slow due to multiple steps
24+
test.use({ viewport: { width: 1920, height: 1080 } });
25+
26+
let infra: Infra;
27+
let OSRDLanguage: string;
28+
const consistDetails: ConsistFields = {
29+
tractionEngine: electricRollingStockName,
30+
tonnage: '950',
31+
length: '567',
32+
maxSpeed: '180',
33+
speedLimitTag: 'HLP',
34+
};
35+
const tractionEnginePrefilledValues = {
36+
tonnage: '900',
37+
length: '400',
38+
maxSpeed: '288',
39+
};
40+
41+
test.beforeAll('Fetch infrastructure', async () => {
42+
infra = await getInfra();
43+
});
44+
45+
test.beforeEach('Navigate to the STDCM page', async ({ page }) => {
46+
// Retrieve OSRD language and navigate to STDCM page
47+
const homePage = new HomePage(page);
48+
await homePage.goToHomePage();
49+
OSRDLanguage = await homePage.getOSRDLanguage();
50+
await page.goto('/stdcm');
51+
await page.waitForLoadState('domcontentloaded', { timeout: 30_000 });
52+
await homePage.removeViteOverlay();
53+
54+
// Wait for infra to be in 'CACHED' state before proceeding
55+
await waitForInfraStateToBeCached(infra.id);
56+
});
57+
58+
/** *************** Test 1 **************** */
59+
test('Verify STDCM stops and simulation sheet', async ({ page, browserName, context }) => {
60+
// Populate STDCM page with origin, destination, and via details
61+
const stdcmPage = new STDCMPage(page);
62+
await stdcmPage.fillAndVerifyConsistDetails(
63+
consistDetails,
64+
tractionEnginePrefilledValues.tonnage,
65+
tractionEnginePrefilledValues.length,
66+
tractionEnginePrefilledValues.maxSpeed
67+
);
68+
await stdcmPage.fillOriginDetailsLight();
69+
await stdcmPage.fillDestinationDetailsLight();
70+
await stdcmPage.fillAndVerifyViaDetails({
71+
viaNumber: 1,
72+
ciSearchText: 'mid_west',
73+
});
74+
// Verify input map markers in Chromium
75+
if (browserName === 'chromium') {
76+
await stdcmPage.mapMarkerVisibility();
77+
}
78+
// Launch simulation and verify output data matches expected results
79+
await stdcmPage.launchSimulation();
80+
// Verify map results markers in Chromium
81+
if (browserName === 'chromium') {
82+
await stdcmPage.mapMarkerResultVisibility();
83+
}
84+
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithoutAllVia.json');
85+
await stdcmPage.displayAllOperationalPoints();
86+
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithAllVia.json');
87+
await stdcmPage.retainSimulation();
88+
await stdcmPage.downloadSimulation(browserName);
89+
// Reset and verify empty fields
90+
const [newPage] = await Promise.all([context.waitForEvent('page'), stdcmPage.startNewQuery()]);
91+
await newPage.waitForLoadState();
92+
// TODO: Uncomment the check when the bug #10335 is fixed
93+
// const newStdcmPage = new STDCMPage(newPage);
94+
// await newStdcmPage.verifyAllFieldsEmpty();
95+
});
96+
97+
/** *************** Test 2 **************** */
98+
test('Verify simulation sheet content', async ({ browserName }) => {
99+
const downloadDir = `./tests/stdcm-results/${browserName}`;
100+
const pdfFilePath = findFirstPdf(downloadDir);
101+
102+
if (!pdfFilePath) {
103+
throw new Error(`No PDF files found in directory: ${downloadDir}`);
104+
}
105+
// Read and parse the PDF
106+
const pdfBuffer = fs.readFileSync(pdfFilePath);
107+
const pdfData = await pdfParse(pdfBuffer);
108+
const pdfText = pdfData.text;
109+
const expectedSimulation: Simulation = simulationSheetDetails(OSRDLanguage);
110+
verifySimulationContent(pdfText, expectedSimulation);
111+
});
112+
});

front/tests/assets/project-const.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export const electricRollingStockName = 'electric_rolling_stock_test_e2e';
2-
export const dualModeRollingStockName = 'dual-mode_rolling_stock_test_e2e';
3-
export const slowRollingStockName = 'slow_rolling_stock_test_e2e';
4-
export const fastRollingStockName = 'FAST_ROLLING_STOCK_TEST_E2E';
5-
export const improbableRollingStockName = 'improbable_rolling_stock_test_e2e';
1+
export const electricRollingStockName = 'ELECTRIC_RS_E2E';
2+
export const dualModeRollingStockName = 'DUAL-MODE_RS_E2E';
3+
export const slowRollingStockName = 'SLOW_RS_E2E';
4+
export const fastRollingStockName = 'FAST_RS_E2E';
5+
export const improbableRollingStockName = 'IMPROBABLE_RS_E2E';
66
export const infrastructureName = 'small_infra_test_e2e';
77
export const trainScheduleProjectName = 'TS_project_test_e2e';
88
export const globalProjectName = 'project_test_e2e';

front/tests/assets/rollingStock/dual-mode_rolling_stock.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"railjson_version": "3.2",
3-
"name": "dual-mode_rolling_stock_test_e2e",
3+
"name": "DUAL-MODE_RS_E2Ee",
44
"effort_curves": {
55
"modes": {
66
"25000V": {

front/tests/assets/rollingStock/improbable_rolling_stock.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": 789,
33
"railjson_version": "3.2",
4-
"name": "improbable_rolling_stock_test_e2e",
4+
"name": "IMPROBABLE_RS_E2E",
55
"effort_curves": {
66
"modes": {
77
"1500V": {

0 commit comments

Comments
 (0)