-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy path013-stdcm-simulation-sheet.spec.ts
47 lines (36 loc) · 1.52 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
import fs from 'fs';
import pdfParse from 'pdf-parse';
import simulationSheetDetails from './assets/simulationSheet-const';
import HomePage from './pages/home-page-model';
import test, { logger } from './test-logger';
import { findFirstPdf, verifySimulationContent, type Simulation } from './utils/simulationSheet';
let OSRDLanguage: string;
test.beforeEach(
'Navigate to Times and Stops tab with rolling stock and route set',
async ({ page }) => {
const homePage = new HomePage(page);
await homePage.goToHomePage();
OSRDLanguage = await homePage.getOSRDLanguage();
}
);
test('Verify PDF content', async ({ browserName }) => {
/**
* Finds the first `.pdf` file in the specified directory.
* @param directory The directory to search in.
* @returns The path of the first `.pdf` file or `null` if not found.
*/
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);
// Dynamically create the expected simulation based on language
const expectedSimulation: Simulation = simulationSheetDetails(OSRDLanguage);
// Verify PDF content
const pdfText = pdfData.text;
const isCorrect = verifySimulationContent(pdfText, expectedSimulation);
logger.info(isCorrect ? 'Simulation data is correct!' : 'Mismatch in simulation data.');
});