Skip to content

Commit

Permalink
front: add rolling stock selectos e2e test for operational studies
Browse files Browse the repository at this point in the history
  • Loading branch information
Maymanaf committed Jul 8, 2024
1 parent 4cda861 commit 41947c4
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ const RollingStockCardButtons = ({
options.push({
value: 'HEATING',
label: (
<span className="rollingstock-footer-button-with-picto">
<span
data-testid="comfort-heating-button"
className="rollingstock-footer-button-with-picto"
>
{comfort2pictogram('HEATING')} {t('comfortTypes.HEATING')}
</span>
),
Expand All @@ -71,7 +74,7 @@ const RollingStockCardButtons = ({
options.push({
value: 'AC',
label: (
<span className="rollingstock-footer-button-with-picto">
<span data-testid="comfort-ac-button" className="rollingstock-footer-button-with-picto">
{comfort2pictogram('AC')} {t('comfortTypes.AC')}
</span>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export const RollingStockInfo = ({
{`${metadata.family} / ${metadata.type} / ${metadata.grouping}`}
</span>
)}
{showEnd && <span className="rollingstock-info-end">{rollingStock.name}</span>}
{showEnd && (
<span data-testid="selected-rolling-stock-info" className="rollingstock-info-end">
{rollingStock.name}
</span>
)}
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ const RollingStockSelector = ({
<span className="rollingstock-info-comfort text-uppercase small">
<span className="text-uppercase font-weight-bold">{t('comfort')}</span>
<span className="mx-2">{comfort2pictogram(rollingStockComfort)}</span>
{t(`comfortTypes.${rollingStockComfort}`)}
<span data-testid="selected-comfort-type-info">
{t(`comfortTypes.${rollingStockComfort}`)}
</span>
</span>
<RollingStockInfo
rollingStock={rollingStockSelected}
Expand Down
121 changes: 120 additions & 1 deletion front/tests/005-operational-studies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import fs from 'fs';
import path from 'path';

import { test, expect } from '@playwright/test';
import { v4 as uuidv4 } from 'uuid';

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

import scenarioData from './assets/operationStudies/scenario.json';
import { getProject, getStudy, getRollingStock, postApiRequest, getInfra } from './assets/utils';
import {
getProject,
getStudy,
getRollingStock,
postApiRequest,
getInfra,
addRollingStock,
findAndDeleteRollingStock,
} from './assets/utils';
import { PlaywrightHomePage } from './pages/home-page-model';
import PlaywrightOperationalStudiesPage from './pages/operationa-studies-page-model';
import RollingStockSelectorPage from './pages/rolling-stock-selector-page';
import PlaywrightScenarioPage from './pages/scenario-page-model';

Expand All @@ -15,11 +27,18 @@ let study: Study;
let scenario: Scenario;
let rollingStock: RollingStock;

const rollingstockPath = path.resolve(
__dirname,
'../tests/assets/rollingStock/thermal-electric_rolling_stock.json'
);
const rollingStockJson = JSON.parse(fs.readFileSync(rollingstockPath, 'utf8'));
const thermalElectricRollingStockName = 'thermal-electric_rolling_stock';
test.beforeAll(async () => {
smallInfra = (await getInfra()) as Infra;
project = await getProject();
study = await getStudy(project.id);
rollingStock = await getRollingStock();
await findAndDeleteRollingStock(thermalElectricRollingStockName);
});

test.beforeEach(async () => {
Expand All @@ -29,6 +48,7 @@ test.beforeEach(async () => {
study_id: study.id,
infra_id: smallInfra.id,
});
await findAndDeleteRollingStock(thermalElectricRollingStockName);
});

test.describe('Testing if all mandatory elements simulation configuration are loaded in operationnal studies app', () => {
Expand Down Expand Up @@ -102,4 +122,103 @@ test.describe('Testing if all mandatory elements simulation configuration are lo
await scenarioPage.returnSimulationResult();
await scenarioPage.checkNumberOfTrains(Number(trainCount));
});

test('should correctly select a rolling stock for operational study', async ({ page }) => {
const operationalStudiesPage = new PlaywrightOperationalStudiesPage(page);
const scenarioPage = new PlaywrightScenarioPage(page);
const rollingStockSelector = new RollingStockSelectorPage(page);

// Add a rolling stock via postAPI
await addRollingStock(thermalElectricRollingStockName, rollingStockJson);

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

// Verify that the infrastructure is correctly loaded
await scenarioPage.checkInfraLoaded();

// Click on add train button
await operationalStudiesPage.clickOnAddScenarioTrainBtn();

// Verify the presence of warnings in Rolling Stock and Route Tab
await operationalStudiesPage.getTabWarningPresence();

// Open Rolling Stock Selector and search for the added train
await operationalStudiesPage.openEmptyRollingStockSelector();
await rollingStockSelector.searchRollingstock(thermalElectricRollingStockName);
const rollingstockCard = rollingStockSelector.getRollingstockCardByTestID(
`rollingstock-${thermalElectricRollingStockName}`
);

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

// Verify that the rolling stock card is active after clicking on it
await rollingstockCard.click();
await expect(rollingstockCard).not.toHaveClass(/inactive/);

// Select the comfort AC
const comfortACRadioText = await rollingStockSelector.comfortACRadio.innerText();
await rollingStockSelector.comfortACRadio.click();

// Select the rolling stock
await rollingstockCard.locator('button').click();

// Verify that the correct comfort type is displayed
const selectedComfortACText = await rollingStockSelector.getSelectedComfortType.innerText();
expect(selectedComfortACText).toMatch(new RegExp(comfortACRadioText, 'i'));
});

test('should correctly modify a rolling stock for operational study', async ({ page }) => {
const operationalStudiesPage = new PlaywrightOperationalStudiesPage(page);
const scenarioPage = new PlaywrightScenarioPage(page);
const rollingStockSelector = new RollingStockSelectorPage(page);

// Add a rolling stock via postAPI
await addRollingStock(thermalElectricRollingStockName, rollingStockJson);

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

// Verify that the infrastructure is correctly loaded
await scenarioPage.checkInfraLoaded();

// Click on add train button
await operationalStudiesPage.clickOnAddScenarioTrainBtn();

// Open Rolling Stock Selector, search for the added train, and select it
await operationalStudiesPage.openEmptyRollingStockSelector();
await rollingStockSelector.searchRollingstock('rollingstock_1500_25000_test_e2e');
const fastRollingstockCard = rollingStockSelector.getRollingstockCardByTestID(
`rollingstock-${rollingStock.name}`
);
await fastRollingstockCard.click();
await fastRollingstockCard.locator('button').click();
expect(await rollingStockSelector.getSelectedRollingStockName.innerText()).toEqual(
'rollingstock_1500_25000_test_e2e'
);

// Reopen the Rolling Stock selector from the selected card
await operationalStudiesPage.openRollingStockSelector();

// Apply thermal and electrical filters
await rollingStockSelector.thermalRollingStockFilter();
await rollingStockSelector.electricRollingStockFilter();

// Select the thermal electric rolling stock
const thermalElectricRollingstockCard = rollingStockSelector.getRollingstockCardByTestID(
`rollingstock-${thermalElectricRollingStockName}`
);
await thermalElectricRollingstockCard.click();
await thermalElectricRollingstockCard.locator('button').click();

// Verify that the correct rolling stock name is displayed
expect(await rollingStockSelector.getSelectedRollingStockName.innerText()).toEqual(
thermalElectricRollingStockName
);
});
});
4 changes: 2 additions & 2 deletions front/tests/009-rollingstock-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ test.describe('Rollingstock editor page', () => {
await rollingStockSelectorPage.electricRollingStockFilter();

// Perform a filtering action for thermal rolling stock
await rollingStockSelectorPage.themalRollingStockFilter();
await rollingStockSelectorPage.thermalRollingStockFilter();

// Verify that filtering reduces the count and all the RS have thermal icons
expect(await rollingStockSelectorPage.getThermalRollingStockIcons.count()).toEqual(
Expand All @@ -239,7 +239,7 @@ test.describe('Rollingstock editor page', () => {

// Clear filters
await rollingStockSelectorPage.electricRollingStockFilter();
await rollingStockSelectorPage.themalRollingStockFilter();
await rollingStockSelectorPage.thermalRollingStockFilter();

// Verify that the count of rolling stock is back to the initial number
expect(await rollingStockSelectorPage.getRollingStockList.count()).toEqual(
Expand Down
42 changes: 42 additions & 0 deletions front/tests/pages/operationa-studies-page-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect, type Locator, type Page } from '@playwright/test';

export default class PlaywrightOperationalStudiesPage {
readonly getAddScenarioTrainBtn: Locator;

readonly getRollingStockTab: Locator;

readonly getRollingStockSelector: Locator;

readonly getEmptyRollingStockSelector: Locator;

readonly getRouteTab: Locator;

constructor(readonly page: Page) {
this.page = page;
this.getAddScenarioTrainBtn = page.getByTestId('scenarios-add-train-schedule-button');
this.getRollingStockTab = page.getByTestId('tab-rollingstock');
this.getRouteTab = page.getByTestId('tab-pathfinding');
this.getEmptyRollingStockSelector = page.getByTestId('rollingstock-selector-empty');
this.getRollingStockSelector = page.getByTestId('rollingstock-selector');
}

async clickOnAddScenarioTrainBtn() {
await this.getAddScenarioTrainBtn.click();
}

// Verify that the tabs RS and Route have warnings
async getTabWarningPresence() {
await expect(this.getRollingStockTab).toHaveClass(/warning/);
await expect(this.getRouteTab).toHaveClass(/warning/);
}

// Click on Choose a rolling stock
async openEmptyRollingStockSelector() {
await this.getEmptyRollingStockSelector.click();
}

// Click on the selected rolling stock
async openRollingStockSelector() {
await this.getRollingStockSelector.click();
}
}
14 changes: 13 additions & 1 deletion front/tests/pages/rolling-stock-selector-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export default class RollingStockSelectorPage extends BasePage {

readonly getNoRollingStockResult: Locator;

readonly comfortHeatingRadio: Locator;

readonly comfortACRadio: Locator;

readonly getSelectedComfortType: Locator;

readonly getSelectedRollingStockName: Locator;

constructor(page: Page) {
super(page);
this.rollingStockSelectorButton = page.getByTestId('rollingstock-selector');
Expand All @@ -66,6 +74,10 @@ export default class RollingStockSelectorPage extends BasePage {
this.getThermalRollingStockFirstIcon = this.getThermalRollingStockIcons.first();
this.getRollingStockList = page.locator('.rollingstock-editor-list .rollingstock-title');
this.getNoRollingStockResult = page.locator('.rollingstock-empty');
this.comfortHeatingRadio = page.getByTestId('comfort-heating-button');
this.comfortACRadio = page.getByTestId('comfort-ac-button');
this.getSelectedComfortType = page.getByTestId('selected-comfort-type-info');
this.getSelectedRollingStockName = page.getByTestId('selected-rolling-stock-info');
}

async openRollingstockModal() {
Expand Down Expand Up @@ -105,7 +117,7 @@ export default class RollingStockSelectorPage extends BasePage {
}

// Select Combustion engine RS filter
async themalRollingStockFilter() {
async thermalRollingStockFilter() {
await this.getThermalRollingStockFilter.click();
}

Expand Down

0 comments on commit 41947c4

Please sign in to comment.