-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
front: add times and stops e2e test for operational studies
Signed-off-by: maymanaf <med.aymen.naf@gmail.com>
- Loading branch information
Showing
11 changed files
with
660 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
import type { Project, Scenario, Study } from 'common/api/osrdEditoastApi'; | ||
|
||
import HomePage from './pages/home-page-model'; | ||
import OperationalStudiesInputTablePage from './pages/op-input-table-page-model'; | ||
import OperationalStudiesOutputTablePage from './pages/op-output-table-page-model'; | ||
import OperationalStudiesTimetablePage from './pages/op-timetable-page-model'; | ||
import OperationalStudiesPage from './pages/operational-studies-page-model'; | ||
import ScenarioPage from './pages/scenario-page-model'; | ||
import { readJsonFile } from './utils'; | ||
import { cleanWhitespace, cleanWhitespaces, type StationData } from './utils/dataNormalizer'; | ||
import setupScenario from './utils/scenario'; | ||
import scrollContainer from './utils/scrollHelper'; | ||
import enTranslations from '../public/locales/en/timesStops.json'; | ||
import frTranslations from '../public/locales/fr/timesStops.json'; | ||
|
||
let project: Project; | ||
let study: Study; | ||
let selectedLanguage: string; | ||
let scenario: Scenario; | ||
|
||
const fastRollingStockName = 'fast_rolling_stock_test_e2e'; | ||
const inputExpectedData = readJsonFile( | ||
'./tests/assets/operationStudies/timesAndStops/timesAndStopsInput.json' | ||
); | ||
|
||
const inputExpectedUpdatedData = readJsonFile( | ||
'./tests/assets/operationStudies/timesAndStops/timesAndStopsDeletedInput.json' | ||
); | ||
const outputExpectedData: StationData[] = readJsonFile( | ||
'./tests/assets/operationStudies/timesAndStops/timesAndStopsOutput.json' | ||
); | ||
const cellData: CellData[] = readJsonFile( | ||
'./tests/assets/operationStudies/timesAndStops/timesAndStopsCellData.json' | ||
); | ||
|
||
type TranslationKeys = keyof typeof enTranslations; | ||
|
||
interface CellData { | ||
stationName: string; | ||
header: TranslationKeys; | ||
value: string; | ||
marginForm?: string; | ||
} | ||
|
||
test.beforeEach(async ({ page }) => { | ||
({ project, study, scenario } = await setupScenario()); | ||
const homePage = new HomePage(page); | ||
await homePage.goToHomePage(); | ||
selectedLanguage = await homePage.getOSRDLanguage(); | ||
|
||
await page.goto( | ||
`/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}` | ||
); | ||
}); | ||
|
||
test.describe('Times and Stops Tab Verification', () => { | ||
test('should correctly set and display times and stops tables', async ({ page }) => { | ||
const [ | ||
opInputTablePage, | ||
opTimetablePage, | ||
opOutputTablePage, | ||
operationalStudiesPage, | ||
scenarioPage, | ||
] = [ | ||
new OperationalStudiesInputTablePage(page), | ||
new OperationalStudiesTimetablePage(page), | ||
new OperationalStudiesOutputTablePage(page), | ||
new OperationalStudiesPage(page), | ||
new ScenarioPage(page), | ||
]; | ||
|
||
await scenarioPage.checkInfraLoaded(); | ||
await operationalStudiesPage.clickOnAddTrainBtn(); | ||
|
||
await scenarioPage.setTrainScheduleName('Train1'); | ||
await page.waitForTimeout(500); | ||
await operationalStudiesPage.setTrainStartTime('2024-09-19T11:22:40'); | ||
await operationalStudiesPage.selectRollingStock(fastRollingStockName); | ||
|
||
await scenarioPage.openTabByDataId('tab-pathfinding'); | ||
await operationalStudiesPage.performPathfindingByTrigram('WS', 'NES'); | ||
await scenarioPage.openTabByDataId('tab-timesStops'); | ||
|
||
await scrollContainer(page, '.time-stops-datasheet .dsg-container'); | ||
|
||
const translations = selectedLanguage === 'English' ? enTranslations : frTranslations; | ||
const expectedColumnNames = cleanWhitespaces([ | ||
translations.name, | ||
'Ch', | ||
translations.arrivalTime, | ||
translations.departureTime, | ||
translations.stopTime, | ||
translations.receptionOnClosedSignal, | ||
translations.theoreticalMargin, | ||
]); | ||
|
||
const actualColumnHeaders = cleanWhitespaces( | ||
await opInputTablePage.columnHeaders.allInnerTexts() | ||
); | ||
expect(actualColumnHeaders).toEqual(expectedColumnNames); | ||
|
||
await opInputTablePage.verifyActiveRowsCount(2); | ||
|
||
for (const cell of cellData) { | ||
const translatedHeader = cleanWhitespace(translations[cell.header]); | ||
await opInputTablePage.fillTableCellByStationAndHeader( | ||
cell.stationName, | ||
translatedHeader, | ||
cell.value, | ||
selectedLanguage, | ||
cell.marginForm | ||
); | ||
} | ||
|
||
await opInputTablePage.verifyActiveRowsCount(4); | ||
await opInputTablePage.verifyDeleteButtons(2); | ||
await opInputTablePage.verifyInputTableData(inputExpectedData); | ||
|
||
await scenarioPage.openTabByDataId('tab-pathfinding'); | ||
|
||
const expectedValues = [ | ||
{ name: 'Mid_West_station', ch: 'BV', uic: '3', km: 'KM 11.850' }, | ||
{ name: 'Mid_East_station', ch: 'BV', uic: '4', km: 'KM 26.300' }, | ||
]; | ||
|
||
for (const [index, expectedValue] of expectedValues.entries()) { | ||
const droppedWaypoint = operationalStudiesPage.droppedWaypoints.nth(index); | ||
await OperationalStudiesPage.validateAddedWaypoint( | ||
droppedWaypoint, | ||
expectedValue.name, | ||
expectedValue.ch, | ||
expectedValue.uic | ||
); | ||
} | ||
|
||
await scenarioPage.addTrainSchedule(); | ||
await scenarioPage.returnSimulationResult(); | ||
await expect(opTimetablePage.timeStopsDatasheet).toBeVisible(); | ||
await scrollContainer(page, '.osrd-simulation-container .time-stops-datasheet .dsg-container'); | ||
|
||
await opOutputTablePage.getOutputTableData(outputExpectedData); | ||
}); | ||
test('should correctly clear input table row', async ({ page }) => { | ||
const [opInputTablePage, operationalStudiesPage, scenarioPage] = [ | ||
new OperationalStudiesInputTablePage(page), | ||
new OperationalStudiesPage(page), | ||
new ScenarioPage(page), | ||
]; | ||
|
||
await scenarioPage.checkInfraLoaded(); | ||
await operationalStudiesPage.clickOnAddTrainBtn(); | ||
|
||
await scenarioPage.setTrainScheduleName('Train1'); | ||
await page.waitForTimeout(500); | ||
await operationalStudiesPage.setTrainStartTime('2024-09-19T11:22:40'); | ||
await operationalStudiesPage.selectRollingStock(fastRollingStockName); | ||
|
||
await scenarioPage.openTabByDataId('tab-pathfinding'); | ||
await operationalStudiesPage.performPathfindingByTrigram('WS', 'NES'); | ||
await scenarioPage.openTabByDataId('tab-timesStops'); | ||
|
||
await scrollContainer(page, '.time-stops-datasheet .dsg-container'); | ||
|
||
const translations = selectedLanguage === 'English' ? enTranslations : frTranslations; | ||
|
||
await opInputTablePage.verifyActiveRowsCount(2); | ||
|
||
for (const cell of cellData) { | ||
const translatedHeader = cleanWhitespace(translations[cell.header]); | ||
await opInputTablePage.fillTableCellByStationAndHeader( | ||
cell.stationName, | ||
translatedHeader, | ||
cell.value, | ||
selectedLanguage, | ||
cell.marginForm | ||
); | ||
} | ||
|
||
await opInputTablePage.verifyActiveRowsCount(4); | ||
await opInputTablePage.verifyDeleteButtons(2); | ||
await opInputTablePage.deleteButtons.nth(0).click(); | ||
await opInputTablePage.verifyActiveRowsCount(4); | ||
await opInputTablePage.verifyDeleteButtons(1); | ||
await opInputTablePage.verifyInputTableData(inputExpectedUpdatedData); | ||
|
||
await scenarioPage.openTabByDataId('tab-pathfinding'); | ||
|
||
const expectedValues = [ | ||
{ name: 'Mid_West_station', ch: 'BV', uic: '3', km: 'KM 11.850' }, | ||
{ name: 'Mid_East_station', ch: 'BV', uic: '4', km: 'KM 26.300' }, | ||
]; | ||
|
||
for (const [index, expectedValue] of expectedValues.entries()) { | ||
const droppedWaypoint = operationalStudiesPage.droppedWaypoints.nth(index); | ||
await OperationalStudiesPage.validateAddedWaypoint( | ||
droppedWaypoint, | ||
expectedValue.name, | ||
expectedValue.ch, | ||
expectedValue.uic | ||
); | ||
} | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
front/tests/assets/operationStudies/timesAndStops/timesAndStopsCellData.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[ | ||
{ | ||
"stationName": "West_station", | ||
"header": "theoreticalMargin", | ||
"value": "5%", | ||
"marginForm": "% ou min/100km" | ||
}, | ||
{ | ||
"stationName": "Mid_West_station", | ||
"header": "theoreticalMargin", | ||
"value": "1min/100km", | ||
"marginForm": "% ou min/100km" | ||
}, | ||
{ | ||
"stationName": "Mid_West_station", | ||
"header": "arrivalTime", | ||
"value": "14:22:40" | ||
}, | ||
{ | ||
"stationName": "Mid_West_station", | ||
"header": "stopTime", | ||
"value": "300" | ||
}, | ||
{ | ||
"stationName": "Mid_East_station", | ||
"header": "arrivalTime", | ||
"value": "18:23:19" | ||
}, | ||
{ | ||
"stationName": "Mid_East_station", | ||
"header": "stopTime", | ||
"value": "124" | ||
} | ||
] |
18 changes: 18 additions & 0 deletions
18
front/tests/assets/operationStudies/timesAndStops/timesAndStopsDeletedInput.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"row": 1, | ||
"values": ["West_station", "BV", "11:22:40", "", "", "5%"] | ||
}, | ||
{ | ||
"row": 2, | ||
"values": ["Mid_West_station", "BV", "", "", "", ""] | ||
}, | ||
{ | ||
"row": 3, | ||
"values": ["Mid_East_station", "BV", "18:23:19", "18:25:23", "124", ""] | ||
}, | ||
{ | ||
"row": 4, | ||
"values": ["North_East_station", "BV", "", "", "0", ""] | ||
} | ||
] |
18 changes: 18 additions & 0 deletions
18
front/tests/assets/operationStudies/timesAndStops/timesAndStopsInput.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"row": 1, | ||
"values": ["West_station", "BV", "11:22:40", "", "", "5%"] | ||
}, | ||
{ | ||
"row": 2, | ||
"values": ["Mid_West_station", "BV", "14:22:40", "14:27:40", "300", "1min/100km"] | ||
}, | ||
{ | ||
"row": 3, | ||
"values": ["Mid_East_station", "BV", "18:23:19", "18:25:23", "124", ""] | ||
}, | ||
{ | ||
"row": 4, | ||
"values": ["North_East_station", "BV", "", "", "0", ""] | ||
} | ||
] |
66 changes: 66 additions & 0 deletions
66
front/tests/assets/operationStudies/timesAndStops/timesAndStopsOutput.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
[ | ||
{ | ||
"stationName": "West_station", | ||
"stationCh": "BV", | ||
"requestedArrival": "11:22:40", | ||
"requestedDeparture": "", | ||
"stopTime": "", | ||
"signalReceptionClosed": false, | ||
"margin": { | ||
"theoretical": "5 %", | ||
"theoreticalS": "17 s", | ||
"actual": "10465 s", | ||
"difference": "10449 s" | ||
}, | ||
"calculatedArrival": "11:22:40", | ||
"calculatedDeparture": "" | ||
}, | ||
{ | ||
"stationName": "Mid_West_station", | ||
"stationCh": "BV", | ||
"requestedArrival": "14:22:40", | ||
"requestedDeparture": "14:27:40", | ||
"stopTime": "300", | ||
"signalReceptionClosed": true, | ||
"margin": { | ||
"theoretical": "1 min/100km", | ||
"theoreticalS": "9 s", | ||
"actual": "13765 s", | ||
"difference": "13756 s" | ||
}, | ||
"calculatedArrival": "14:22:39", | ||
"calculatedDeparture": "14:27:39" | ||
}, | ||
{ | ||
"stationName": "Mid_East_station", | ||
"stationCh": "BV", | ||
"requestedArrival": "18:23:19", | ||
"requestedDeparture": "18:25:23", | ||
"stopTime": "124", | ||
"signalReceptionClosed": false, | ||
"margin": { | ||
"theoretical": "", | ||
"theoreticalS": "12 s", | ||
"actual": "12 s", | ||
"difference": "0 s" | ||
}, | ||
"calculatedArrival": "18:23:18", | ||
"calculatedDeparture": "18:25:22" | ||
}, | ||
{ | ||
"stationName": "North_East_station", | ||
"stationCh": "BV", | ||
"requestedArrival": "", | ||
"requestedDeparture": "", | ||
"stopTime": "0", | ||
"signalReceptionClosed": false, | ||
"margin": { | ||
"theoretical": "", | ||
"theoreticalS": "", | ||
"actual": "", | ||
"difference": "" | ||
}, | ||
"calculatedArrival": "18:32:53", | ||
"calculatedDeparture": "" | ||
} | ||
] |
Oops, something went wrong.