Skip to content

Commit

Permalink
fixup! front: add e2e tests for add paced train feature
Browse files Browse the repository at this point in the history
  • Loading branch information
SharglutDev committed Feb 24, 2025
1 parent 7422d69 commit 49d4672
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 37 deletions.
93 changes: 84 additions & 9 deletions front/tests/005-operational-studies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import type { Infra, Project, Scenario, Study } from 'common/api/osrdEditoastApi';

import { expect } from '@playwright/test';

import type {
Infra,
LightRollingStock,
Project,
Scenario,
Study,
} from 'common/api/osrdEditoastApi';

import { NEW_PACED_TRAIN_SETTINGS } from './assets/operational-studies-const';
import { dualModeRollingStockName, electricRollingStockName } from './assets/project-const';
import test from './logging-fixture';
import RoutePage from './pages/op-route-page-model';
import OperationalStudiesPage from './pages/operational-studies-page-model';
import RollingStockSelectorPage from './pages/rollingstock-selector-page-model';
import { getTranslations, waitForInfraStateToBeCached } from './utils';
import { getInfra } from './utils/api-setup';
import { getInfra, getRollingStock } from './utils/api-setup';
import readJsonFile from './utils/file-utils';
import createScenario from './utils/scenario';
import { deleteScenario } from './utils/teardown-utils';
Expand All @@ -18,7 +28,7 @@ const frTranslations: ManageTrainScheduleTranslations = readJsonFile(
'public/locales/fr/operationalStudies/manageTrainSchedule.json'
);

test.describe('Verify simulation configuration in operational studies for paced trains', () => {
test.describe('Verify simulation configuration in operational studies for train schedules and paced trains', () => {
test.slow();

let rollingstockPage: RollingStockSelectorPage;
Expand All @@ -28,9 +38,11 @@ test.describe('Verify simulation configuration in operational studies for paced
let study: Study;
let scenario: Scenario;
let infra: Infra;
let rollingStock: LightRollingStock;
let translations: ManageTrainScheduleTranslations;

test.beforeAll('Fetch infrastructure and get translations', async () => {
rollingStock = await getRollingStock(electricRollingStockName);
infra = await getInfra();
translations = getTranslations({
en: enTranslations,
Expand Down Expand Up @@ -80,13 +92,10 @@ test.describe('Verify simulation configuration in operational studies for paced
await operationalStudiesPage.testPacedTrainMode(translations);

// Set the paced train inputs
await operationalStudiesPage.setTimeRangeDuration('150');
await operationalStudiesPage.setCadence('20');
await operationalStudiesPage.setTrainScheduleName('Paced train test');
await operationalStudiesPage.setTrainStartTime('08:35:40');
await operationalStudiesPage.fillPacedTrainSettings(NEW_PACED_TRAIN_SETTINGS);

// Select a rolling stock
await operationalStudiesPage.selectRollingStock(rollingstockPage);
await rollingstockPage.selectRollingStock(dualModeRollingStockName);

// Select an itinerary
await operationalStudiesPage.clickOnRouteTab();
Expand All @@ -101,4 +110,70 @@ test.describe('Verify simulation configuration in operational studies for paced

// TODO : update the test to verify the newly added paced train (for now nothing happens when clicking on the button)
});

// TODO Paced train : Remove this test in https://github.com/OpenRailAssociation/osrd/issues/10791
test('Pathfinding with rolling stock and composition code', async ({ page }) => {
// Page models

// Navigate to the scenario page for the given project and study
await page.goto(
`/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}`
);

// Wait for infra to be in 'CACHED' state before proceeding
await waitForInfraStateToBeCached(infra.id);

// Click the button to add a train schedule
await operationalStudiesPage.clickOnAddTrainButton();

// Set the train schedule name and number of trains
await operationalStudiesPage.setTrainScheduleName('TrainSchedule');
await operationalStudiesPage.setNumberOfTrains('7');

// Open the rolling stock modal

await rollingstockPage.openRollingstockModal();
await expect(rollingstockPage.rollingStockSelectorModal).toBeVisible();

// Test rolling stock search with normalization (spaces and capital letters)
await rollingstockPage.searchRollingstock(' electric_Rs_E2e ');

// Select the rolling stock card based on the test ID
const rollingstockCard = rollingstockPage.getRollingstockCardByTestID(
`rollingstock-${rollingStock.name}`
);

// Verify the rolling stock card is inactive initially
await expect(rollingstockCard).toHaveClass(/inactive/);

// Select the rolling stock and ensure it becomes active
await rollingstockCard.click();
await expect(rollingstockCard).not.toHaveClass(/inactive/);

// Confirm rolling stock selection by clicking the button on the card
await rollingstockCard.locator('button').click();

// Validate that the rolling stock's name and comfort class are displayed correctly
expect(await rollingstockPage.getRollingStockMiniCardInfo().first().textContent()).toMatch(
rollingStock.name
);
expect(await rollingstockPage.getRollingStockInfoComfort().textContent()).toMatch(
/ConfortSStandard/i
);

// Perform Pathfinding and verify the distance
await operationalStudiesPage.clickOnRouteTab();
await routePage.performPathfindingByTrigram('MWS', 'NES');
await operationalStudiesPage.checkPathfindingDistance('33.950 km');

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

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

// Confirm the number of trains added matches the expected number
await operationalStudiesPage.checkNumberOfTrains(7);
});
});
22 changes: 22 additions & 0 deletions front/tests/assets/operational-studies-const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { PacedTrainSettings } from '../utils/types';

export const DEFAULT_PACED_TRAIN_SETTINGS: Pick<
PacedTrainSettings,
'timeRangeDuration' | 'cadence'
> = {
timeRangeDuration: '120',
cadence: '60',
};

export const PACED_TRAIN_SETTINGS_TEST: Pick<PacedTrainSettings, 'timeRangeDuration' | 'cadence'> =
{
timeRangeDuration: '180',
cadence: '30',
};

export const NEW_PACED_TRAIN_SETTINGS: PacedTrainSettings = {
name: 'Paced train test',
startTime: '08:35:40',
timeRangeDuration: '150',
cadence: '20',
};
62 changes: 34 additions & 28 deletions front/tests/pages/operational-studies-page-model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { expect, type Locator, type Page } from '@playwright/test';

import CommonPage from './common-page-model';
import type RollingStockSelectorPage from './rollingstock-selector-page-model';
import { dualModeRollingStockName } from '../assets/project-const';
import {
DEFAULT_PACED_TRAIN_SETTINGS,
PACED_TRAIN_SETTINGS_TEST,
} from '../assets/operational-studies-const';
import readJsonFile from '../utils/file-utils';
import type { ManageTrainScheduleTranslations } from '../utils/types';
import type { ManageTrainScheduleTranslations, PacedTrainSettings } from '../utils/types';

const manageTrainScheduleTranslation: { trainAdded: string } = readJsonFile(
'public/locales/fr/operationalStudies/manageTrainSchedule.json'
Expand Down Expand Up @@ -162,28 +164,29 @@ class OperationalStudiesPage extends CommonPage {
await expect(this.pacedTrainSwitch).toBeVisible();
await expect(this.pacedTrainSwitch).not.toBeChecked();
await this.pacedTrainSwitch.click();
await expect(this.pacedTrainSwitch).toBeChecked();

await this.modalCloseButton.click();
}

async checkInputsAndButtons(
translations: ManageTrainScheduleTranslations,
scenarioCreationDate: string
) {
async checkInputsAndButtons(translations: ManageTrainScheduleTranslations, date: string) {
await expect(this.addTrainButton).toBeVisible();
await expect(this.addTrainButton).toHaveText(translations.addTrainSchedule);
await expect(this.definePacedTrainCheckboxLabel).toBeVisible();
await expect(this.definePacedTrainCheckboxLabel).toHaveText(
translations.pacedTrains.defineService
);
await expect(this.definePacedTrainCheckbox).not.toBeChecked();
await expect(this.returnSimulationResultButton).toBeVisible();
await expect(this.trainNameInput).toBeVisible();

await expect(this.startTimeField).toBeVisible();
const startTimeDate = new Date(await this.startTimeField.inputValue());
const scenarioCreationDateDate = new Date(scenarioCreationDate);
const scenarioCreationDate = new Date(date);
const isSameDate =
startTimeDate.getFullYear() === scenarioCreationDateDate.getFullYear() &&
startTimeDate.getMonth() === scenarioCreationDateDate.getMonth() &&
startTimeDate.getDate() === scenarioCreationDateDate.getDate();
startTimeDate.getFullYear() === scenarioCreationDate.getFullYear() &&
startTimeDate.getMonth() === scenarioCreationDate.getMonth() &&
startTimeDate.getDate() === scenarioCreationDate.getDate();
expect(isSameDate).toBe(true);

await expect(this.trainInitialSpeedInput).toBeVisible();
Expand All @@ -206,14 +209,16 @@ class OperationalStudiesPage extends CommonPage {
await this.definePacedTrainCheckboxLabel.click();
await expect(this.addTrainButton).toHaveText(translations.addPacedTrain);
await expect(this.pacedTrainTimeRangeDurationInput).toBeVisible();
await expect(this.pacedTrainTimeRangeDurationInput).toHaveValue('120');
await expect(this.pacedTrainTimeRangeDurationInput).toHaveValue(
DEFAULT_PACED_TRAIN_SETTINGS.timeRangeDuration
);
await expect(this.pacedTrainCadenceInput).toBeVisible();
await expect(this.pacedTrainCadenceInput).toHaveValue('60');
await expect(this.pacedTrainCadenceInput).toHaveValue(DEFAULT_PACED_TRAIN_SETTINGS.cadence);
}

async testPacedTrainMode(translations: ManageTrainScheduleTranslations) {
await this.setTimeRangeDuration('180');
await this.setCadence('30');
await this.setTimeRangeDuration(PACED_TRAIN_SETTINGS_TEST.timeRangeDuration);
await this.setCadence(PACED_TRAIN_SETTINGS_TEST.cadence);
await this.definePacedTrainCheckboxLabel.click();
await expect(this.addTrainButton).toHaveText(translations.addTrainSchedule);
await expect(this.pacedTrainTimeRangeDurationInput).not.toBeVisible();
Expand All @@ -222,22 +227,23 @@ class OperationalStudiesPage extends CommonPage {
await this.definePacedTrainCheckboxLabel.click();
await expect(this.addTrainButton).toHaveText(translations.addPacedTrain);
await expect(this.pacedTrainTimeRangeDurationInput).toBeVisible();
await expect(this.pacedTrainTimeRangeDurationInput).toHaveValue('180');
await expect(this.pacedTrainTimeRangeDurationInput).toHaveValue(
PACED_TRAIN_SETTINGS_TEST.timeRangeDuration
);
await expect(this.pacedTrainCadenceInput).toBeVisible();
await expect(this.pacedTrainCadenceInput).toHaveValue('30');
await expect(this.pacedTrainCadenceInput).toHaveValue(PACED_TRAIN_SETTINGS_TEST.cadence);
}

// eslint-disable-next-line class-methods-use-this
async selectRollingStock(rollingStockSelectorPage: RollingStockSelectorPage) {
await rollingStockSelectorPage.openRollingstockModal();
const rollingstockCard = rollingStockSelectorPage.getRollingstockCardByTestID(
`rollingstock-${dualModeRollingStockName}`
);
await rollingstockCard.click();
await rollingstockCard.locator('button').click();
expect(
await rollingStockSelectorPage.getRollingStockMiniCardInfo().first().textContent()
).toMatch(dualModeRollingStockName);
async fillPacedTrainSettings({
name,
startTime,
timeRangeDuration,
cadence,
}: PacedTrainSettings) {
await this.setTrainScheduleName(name);
await this.setTrainStartTime(startTime);
await this.setTimeRangeDuration(timeRangeDuration);
await this.setCadence(cadence);
}

async setTimeRangeDuration(timeRangeDuration: string) {
Expand Down
7 changes: 7 additions & 0 deletions front/tests/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,10 @@ export type FlatTranslations = Record<string, string>;
export type ManageTrainScheduleTranslations = FlatTranslations & {
pacedTrains: FlatTranslations;
};

export type PacedTrainSettings = {
name: string;
startTime: string;
timeRangeDuration: string;
cadence: string;
};

0 comments on commit 49d4672

Please sign in to comment.