-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy path013-stdcm-simulation-sheet.spec.ts
105 lines (92 loc) · 3.78 KB
/
013-stdcm-simulation-sheet.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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 test from './logging-fixture';
import STDCMPage from './pages/stdcm-page-model';
import { waitForInfraStateToBeCached } from './utils';
import { getInfra } from './utils/api-setup';
import { findFirstPdf, verifySimulationContent } from './utils/simulationSheet';
import type { ConsistFields, Simulation } from './utils/types';
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 stdcmPage: STDCMPage;
let infra: Infra;
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 }) => {
stdcmPage = new STDCMPage(page);
await page.goto('/stdcm');
await page.waitForLoadState('networkidle');
await stdcmPage.removeViteOverlay();
// Wait for infra to be in 'CACHED' state before proceeding
await waitForInfraStateToBeCached(infra.id);
});
let downloadDir: string | undefined;
/** *************** Test 1 **************** */
test('Verify STDCM stops and simulation sheet', async ({ browserName, context }, testInfo) => {
// Populate STDCM page with origin, destination, and via details
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();
downloadDir = testInfo.outputDir;
await stdcmPage.downloadSimulation(downloadDir);
// Reset and verify empty fields
const [newPage] = await Promise.all([context.waitForEvent('page'), stdcmPage.startNewQuery()]);
await newPage.waitForLoadState();
const newStdcmPage = new STDCMPage(newPage);
await newStdcmPage.verifyAllDefaultPageFields();
});
/** *************** Test 2 **************** */
test('Verify simulation sheet content', async () => {
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();
verifySimulationContent(pdfText, expectedSimulation);
});
});