Skip to content

Commit

Permalink
front: add fourth stdcm e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: maymanaf <[email protected]>
  • Loading branch information
Maymanaf committed Nov 7, 2024
1 parent 8107161 commit 8211a9a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 34 deletions.
6 changes: 3 additions & 3 deletions front/tests/005-operational-studies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
Study,
} from 'common/api/osrdEditoastApi';

import { electricRollingStockName, infrastructureName } from './assets/project-const';
import { electricRollingStockName } from './assets/project-const';
import RoutePage from './pages/op-route-page-model';
import OperationalStudiesPage from './pages/operational-studies-page-model';
import RollingStockSelectorPage from './pages/rollingstock-selector-page-model';
Expand All @@ -26,9 +26,9 @@ test.describe('Verify simulation configuration in operational studies', () => {
let infra: Infra;
let rollingStock: LightRollingStock;

test.beforeAll('Fetch rolling stock ', async () => {
test.beforeAll('Fetch rolling stock and infrastructure ', async () => {
rollingStock = await getRollingStock(electricRollingStockName);
infra = await getInfra(infrastructureName);
infra = await getInfra();
});

test.beforeEach('Set up the project, study, and scenario', async () => {
Expand Down
29 changes: 25 additions & 4 deletions front/tests/006-stdcm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Infra } from 'common/api/osrdEditoastApi';

import { infrastructureName } from './assets/project-const';
import HomePage from './pages/home-page-model';
import STDCMPage from './pages/stdcm-page-model';
import test from './test-logger';
Expand All @@ -14,7 +13,7 @@ test.describe('Verify train schedule elements and filters', () => {
let OSRDLanguage: string;

test.beforeAll('Fetch infrastructure', async () => {
infra = await getInfra(infrastructureName);
infra = await getInfra();
});

test.beforeEach('Navigate to the STDCM page', async ({ page }) => {
Expand All @@ -23,6 +22,8 @@ test.describe('Verify train schedule elements and filters', () => {
await homePage.goToHomePage();
OSRDLanguage = await homePage.getOSRDLanguage();
await page.goto('/stdcm');
await page.waitForLoadState('load', { timeout: 30 * 1000 });

// Wait for infra to be in 'CACHED' state before proceeding
await waitForInfraStateToBeCached(infra.id);
});
Expand Down Expand Up @@ -54,7 +55,7 @@ test.describe('Verify train schedule elements and filters', () => {
}

// Launch simulation and verify output data matches expected results
await stdcmPage.launchSimulation(OSRDLanguage);
await stdcmPage.launchSimulation();
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmAllStops.json');
});

Expand All @@ -68,10 +69,30 @@ test.describe('Verify train schedule elements and filters', () => {
await stdcmPage.fillAndVerifyViaDetails(1, 'mid_west');

// Launch simulation and verify output data matches expected results
await stdcmPage.launchSimulation(OSRDLanguage);
await stdcmPage.launchSimulation();
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithoutAllVia.json');
await stdcmPage.clickOnAllViaButton();
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithAllVia.json');
await stdcmPage.retainSimulation();
});
/** *************** Test 4 **************** */
test('STDCM map and reset fields', async ({ page, browserName }) => {
// Populate STDCM page with origin, destination, and via details
const stdcmPage = new STDCMPage(page);
await stdcmPage.fillConsistDetails();
await stdcmPage.fillOriginDetailsLight();
await stdcmPage.fillDestinationDetailsLight();
await stdcmPage.fillAndVerifyViaDetails(1, 'mid_west');
// Verify map markers in Chromium
if (browserName === 'chromium') {
await stdcmPage.mapMarkerVisibility();
}
// Launch simulation
await stdcmPage.launchSimulation();
await stdcmPage.clickOnRetainSimulation();
// Reset and verify empty fields
await stdcmPage.clickOnStartNewQueryButton();
// TODO: Uncomment the check when the bug #9533 is fixed
// await stdcmPage.verifyAllFieldsEmpty();
});
});
9 changes: 2 additions & 7 deletions front/tests/008-train-schedule.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { Scenario, Project, Study, Infra } from 'common/api/osrdEditoastApi';

import {
infrastructureName,
stdcmProjectName,
stdcmScenarioName,
stdcmStudyName,
} from './assets/project-const';
import { stdcmProjectName, stdcmScenarioName, stdcmStudyName } from './assets/project-const';
import HomePage from './pages/home-page-model';
import OperationalStudiesTimetablePage from './pages/op-timetable-page-model';
import test from './test-logger';
Expand All @@ -32,7 +27,7 @@ test.describe('Verify train schedule elements and filters', () => {
project = await getProject(stdcmProjectName);
study = await getStudy(project.id, stdcmStudyName);
scenario = await getScenario(project.id, study.id, stdcmScenarioName);
infra = await getInfra(infrastructureName);
infra = await getInfra();
});

test.beforeEach('Navigate to scenario page before each test', async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions front/tests/011-op-times-and-stops-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from '@playwright/test';

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

import { dualModeRollingStockName, infrastructureName } from './assets/project-const';
import { dualModeRollingStockName } from './assets/project-const';
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';
Expand Down Expand Up @@ -64,7 +64,7 @@ test.describe('Times and Stops Tab Verification', () => {
type TranslationKeys = keyof typeof enTranslations;

test.beforeAll('Fetch infrastructure', async () => {
infra = await getInfra(infrastructureName);
infra = await getInfra();
});

test.beforeEach(
Expand Down
4 changes: 2 additions & 2 deletions front/tests/012-op-simulation-settings-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
Study,
} from 'common/api/osrdEditoastApi';

import { improbableRollingStockName, infrastructureName } from './assets/project-const';
import { improbableRollingStockName } from './assets/project-const';
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';
Expand Down Expand Up @@ -75,7 +75,7 @@ test.describe('Simulation Settings Tab Verification', () => {

test.beforeAll('Add electrical profile via API and fetch infrastructure', async () => {
electricalProfileSet = await setElectricalProfile();
infra = await getInfra(infrastructureName);
infra = await getInfra();
});

test.afterAll('Delete the electrical profile', async () => {
Expand Down
38 changes: 22 additions & 16 deletions front/tests/pages/stdcm-page-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ class STDCMPage {

readonly simulationList: Locator;

readonly cancelSimulationButton: Locator;

readonly simulationLoader: Locator;

readonly incrementButton: Locator;

readonly allViaButton: Locator;
Expand Down Expand Up @@ -179,8 +175,6 @@ class STDCMPage {
this.dynamicDestinationCi = this.destinationCard.locator('[id^="id"][id$="-ci"]');
this.simulationStatus = page.getByTestId('simulation-status');
this.simulationList = page.locator('.simulation-list .simulation-name');
this.cancelSimulationButton = page.getByTestId('cancel-simulation-button');
this.simulationLoader = page.locator('.stdcm-loader');
this.incrementButton = page.locator('.minute-button', { hasText: '+1mn' });
this.allViaButton = page.getByTestId('all-via-button');
this.retainSimulationButton = page.getByTestId('retain-simulation-button');
Expand Down Expand Up @@ -293,6 +287,8 @@ class STDCMPage {
// Fills fields with test values in the consist section
async fillConsistDetails() {
await this.tractionEngineField.fill(electricRollingStockName);
await this.tractionEngineField.press('ArrowDown');
await this.tractionEngineField.press('Enter');
await this.tonnageField.fill('400');
await this.lengthField.fill('300');
await this.codeCompoField.selectOption('HLP');
Expand All @@ -304,7 +300,8 @@ class STDCMPage {
await this.dynamicOriginCi.fill('North');
await this.verifyOriginNorthSuggestions();
await this.suggestionNWS.click();
await expect(this.dynamicOriginCi).toHaveValue('North_West_station');
const originCiValue = await this.dynamicOriginCi.getAttribute('value');
expect(originCiValue).toContain('North_West_station');
await expect(this.dynamicOriginCh).toHaveValue('BV');
await expect(this.originArrival).toHaveValue('preciseTime');
await expect(this.dateOriginArrival).toHaveValue('17/10/24');
Expand All @@ -323,7 +320,8 @@ class STDCMPage {
await this.dynamicDestinationCi.fill('South');
await this.verifyDestinationSouthSuggestions();
await this.suggestionSS.click();
await expect(this.dynamicDestinationCi).toHaveValue('South_station');
const destinationCiValue = await this.dynamicDestinationCi.getAttribute('value');
expect(destinationCiValue).toContain('South_station');
await expect(this.dynamicDestinationCh).toHaveValue('BV');
await expect(this.destinationArrival).toHaveValue('asSoonAsPossible');
await expect(this.warningBox).toContainText(translations.stdcmErrors.noScheduledPoint);
Expand Down Expand Up @@ -416,16 +414,14 @@ class STDCMPage {
}
}

// Launches the simulation, verifies the loading indicator, and checks if simulation-related elements are visible
async launchSimulation(selectedLanguage: string) {
const translations = selectedLanguage === 'English' ? enTranslations : frTranslations;
// Launches the simulation and checks if simulation-related elements are visible
async launchSimulation() {
await this.launchSimulationButton.click();
await expect(this.simulationLoader).toBeVisible();
const loaderText = await this.simulationLoader.textContent();
expect(loaderText).toContain(translations.simulation.averageRequestTime);
await expect(this.cancelSimulationButton).toBeVisible();
await expect(this.simulationList).toBeVisible();
await expect(this.mapResultContainer).toBeVisible();
// Check map result container visibility only for Chromium browser
if (this.page.context().browser()?.browserType().name() === 'chromium') {
await expect(this.mapResultContainer).toBeVisible();
}
}

async verifyTableData(tableDataPath: string): Promise<void> {
Expand Down Expand Up @@ -497,5 +493,15 @@ class STDCMPage {
throw new Error('Download failed');
}
}

async clickOnStartNewQueryButton() {
await this.startNewQueryButton.click();
}

async mapMarkerVisibility() {
await expect(this.originMarker).toBeVisible();
await expect(this.destinationMarker).toBeVisible();
await expect(this.viaMarker).toBeVisible();
}
}
export default STDCMPage;

0 comments on commit 8211a9a

Please sign in to comment.