|
| 1 | +import { test } from '@playwright/test'; |
| 2 | + |
| 3 | +import type { Scenario, Study, Project } from 'common/api/osrdEditoastApi'; |
| 4 | + |
| 5 | +import HomePage from './pages/home-page-model'; |
| 6 | +import OperationalStudiesTimetablePage from './pages/op-timetable-page-model'; |
| 7 | +import ScenarioPage from './pages/scenario-page-model'; |
| 8 | +import { readJsonFile } from './utils'; |
| 9 | +import setupScenario from './utils/scenario'; |
| 10 | +import { postSimulation, sendTrainSchedules } from './utils/trainSchedule'; |
| 11 | + |
| 12 | +let selectedLanguage: string; |
| 13 | +let project: Project; |
| 14 | +let study: Study; |
| 15 | +let scenario: Scenario; |
| 16 | + |
| 17 | +const trainSchedulesJson = readJsonFile('./tests/assets/trainSchedule/train_schedules.json'); |
| 18 | + |
| 19 | +test.beforeAll(async () => { |
| 20 | + ({ project, study, scenario } = await setupScenario()); |
| 21 | + |
| 22 | + // Post train schedule import and simulation |
| 23 | + const response = await sendTrainSchedules(scenario.timetable_id, trainSchedulesJson); |
| 24 | + await postSimulation(response, scenario.infra_id); |
| 25 | +}); |
| 26 | + |
| 27 | +test.beforeEach(async ({ page }) => { |
| 28 | + const homePage = new HomePage(page); |
| 29 | + await homePage.goToHomePage(); |
| 30 | + selectedLanguage = await homePage.getOSRDLanguage(); |
| 31 | + |
| 32 | + // Navigate to the created scenario page |
| 33 | + await page.goto( |
| 34 | + `/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}` |
| 35 | + ); |
| 36 | +}); |
| 37 | + |
| 38 | +test.describe('Verifying that all elements in the train schedule are loaded correctly', () => { |
| 39 | + test('should accurately load the trains with their corresponding simulation results', async ({ |
| 40 | + page, |
| 41 | + }) => { |
| 42 | + test.setTimeout(120000); |
| 43 | + const scenarioPage = new ScenarioPage(page); |
| 44 | + const opTimetablePage = new OperationalStudiesTimetablePage(page); |
| 45 | + |
| 46 | + // Check if the infrastructure is loaded |
| 47 | + await scenarioPage.checkInfraLoaded(); |
| 48 | + |
| 49 | + // Verify the train count and various elements on the timetable page |
| 50 | + await opTimetablePage.verifyTrainCount(20, selectedLanguage); |
| 51 | + await opTimetablePage.verifyInvalidTrainsMessageVisibility(selectedLanguage); |
| 52 | + await opTimetablePage.checkSelectedTimetableTrain(); |
| 53 | + await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Valid', 16); |
| 54 | + await opTimetablePage.verifyEachTrainSimulation(); |
| 55 | + }); |
| 56 | + |
| 57 | + test('should accurately filter the imported trains', async ({ page }) => { |
| 58 | + test.setTimeout(120000); |
| 59 | + const scenarioPage = new ScenarioPage(page); |
| 60 | + const opTimetablePage = new OperationalStudiesTimetablePage(page); |
| 61 | + |
| 62 | + // Check if the infrastructure is loaded |
| 63 | + await scenarioPage.checkInfraLoaded(); |
| 64 | + |
| 65 | + // Verify the train count and apply various filters |
| 66 | + await opTimetablePage.verifyTrainCount(20, selectedLanguage); |
| 67 | + await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Invalid', 4); |
| 68 | + await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'All', 20); |
| 69 | + await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'Honored', 12); |
| 70 | + await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Valid', 12); |
| 71 | + await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'Not honored', 4); |
| 72 | + await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Invalid', 0); |
| 73 | + await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'All', 4); |
| 74 | + await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'All', 20); |
| 75 | + |
| 76 | + // Define the composition filters and verify each filter |
| 77 | + const compositionFilters = [ |
| 78 | + { code: 'MA100', count: 7 }, |
| 79 | + { code: 'HLP', count: 3 }, |
| 80 | + { code: 'E32C', count: 1 }, |
| 81 | + { code: 'Without code', count: 9 }, |
| 82 | + ]; |
| 83 | + |
| 84 | + await compositionFilters.reduce(async (promise, filter) => { |
| 85 | + await promise; |
| 86 | + return opTimetablePage.clickCodeCompoTrainFilterButton( |
| 87 | + selectedLanguage, |
| 88 | + filter.code, |
| 89 | + filter.count |
| 90 | + ); |
| 91 | + }, Promise.resolve()); |
| 92 | + }); |
| 93 | +}); |
0 commit comments