Skip to content

Commit

Permalink
front: add stdcm simulation sheet e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: maymanaf <[email protected]>
  • Loading branch information
Maymanaf committed Jan 13, 2025
1 parent e3af230 commit 8d3db3d
Show file tree
Hide file tree
Showing 15 changed files with 524 additions and 79 deletions.
37 changes: 37 additions & 0 deletions front/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"maplibre-gl": "^4.0.0",
"openapi-typescript-codegen": "^0.29.0",
"party-js": "^2.2.0",
"pdf-parse": "^1.1.1",
"prop-types": "^15.8.1",
"rc-slider": "^11.1.8",
"react": "^18.2.0",
Expand Down Expand Up @@ -112,6 +113,7 @@
"@types/jest": "^29.5.14",
"@types/lodash": "^4.17.14",
"@types/node": "^22",
"@types/pdf-parse": "^1.1.4",
"@types/react": "^18.2.53",
"@types/react-beautiful-dnd": "^13.1.8",
"@types/react-dom": "^18.2.18",
Expand Down
7 changes: 4 additions & 3 deletions front/src/assets/rollingStock/freightRollingStocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ export const FREIGHT_ROLLING_STOCKS = [
'Y8000AG',
'Y8000AP',
'Y9000US',
'electric_rolling_stock_test_e2e',
// TODO Find a better solution for injecting test data.
'FAST_ROLLING_STOCK_TEST_E2E',
// TODO: Find a better solution for injecting e2e test data.
'ELECTRIC_RS_E2E',
'FAST_RS_E2E',
];

export const ALLOWED_TOWED_ROLLING_STOCKS = [
Expand All @@ -125,5 +125,6 @@ export const ALLOWED_TOWED_ROLLING_STOCKS = [
'ME200SER',
'MEPA',
'TRAINLOC',
// TODO: Find a better solution for injecting e2e test data.
'TOWED-TEST-E2E',
];
2 changes: 1 addition & 1 deletion front/tests/005-operational-studies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test.describe('Verify simulation configuration in operational studies', () => {
await expect(rollingstockPage.rollingStockSelectorModal).toBeVisible();

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

// Select the rolling stock card based on the test ID
const rollingstockCard = rollingstockPage.getRollingstockCardByTestID(
Expand Down
41 changes: 2 additions & 39 deletions front/tests/006-stdcm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.use({
slowMo: 500, // Give the interface time to update between actions
},
});
test.describe('Verify train schedule elements and filters', () => {
test.describe('Verify stdcm simulation page', () => {
test.slow(); // Mark test as slow due to multiple steps

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

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

/** *************** Test 3 **************** */
test('Verify STDCM stops and simulation sheet', async ({ page, browserName }) => {
// Populate STDCM page with origin, destination, and via details
const stdcmPage = new STDCMPage(page);
await stdcmPage.fillAndVerifyConsistDetails(
consistDetails,
tractionEnginePrefilledValues.tonnage,
tractionEnginePrefilledValues.length,
tractionEnginePrefilledValues.maxSpeed
);
await stdcmPage.fillOriginDetailsLight();
await stdcmPage.fillDestinationDetailsLight();
await stdcmPage.fillAndVerifyViaDetails({
viaNumber: 1,
ciSearchText: 'mid_west',
});
// Verify input map markers in Chromium
if (browserName === 'chromium') {
await stdcmPage.mapMarkerVisibility();
}
// Launch simulation and verify output data matches expected results
await stdcmPage.launchSimulation();
// Verify map results markers in Chromium
if (browserName === 'chromium') {
await stdcmPage.mapMarkerResultVisibility();
}
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithoutAllVia.json');
await stdcmPage.displayAllOperationalPoints();
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithAllVia.json');
await stdcmPage.retainSimulation();
await stdcmPage.downloadSimulation(browserName);
// Reset and verify empty fields
await stdcmPage.startNewQuery();
// TODO: Uncomment the check when the bug #9533 is fixed
// await stdcmPage.verifyAllFieldsEmpty();
});

/** *************** Test 4 **************** */
test('Launch simulation with and without capacity for towed rolling stock', async ({ page }) => {
const towedConsistDetails: ConsistFields = {
tractionEngine: fastRollingStockName,
Expand Down
112 changes: 112 additions & 0 deletions front/tests/013-stdcm-simulation-sheet.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import fs from 'fs';

import pdfParse from 'pdf-parse';

import type { Infra } from 'common/api/osrdEditoastApi';

import { electricRollingStockName } from './assets/project-const';
import simulationSheetDetails from './assets/simulation-sheet-const';
import HomePage from './pages/home-page-model';
import STDCMPage, { type ConsistFields } from './pages/stdcm-page-model';
import test from './test-logger';
import { waitForInfraStateToBeCached } from './utils';
import { getInfra } from './utils/api-setup';
import { findFirstPdf, verifySimulationContent, type Simulation } from './utils/simulationSheet';

test.use({
launchOptions: {
slowMo: 500, // Give the interface time to update between actions
},
});
test.describe('Verify stdcm simulation page', () => {
test.describe.configure({ mode: 'serial' }); // Configure this block to run serially
test.slow(); // Mark test as slow due to multiple steps
test.use({ viewport: { width: 1920, height: 1080 } });

let infra: Infra;
let OSRDLanguage: string;
const consistDetails: ConsistFields = {
tractionEngine: electricRollingStockName,
tonnage: '950',
length: '567',
maxSpeed: '180',
speedLimitTag: 'HLP',
};
const tractionEnginePrefilledValues = {
tonnage: '900',
length: '400',
maxSpeed: '288',
};

test.beforeAll('Fetch infrastructure', async () => {
infra = await getInfra();
});

test.beforeEach('Navigate to the STDCM page', async ({ page }) => {
// Retrieve OSRD language and navigate to STDCM page
const homePage = new HomePage(page);
await homePage.goToHomePage();
OSRDLanguage = await homePage.getOSRDLanguage();
await page.goto('/stdcm');
await page.waitForLoadState('domcontentloaded', { timeout: 30_000 });
await homePage.removeViteOverlay();

// Wait for infra to be in 'CACHED' state before proceeding
await waitForInfraStateToBeCached(infra.id);
});

/** *************** Test 1 **************** */
test('Verify STDCM stops and simulation sheet', async ({ page, browserName, context }) => {
// Populate STDCM page with origin, destination, and via details
const stdcmPage = new STDCMPage(page);
await stdcmPage.fillAndVerifyConsistDetails(
consistDetails,
tractionEnginePrefilledValues.tonnage,
tractionEnginePrefilledValues.length,
tractionEnginePrefilledValues.maxSpeed
);
await stdcmPage.fillOriginDetailsLight();
await stdcmPage.fillDestinationDetailsLight();
await stdcmPage.fillAndVerifyViaDetails({
viaNumber: 1,
ciSearchText: 'mid_west',
});
// Verify input map markers in Chromium
if (browserName === 'chromium') {
await stdcmPage.mapMarkerVisibility();
}
// Launch simulation and verify output data matches expected results
await stdcmPage.launchSimulation();
// Verify map results markers in Chromium
if (browserName === 'chromium') {
await stdcmPage.mapMarkerResultVisibility();
}
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithoutAllVia.json');
await stdcmPage.displayAllOperationalPoints();
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithAllVia.json');
await stdcmPage.retainSimulation();
await stdcmPage.downloadSimulation(browserName);
// Reset and verify empty fields
const [newPage] = await Promise.all([context.waitForEvent('page'), stdcmPage.startNewQuery()]);
await newPage.waitForLoadState();
// TODO: Uncomment the check when the bug #10335 is fixed
// const newStdcmPage = new STDCMPage(newPage);
// await newStdcmPage.verifyAllFieldsEmpty();
});

/** *************** Test 2 **************** */
test('Verify simulation sheet content', async ({ browserName }) => {
const downloadDir = `./tests/stdcm-results/${browserName}`;
const pdfFilePath = findFirstPdf(downloadDir);

if (!pdfFilePath) {
throw new Error(`No PDF files found in directory: ${downloadDir}`);
}
// Read and parse the PDF
const pdfBuffer = fs.readFileSync(pdfFilePath);
const pdfData = await pdfParse(pdfBuffer);
const pdfText = pdfData.text;
const expectedSimulation: Simulation = simulationSheetDetails(OSRDLanguage);
verifySimulationContent(pdfText, expectedSimulation);
});
});
10 changes: 5 additions & 5 deletions front/tests/assets/project-const.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const electricRollingStockName = 'electric_rolling_stock_test_e2e';
export const dualModeRollingStockName = 'dual-mode_rolling_stock_test_e2e';
export const slowRollingStockName = 'slow_rolling_stock_test_e2e';
export const fastRollingStockName = 'FAST_ROLLING_STOCK_TEST_E2E';
export const improbableRollingStockName = 'improbable_rolling_stock_test_e2e';
export const electricRollingStockName = 'ELECTRIC_RS_E2E';
export const dualModeRollingStockName = 'DUAL-MODE_RS_E2E';
export const slowRollingStockName = 'SLOW_RS_E2E';
export const fastRollingStockName = 'FAST_RS_E2E';
export const improbableRollingStockName = 'IMPROBABLE_RS_E2E';
export const infrastructureName = 'small_infra_test_e2e';
export const trainScheduleProjectName = 'TS_project_test_e2e';
export const globalProjectName = 'project_test_e2e';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"railjson_version": "3.2",
"name": "dual-mode_rolling_stock_test_e2e",
"name": "DUAL-MODE_RS_E2Ee",
"effort_curves": {
"modes": {
"25000V": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": 789,
"railjson_version": "3.2",
"name": "improbable_rolling_stock_test_e2e",
"name": "IMPROBABLE_RS_E2E",
"effort_curves": {
"modes": {
"1500V": {
Expand Down
Loading

0 comments on commit 8d3db3d

Please sign in to comment.