|
| 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 | +}); |
0 commit comments