Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: add e2e stdcm tests #9599

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions front/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export default defineConfig({
trace: 'on-first-retry',
video: 'on-first-retry',

/* Set locale and timezone */
locale: 'fr',
timezoneId: 'Europe/Paris',
},
reporter: process.env.CI ? 'github' : [['line'], ['html']],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ const StdcmConfig = ({
})}
>
{showBtnToLaunchSimulation && (
<Button label={t('simulation.getSimulation')} onClick={startSimulation} />
<Button
data-testid="launch-simulation-button"
label={t('simulation.getSimulation')}
onClick={startSimulation}
/>
)}
{formErrors && (
<StdcmWarningBox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const StdcmDestination = ({ disabled = false }: StdcmConfigCardProps) => {

return (
<StdcmCard
data-testid="destination-card"
name={t('trainPath.destination')}
title={<img src={DestinationIcon} alt="destination" className="stdcm-destination-icon" />}
disabled={disabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ const StdcmVias = ({ disabled = false }: StdcmConfigCardProps) => {
<img src={IntermediatePointIcon} alt="intermediate-point" />
<span className="icon-index">{pathStepIndex}</span>
</div>
<button type="button" onClick={() => deleteViaOnClick(pathStep.id)}>
<button
data-testid="delete-via-button"
type="button"
onClick={() => deleteViaOnClick(pathStep.id)}
>
{t('translation:common.delete')}
</button>
</div>
Expand Down
1 change: 1 addition & 0 deletions front/src/applications/stdcm/components/StdcmHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const StdcmHeader = ({ isDebugMode, onDebugModeToggle }: StdcmHeaderProps) => {
{isSuperUser && (
<div className="stdcm-header_debug">
<button
data-testid="stdcm-debug-button"
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
type="button"
aria-label="stdcm-debug"
className={cx({ 'debug-on': isDebugMode, 'debug-off': !isDebugMode })}
Expand Down
1 change: 1 addition & 0 deletions front/src/applications/stdcm/components/StdcmLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const StdcmLoader = forwardRef(
</div>
<div className="stdcm-loader__cancel-btn">
<Button
data-testid="cancel-simulation-button"
variant="Cancel"
label={t('simulation.stopCalculation')}
size="small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,24 @@ const StcdmResults = ({
}
fileName={`STDCM-${simulationReportSheetNumber}.pdf`}
>
<Button label={t('downloadSimulationSheet')} onClick={() => {}} />
<Button
data-testid="download-simulation-button"
label={t('downloadSimulationSheet')}
onClick={() => {}}
/>
</PDFDownloadLink>
</div>
<div className="gesico-text">{t('gesicoRequest')}</div>
</div>
)}
{retainedSimulationIndex > -1 && (
<div className="start-new-query">
<Button variant="Normal" label={t('startNewQuery')} onClick={onStartNewQuery} />
<Button
data-testid="start-new-query-button"
variant="Normal"
label={t('startNewQuery')}
onClick={onStartNewQuery}
/>
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const StcdmResultsTable = ({
<div className={cx('results-buttons', { 'simulation-retained': isSimulationRetained })}>
<div className="button-display-all-PR">
<Button
data-testid="all-vias-button"
variant="Normal"
label={
showAllOP
Expand All @@ -134,6 +135,7 @@ const StcdmResultsTable = ({
<div className="button-get-simulation">
{!isSimulationRetained ? (
<Button
data-testid="retain-simulation-button"
label={t('stdcm:simulation.results.retainThisSimulation')}
onClick={onRetainSimulation}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const StdcmStatusBanner = ({ isFailed }: StdcmStatusBannerProps) => {
return (
<div className="simulation-status-banner">
<div className="banner-content">
<span className={cx('status', { failed: isFailed })}>
<span data-testid="simulation-status" className={cx('status', { failed: isFailed })}>
{isFailed ? t('failed') : t('completed')}
</span>
{isFailed && <p className="error-message">{t('errorMessage')}</p>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const StdcmWarningBox = ({
}: StdcmWarningBoxProps) => {
const { t } = useTranslation('stdcm');
return (
<div className="warning-box">
<div data-testid="warning-box" className="warning-box">
<span>
<Alert variant="fill" size="lg" />
</span>
Expand Down
5 changes: 5 additions & 0 deletions front/src/assets/rollingStock/freightRollingStocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ const FREIGHT_ROLLING_STOCKS = [
'Y8000AG',
'Y8000AP',
'Y9000US',
'electric_rolling_stock_test_e2e',
'dual-mode_rolling_stock_test_e2e',
'slow_rolling_stock_test_e2e',
'fast_rolling_stock_test_e2e',
'improbable_rolling_stock_test_e2e',
Yohh marked this conversation as resolved.
Show resolved Hide resolved
];

export default FREIGHT_ROLLING_STOCKS;
2 changes: 1 addition & 1 deletion front/tests/004-scenario-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from '@playwright/test';
import type { ElectricalProfileSet, Project, Scenario, Study } from 'common/api/osrdEditoastApi';

import scenarioData from './assets/operationStudies/scenario.json';
import { infrastructureName } from './assets/project_const';
import { infrastructureName } from './assets/project-const';
import ScenarioPage from './pages/scenario-page-model';
import test from './test-logger';
import { generateUniqueName } from './utils';
Expand Down
24 changes: 17 additions & 7 deletions front/tests/005-operational-studies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import { expect } from '@playwright/test';

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

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

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';
import test from './test-logger';
import { getRollingStock } from './utils/api-setup';
import { waitForInfraStateToBeCached } from './utils';
import { getInfra, getRollingStock } from './utils/api-setup';
import createScenario from './utils/scenario';
import { deleteScenario } from './utils/teardown-utils';

test.describe('Verify simulation configuration in operational studies', () => {
test.slow();
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
let project: Project;
let study: Study;
let scenario: Scenario;
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();
});

test.beforeEach('Set up the project, study, and scenario', async () => {
Expand All @@ -43,8 +53,8 @@ test.describe('Verify simulation configuration in operational studies', () => {
`/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}`
);

// Ensure infrastructure is loaded
await operationalStudiesPage.checkInfraLoaded();
// Wait for infra to be in 'CACHED' state before proceeding
await waitForInfraStateToBeCached(infra.id);
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved

// Click the button to add a train schedule
await operationalStudiesPage.clickOnAddTrainButton();
Expand Down
95 changes: 95 additions & 0 deletions front/tests/006-stdcm.spec.ts
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { Infra } from 'common/api/osrdEditoastApi';

import HomePage from './pages/home-page-model';
import STDCMPage from './pages/stdcm-page-model';
import test from './test-logger';
import { waitForInfraStateToBeCached } from './utils';
import { getInfra } from './utils/api-setup';

test.use({
launchOptions: {
slowMo: 500, // Give the interface time to update between actions
},
});
test.describe('Verify train schedule elements and filters', () => {
test.slow(); // Mark test as slow due to multiple steps

let infra: Infra;
let OSRDLanguage: string;

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

test.beforeEach('Navigate to the STDCM page', async ({ page }) => {
// Retrieve OSRD language and navigate to STDCM page
const homePage = new HomePage(page);
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);
});

/** *************** Test 1 **************** */
test('Verify empty STDCM page', async ({ page }) => {
// Verify visibility of STDCM elements and handle empty via fields
const stdcmPage = new STDCMPage(page);
await stdcmPage.verifyStdcmElementsVisibility();
await stdcmPage.verifyAllFieldsEmpty();
await stdcmPage.addAndDeleteEmptyVia();
});

/** *************** Test 2 **************** */
test('Launch STDCM simulation with all stops', async ({ page }) => {
// Populate STDCM page with origin, destination, and via details, then verify
const stdcmPage = new STDCMPage(page);
await stdcmPage.fillConsistDetails();
await stdcmPage.fillAndVerifyOriginDetails();
await stdcmPage.fillAndVerifyDestinationDetails(OSRDLanguage);
const viaDetails = [
{ viaNumber: 1, ciSearchValue: 'mid_west' },
{ viaNumber: 2, ciSearchValue: 'mid_east' },
{ viaNumber: 3, ciSearchValue: 'nS', language: OSRDLanguage },
];

for (const { viaNumber, ciSearchValue, language } of viaDetails) {
await stdcmPage.fillAndVerifyViaDetails(viaNumber, ciSearchValue, language);
}

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

/** *************** Test 3 **************** */
test('Verify STDCM stops and simulation sheet', 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 input map markers in Chromium
if (browserName === 'chromium') {
await stdcmPage.mapMarkerVisibility();
}
// Launch simulation and verify output data matches expected results
await stdcmPage.launchSimulation();
// Verify map results markers in Chromium
if (browserName === 'chromium') {
await stdcmPage.mapMarkerResultVisibility();
}
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithoutAllVia.json');
await stdcmPage.clickOnAllViaButton();
await stdcmPage.verifyTableData('./tests/assets/stdcm/stdcmWithAllVia.json');
await stdcmPage.retainSimulation();
await stdcmPage.downloadSimulation(browserName);
// Reset and verify empty fields
await stdcmPage.clickOnStartNewQueryButton();
// TODO: Uncomment the check when the bug #9533 is fixed
// await stdcmPage.verifyAllFieldsEmpty();
});
});
21 changes: 15 additions & 6 deletions front/tests/007-op-rollingstock-tab.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { expect } from '@playwright/test';

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

import { dualModeRollingStockName, electricRollingStockName } from './assets/project_const';
import type {
Infra,
LightRollingStock,
Project,
Scenario,
Study,
} from 'common/api/osrdEditoastApi';

import { dualModeRollingStockName, electricRollingStockName } from './assets/project-const';
import OperationalStudiesPage from './pages/operational-studies-page-model';
import RollingStockSelectorPage from './pages/rollingstock-selector-page-model';
import test from './test-logger';
import { getRollingStock } from './utils/api-setup';
import { waitForInfraStateToBeCached } from './utils';
import { getInfra, getRollingStock } from './utils/api-setup';
import createScenario from './utils/scenario';
import { deleteScenario } from './utils/teardown-utils';

Expand All @@ -15,23 +22,25 @@ test.describe('Rolling stock Tab Verification', () => {
let study: Study;
let scenario: Scenario;
let rollingStock: LightRollingStock;
let infra: Infra;

test.beforeAll('Set up a scenario before all tests', async () => {
rollingStock = await getRollingStock(electricRollingStockName);
({ project, study, scenario } = await createScenario());
infra = await getInfra();
});

test.afterAll('Delete the created scenario', async () => {
await deleteScenario(project.id, study.id, scenario.name);
});

test.beforeEach('Navigate to the scenario page', async ({ page }) => {
const operationalStudiesPage = new OperationalStudiesPage(page);
await page.goto(
`/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}`
);
// Ensure infrastructure is loaded before each test
await operationalStudiesPage.checkInfraLoaded();
// Wait for infra to be in 'CACHED' state before proceeding
await waitForInfraStateToBeCached(infra.id);
});

/** *************** Test 1 **************** */
Expand Down
Loading
Loading