Skip to content

Commit

Permalink
front: update e2e tests to handle paced trains
Browse files Browse the repository at this point in the history
Signed-off-by: SharglutDev <[email protected]>
  • Loading branch information
SharglutDev committed Mar 7, 2025
1 parent 5b966b2 commit 42c86a8
Show file tree
Hide file tree
Showing 12 changed files with 347 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const OccurrenceItem = ({ occurrence, isSelected, nextOccurrence }: OccurrenceIt

return (
<div
data-testid="occurrence-item"
className={cx('occurrence-item', {
'after-midnight': isAfterMidnight,
'next-after-midnight': isNextAfterMidnight,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,33 @@ const PacedTrainItem = ({
<Manchette iconColor="var(--white100)" />
</div>
)}
<div className="occurrences-count">{occurrencesCount}</div>
<div data-testid="occurrences-count" className="occurrences-count">
{occurrencesCount}
</div>
{isOccurrencesListOpen ? (
<ChevronDown className="toggle-icon center-icon" />
<ChevronDown
data-testid="hide-occurrences-button"
className="toggle-icon center-icon"
/>
) : (
<ChevronRight className="toggle-icon center-icon" />
<ChevronRight
data-testid="show-occurrences-button"
className="toggle-icon center-icon"
/>
)}
<div className="train-info">
<span className="train-name">{pacedTrain.name}</span>
<span data-testid="paced-train-name" className="train-name">
{pacedTrain.name}
</span>
</div>
</div>

{!pacedTrain.invalidReason ? (
<div className="paced-train-right-zone">
{pacedTrain.isValid && (
<div>&mdash;&nbsp;{`${ms2min(pacedTrain.paced.step.ms)}min`}</div>
<div data-testid="paced-train-cadence">
&mdash;&nbsp;{`${ms2min(pacedTrain.paced.step.ms)}min`}
</div>
)}
<div
className={cx('status-icon', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const TimetableItemActions = ({
aria-label={t('timetable.choosePath')}
title={t('timetable.choosePath')}
onClick={selectPathProjection}
data-testid="project-item"
>
<GiPathDistance />
</button>
Expand All @@ -33,6 +34,7 @@ const TimetableItemActions = ({
aria-label={t('timetable.duplicate')}
title={t('timetable.duplicate')}
onClick={duplicateTimetableItem}
data-testid="duplicate-item"
>
<Duplicate />
</button>
Expand All @@ -41,7 +43,7 @@ const TimetableItemActions = ({
aria-label={t('timetable.update')}
title={t('timetable.update')}
onClick={editTimetableItem}
data-testid="edit-train"
data-testid="edit-item"
>
<Pencil />
</button>
Expand All @@ -50,6 +52,7 @@ const TimetableItemActions = ({
aria-label={t('timetable.delete')}
title={t('timetable.delete')}
onClick={deleteTimetableItem}
data-testid="delete-item"
>
<Trash />
</button>
Expand Down
17 changes: 11 additions & 6 deletions front/tests/005-operational-studies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ test.describe('Verify simulation configuration in operational studies for train
await operationalStudiesPage.checkPathfindingDistance('33.950 km');

// TODO : update this part when paced train endpoints are delivered to find a fine configuration for it
// Change some time and stops
// Change some time and stops ?

// Adding Train Schedule
await operationalStudiesPage.addTrainSchedule();
// Add paced train
await operationalStudiesPage.addTimetableItem();

// Verify the paced train has been added and return to the simulation results and timetable
await operationalStudiesPage.checkTimetableItemHasBeenAdded(translations.pacedTrains.added);
await operationalStudiesPage.returnSimulationResult();

// TODO : update the test to verify the newly added paced train (for now nothing happens when clicking on the button)
// Confirm that the number of paced trains added matches the expected number
await operationalStudiesPage.checkNumberOfTrains(1); // Only one paced train can be added at a time
});

// TODO Paced train : Remove this test in https://github.com/OpenRailAssociation/osrd/issues/10791
Expand Down Expand Up @@ -171,10 +176,10 @@ test.describe('Verify simulation configuration in operational studies for train
await operationalStudiesPage.checkPathfindingDistance('33.950 km');

// Adding Train Schedule
await operationalStudiesPage.addTrainSchedule();
await operationalStudiesPage.addTimetableItem();

// Verify the train has been added and the simulation results
await operationalStudiesPage.checkTrainHasBeenAdded();
await operationalStudiesPage.checkTimetableItemHasBeenAdded(translations.trainAdded);
await operationalStudiesPage.returnSimulationResult();

// Confirm the number of trains added matches the expected number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Scenario, Project, Study, Infra } from 'common/api/osrdEditoastApi';
import type { Scenario, Project, Study, Infra, PacedTrainBase } from 'common/api/osrdEditoastApi';

import {
trainScheduleProjectName,
Expand Down Expand Up @@ -242,4 +242,19 @@ test.describe('Verify train schedule elements and filters', () => {
);
await scenarioTimetableSection.verifyTrainCount(TOTAL_ITEMS);
});

/** *************** Test 4 **************** */
test('Loading timetable items and verifying paced trains display', async () => {
await operationalStudiesPage.checkPacedTrainSwitch();

// Paced train data used in global setup
const pacedTrainsData: PacedTrainBase[] = readJsonFile(
'./tests/assets/paced-train/paced_trains.json'
);

// Verify paced train item
for (let i = 0; i < pacedTrainsData.length; i += 1) {
await scenarioTimetableSection.verifyPacedTrainItemDetails(pacedTrainsData[i], i);
}
});
});
2 changes: 1 addition & 1 deletion front/tests/011-op-times-and-stops-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ test.describe('Times and Stops Tab Verification', () => {
}

// Add train schedule, verify results and output table data
await operationalStudiesPage.addTrainSchedule();
await operationalStudiesPage.addTimetableItem();
await operationalStudiesPage.returnSimulationResult();
await timeAndStopSimulationOutputs.verifyTimesStopsDataSheetVisibility();

Expand Down
8 changes: 4 additions & 4 deletions front/tests/012-op-simulation-settings-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ test.describe('Simulation Settings Tab Verification', () => {
await simulationSettingsTab.checkElectricalProfile();
await simulationSettingsTab.checkMarecoMargin();
// Add the train schedule and verify output results
await operationalStudiesPage.addTrainSchedule();
await operationalStudiesPage.addTimetableItem();
await operationalStudiesPage.returnSimulationResult();
await scenarioTimetableSection.getTrainArrivalTime('11:53');
await scenarioTimetableSection.clickOnScenarioCollapseButton();
Expand Down Expand Up @@ -219,7 +219,7 @@ test.describe('Simulation Settings Tab Verification', () => {
await simulationSettingsTab.checkMarecoMargin();
await simulationSettingsTab.selectCodeCompoOption('HLP');
// Add the train schedule and verify output results
await operationalStudiesPage.addTrainSchedule();
await operationalStudiesPage.addTimetableItem();
await operationalStudiesPage.returnSimulationResult();
await scenarioTimetableSection.getTrainArrivalTime('12:03');
await scenarioTimetableSection.clickOnScenarioCollapseButton();
Expand Down Expand Up @@ -274,7 +274,7 @@ test.describe('Simulation Settings Tab Verification', () => {
await simulationSettingsTab.deactivateElectricalProfile();
await simulationSettingsTab.activateLinearMargin();
// Add the train schedule and verify output results
await operationalStudiesPage.addTrainSchedule();
await operationalStudiesPage.addTimetableItem();
await operationalStudiesPage.returnSimulationResult();
await scenarioTimetableSection.getTrainArrivalTime('11:55');
await scenarioTimetableSection.clickOnScenarioCollapseButton();
Expand Down Expand Up @@ -331,7 +331,7 @@ test.describe('Simulation Settings Tab Verification', () => {
await simulationSettingsTab.activateLinearMargin();
await simulationSettingsTab.selectCodeCompoOption('HLP');
// Add the train schedule and verify output results
await operationalStudiesPage.addTrainSchedule();
await operationalStudiesPage.addTimetableItem();
await operationalStudiesPage.returnSimulationResult();
await scenarioTimetableSection.getTrainArrivalTime('12:06');
await scenarioTimetableSection.clickOnScenarioCollapseButton();
Expand Down
119 changes: 119 additions & 0 deletions front/tests/assets/paced-train/paced_trains.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
[
{
"train_name": "8608",
"labels": ["Paced-Train-Tag-1", "SS-NS", "Valid"],
"rolling_stock_name": "SLOW_RS_E2E",
"start_time": "2024-10-17T03:00:00Z",
"path": [
{ "id": "id227", "deleted": false, "uic": 6, "secondary_code": "BV" },
{ "id": "id228", "deleted": false, "uic": 5, "secondary_code": "BV" }
],
"schedule": [
{
"at": "id228",
"arrival": null,
"stop_for": "P0D",
"reception_signal": "OPEN",
"locked": false
}
],
"margins": { "boundaries": [], "values": ["0%"] },
"initial_speed": 0,
"comfort": "STANDARD",
"constraint_distribution": "MARECO",
"speed_limit_tag": null,
"power_restrictions": [],
"options": { "use_electrical_profiles": true },
"paced": { "duration": "PT2H", "step": "PT1H" }
},
{
"train_name": "Paced Train 2",
"labels": ["Paced-Train-Tag-2", "SS-NS", "Valid"],
"rolling_stock_name": "SLOW_RS_E2E",
"start_time": "2024-10-17T04:00:00Z",
"path": [
{ "id": "id227", "deleted": false, "uic": 6, "secondary_code": "BV" },
{ "id": "id228", "deleted": false, "uic": 5, "secondary_code": "BV" }
],
"schedule": [
{
"at": "id228",
"arrival": null,
"stop_for": "P0D",
"reception_signal": "OPEN",
"locked": false
}
],
"margins": { "boundaries": [], "values": ["0%"] },
"initial_speed": 0,
"comfort": "STANDARD",
"constraint_distribution": "MARECO",
"speed_limit_tag": null,
"power_restrictions": [],
"options": { "use_electrical_profiles": true },
"paced": { "duration": "PT2H", "step": "PT30M" }
},
{
"train_name": "PacedTrain3",
"labels": ["Paced-Train-Tag-2", "MWS-NES", "Not-honored"],
"rolling_stock_name": "DUAL-MODE_RS_E2E",
"start_time": "2024-10-17T05:00:00Z",
"path": [
{ "id": "id744", "deleted": false, "uic": 3, "secondary_code": "BV" },
{ "id": "id765", "deleted": false, "uic": 4, "secondary_code": "BV" },
{ "id": "id745", "deleted": false, "uic": 7, "secondary_code": "BV" }
],
"schedule": [
{
"at": "id765",
"arrival": "PT123S",
"stop_for": "PT120S",
"reception_signal": "SHORT_SLIP_STOP",
"locked": false
},
{
"at": "id745",
"arrival": null,
"stop_for": "P0D",
"reception_signal": "OPEN",
"locked": false
}
],
"margins": { "boundaries": [], "values": ["0%"] },
"initial_speed": 0,
"comfort": "STANDARD",
"constraint_distribution": "MARECO",
"speed_limit_tag": "HLP",
"power_restrictions": [],
"options": { "use_electrical_profiles": false },
"paced": { "duration": "PT2H", "step": "PT25M" }
},
{
"train_name": "PacedTrain4",
"labels": ["Invalid"],
"rolling_stock_name": "",
"start_time": "2024-10-17T09:45:43Z",
"path": [
{ "id": "id3807", "deleted": false, "track": "TA6", "offset": 8058000 },
{ "id": "id3822", "deleted": false, "track": "TD0", "offset": 10809000 },
{ "id": "id3855", "deleted": false, "track": "TG2", "offset": 1686000 }
],
"schedule": [
{
"at": "id3855",
"arrival": null,
"stop_for": "P0D",
"reception_signal": "OPEN",
"locked": false
}
],
"margins": { "boundaries": [], "values": ["0%"] },
"initial_speed": 0,
"comfort": "STANDARD",
"constraint_distribution": "MARECO",
"speed_limit_tag": "MA100",
"power_restrictions": [],
"options": { "use_electrical_profiles": true },
"paced": { "duration": "PT2H", "step": "PT1H" }
}
]
13 changes: 3 additions & 10 deletions front/tests/pages/operational-studies/operational-studies-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@ import {
DEFAULT_PACED_TRAIN_SETTINGS,
PACED_TRAIN_SETTINGS_TEST,
} from '../../assets/constants/operational-studies-const';
import readJsonFile from '../../utils/file-utils';
import type { ManageTrainScheduleTranslations, PacedTrainSettings } from '../../utils/types';
import CommonPage from '../common-page';

const manageTrainScheduleTranslation: { trainAdded: string } = readJsonFile(
'public/locales/fr/operationalStudies/manageTrainSchedule.json'
);

const trainAddedTranslation = manageTrainScheduleTranslation.trainAdded;

class OperationalStudiesPage extends CommonPage {
private readonly addScenarioTrainButton: Locator;

Expand Down Expand Up @@ -135,8 +128,8 @@ class OperationalStudiesPage extends CommonPage {
await expect(this.startTimeField).toHaveValue(startTime);
}

async checkTrainHasBeenAdded() {
await this.checkLastToastTitle(trainAddedTranslation);
async checkTimetableItemHasBeenAdded(translation: string) {
await this.checkLastToastTitle(translation);
}

async returnSimulationResult() {
Expand Down Expand Up @@ -256,7 +249,7 @@ class OperationalStudiesPage extends CommonPage {
await expect(this.pacedTrainCadenceInput).toHaveValue(cadence);
}

async addTrainSchedule() {
async addTimetableItem() {
await this.addTrainButton.click();
await this.closeToastNotification();
}
Expand Down
Loading

0 comments on commit 42c86a8

Please sign in to comment.