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 stdcm test e2e #6644

Merged
merged 2 commits into from
Feb 16, 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
8 changes: 3 additions & 5 deletions front/tests/005-operational-studies.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';
import type { Project, RollingStock, Scenario, Study } from 'common/api/osrdEditoastApi';
import { PlaywrightHomePage } from './pages/home-page-model';
import PlaywrightRollingstockModalPage from './pages/rollingstock-modal-model';
import RollingStockSelectorPage from './pages/rolling-stock-selector-page';
import PlaywrightMap from './pages/map-model';
import PATH_VARIABLES from './assets/operationStudies/testVariablesPaths';
import PlaywrightScenarioPage from './pages/scenario-page-model';
Expand Down Expand Up @@ -38,12 +38,10 @@ test.describe('Testing if all mandatory elements simulation configuration are lo

// TODO: move this test in his own file
// ***************** Test Rolling Stock *****************
const playwrightRollingstockModalPage = new PlaywrightRollingstockModalPage(
playwrightHomePage.page
);
const playwrightRollingstockModalPage = new RollingStockSelectorPage(playwrightHomePage.page);
await expect(scenarioPage.getRollingStockSelector).toBeVisible();
await playwrightRollingstockModalPage.openRollingstockModal();
const rollingstockModal = playwrightRollingstockModalPage.getRollingstockModal;
const rollingstockModal = playwrightRollingstockModalPage.rollingStockSelectorModal;
await expect(rollingstockModal).toBeVisible();

await playwrightRollingstockModalPage.searchRollingstock('rollingstock_1500_25000_test_e2e');
Expand Down
109 changes: 31 additions & 78 deletions front/tests/006-stdcm-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,44 @@
import { test, expect } from '@playwright/test';
import { PlaywrightHomePage } from './pages/home-page-model';
import { PlaywrightSTDCMPage } from './pages/stdcm-page-model';
import StdcmPage from './pages/stdcm-page-model';
import manageTrainScheduleTranslation from '../public/locales/fr/operationalStudies/manageTrainSchedule.json';

// Describe the test suite for the STDCM page
test.describe('STDCM page', () => {
// Declare the necessary variables for the test suite
let playwrightHomePage: PlaywrightHomePage;
let playwrightSTDCMPage: PlaywrightSTDCMPage;
import project from './assets/operationStudies/project.json';
import study from './assets/operationStudies/study.json';
import scenario from './assets/operationStudies/scenario.json';

test('should be correctly displays the rolling stock list and select one', async ({ page }) => {
// Create an instance of the PlaywrightHomePage class
playwrightHomePage = new PlaywrightHomePage(page);
const projectName = project.name;
const studyName = study.name;
const scenarioName = scenario.name;
const rollingStockName = 'rollingstock_1500_25000_test_e2e';

// Create an instance of the PlaywrightSTDCMPage class
playwrightSTDCMPage = new PlaywrightSTDCMPage(page);
const rollingStockTranslation = manageTrainScheduleTranslation.rollingstock;

// Go to the home page of OSRD
await playwrightHomePage.goToHomePage();
test.describe('STDCM page (enabled)', () => {
test('should correctly display the rolling stock list and select one', async ({ page }) => {
const stdcmPage = new StdcmPage(page);

await playwrightHomePage.goToSTDCMPage();
await stdcmPage.navigateToPage();
await expect(stdcmPage.scenarioExplorerModal).not.toBeVisible();
await expect(stdcmPage.rollingStockSelectorModal).not.toBeVisible();

await playwrightSTDCMPage.getScenarioExploratorModalClose();
// Open the scenario explorer and select project, study and scenario
await stdcmPage.openScenarioExplorer();
await stdcmPage.selectMiniCard(projectName);
await stdcmPage.selectMiniCard(studyName);
await stdcmPage.selectMiniCard(scenarioName);

// Opens the scenario explorator and selects project, study and scenario
await playwrightSTDCMPage.openScenarioExplorator();
await playwrightSTDCMPage.getScenarioExploratorModalOpen();
await playwrightSTDCMPage.clickItemScenarioExploratorByName('_@Test integration project');
await playwrightSTDCMPage.clickItemScenarioExploratorByName('_@Test integration study');
await playwrightSTDCMPage.clickItemScenarioExploratorByName('_@Test integration scenario');
// Check no rollingstock is selected and "rollingstock" is in the missing information
await expect(stdcmPage.missingParams).toContainText(rollingStockTranslation);

const rollingStockTranslation =
playwrightSTDCMPage.getmanageTrainScheduleTranslations('rollingstock');
const rollingStockTranslationRegEx = new RegExp(rollingStockTranslation as string);
// Check that the three tests rolling stocks are present
playwrightSTDCMPage.getRollingstockByTestId(`rollingstock-_@Test Locomotives électriques`);
playwrightSTDCMPage.getRollingstockByTestId(`rollingstock-_@Test BB 22200`);
const rollingstockItem = playwrightSTDCMPage.getRollingstockByTestId(
`rollingstock-_@Test BB 7200GVLOCOMOTIVES`
);
// Check that no rollingstock is selected
await expect(
playwrightSTDCMPage.getRollingStockSelector.locator('.rollingstock-minicard')
).not.toBeVisible();
await expect(playwrightSTDCMPage.getMissingParam).toContainText(rollingStockTranslationRegEx);
// Select a rolling stock
await stdcmPage.openRollingstockModal();
await expect(stdcmPage.rollingStockSelectorModal).toBeVisible();
await stdcmPage.selectRollingStock(rollingStockName);

await playwrightSTDCMPage.getRollingstockModalClose();
await playwrightSTDCMPage.openRollingstockModal();
await playwrightSTDCMPage.getRollingstockModalOpen();
// Check that the rollingstock is selected and "rollingstock" is not in the missing information anymore
await expect(stdcmPage.rollingStockSelectorModal).not.toBeVisible();
await expect(stdcmPage.missingParams).not.toContainText(rollingStockTranslation);

await playwrightSTDCMPage.page.waitForSelector('.rollingstock-container');

const infoCardText = await playwrightSTDCMPage.getRollingStockListItem
.locator('.rollingstock-info')
.allTextContents();
expect(infoCardText).toContain(
'BB 7200GVLOCOMOTIVES / Locomotives électriques / Locomotives électriques courant continu_@Test BB 7200GVLOCOMOTIVES'
);
expect(infoCardText).toContain(
'BB 15000BB15000 USLOCOMOTIVES / Locomotives électriques / Locomotives électriques monophasé_@Test Locomotives électriques'
);
expect(infoCardText).toContain(
'BB 22200V160LOCOMOTIVES / Locomotives électriques / Locomotives électriques bi courant_@Test BB 22200'
);

const footerCardText = await playwrightSTDCMPage.getRollingStockListItem
.locator('.rollingstock-footer')
.allTextContents();
expect(footerCardText).toContain('25000V400m900t288km/h');

// Check if rollingstock detail is close
await expect(rollingstockItem).toHaveClass(/inactive/);
await rollingstockItem.click();

// Check if rollingstock detail is open
await expect(rollingstockItem).toHaveClass(/active/);

await rollingstockItem.locator('.rollingstock-footer-buttons > button').click();

// Check that the rollingstock is selected
await expect(
playwrightSTDCMPage.getRollingStockSelector.locator('.rollingstock-minicard')
).toBeVisible();

await expect(playwrightSTDCMPage.getMissingParam).not.toContainText(
rollingStockTranslationRegEx
);

await playwrightHomePage.backToHomePage();
await stdcmPage.backToHomePage();
});
});
6 changes: 2 additions & 4 deletions front/tests/assets/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, Page, request } from '@playwright/test';
import type { Project, Scenario, Study, RollingStock, Infra } from 'common/api/osrdEditoastApi';
import { PlaywrightHomePage } from '../pages/home-page-model';
import PlaywrightRollingstockModalPage from '../pages/rollingstock-modal-model';
import RollingStockSelectorPage from '../pages/rolling-stock-selector-page';
import PlaywrightMap, { selectPointOnMapProps } from '../pages/map-model';
import PlaywrightScenarioPage from '../pages/scenario-page-model';
import { ProjectPage } from '../pages/project-page-model';
Expand Down Expand Up @@ -45,9 +45,7 @@ export default async function createCompleteScenario(
await scenarioPage.setDelta(delta);

// ***************** Select Rolling Stock *****************
const playwrightRollingstockModalPage = new PlaywrightRollingstockModalPage(
playwrightHomePage.page
);
const playwrightRollingstockModalPage = new RollingStockSelectorPage(playwrightHomePage.page);
await playwrightRollingstockModalPage.openRollingstockModal();

const rollingstockCard = playwrightRollingstockModalPage.getRollingstockCardByTestID(
Expand Down
27 changes: 27 additions & 0 deletions front/tests/pages/base-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Locator, Page } from '@playwright/test';

export default class BasePage {
public page: Page;

private backToHomePageButton: Locator;

protected viteOverlay: Locator;

constructor(page: Page) {
this.page = page;

this.backToHomePageButton = page.locator('.mastheader-logo');
this.viteOverlay = page.locator('vite-plugin-checker-error-overlay');
}

// Completly remove VITE button & sign
async removeViteOverlay() {
if ((await this.viteOverlay.count()) > 0) {
await this.viteOverlay.evaluate((node) => node.setAttribute('style', 'display:none;'));
}
}

async backToHomePage() {
await this.backToHomePageButton.click();
}
}
81 changes: 81 additions & 0 deletions front/tests/pages/rolling-stock-selector-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Locator, Page, expect } from '@playwright/test';
import rollingstockTranslation from '../../public/locales/fr/rollingstock.json';
import BasePage from './base-page';

const electricCheckboxTranslation = rollingstockTranslation.electric;

export default class RollingStockSelectorPage extends BasePage {
clarani marked this conversation as resolved.
Show resolved Hide resolved
readonly rollingStockSelectorButton: Locator;

readonly rollingStockSelectorModal: Locator;

readonly getResultsFound: Locator;

private rollingStockList: Locator;

readonly rollingStockListItem: Locator;

readonly getRollingStockSearch: Locator;

readonly getRollingStockSearchFilter: Locator;

readonly rollingStockMiniCards: Locator;

readonly getRollingstockSpanNames: Locator;

readonly electricalCheckbox: Locator;

constructor(page: Page) {
super(page);
this.rollingStockSelectorButton = page.getByTestId('rollingstock-selector');
this.rollingStockSelectorModal = page.locator('.modal-dialog');

this.rollingStockList = page.locator('.rollingstock-search-list');
this.rollingStockListItem = page.locator('.rollingstock-container');

this.getResultsFound = page.locator('.modal-dialog').locator('small').first();
this.getRollingStockSearch = this.rollingStockSelectorModal.locator('#searchfilter');
this.getRollingStockSearchFilter = page.locator('.rollingstock-search-filters');
this.rollingStockMiniCards = page.locator('.rollingstock-selector-minicard');
this.getRollingstockSpanNames = page.locator('.rollingstock-minicard-name');
this.electricalCheckbox = this.rollingStockSelectorModal.locator('label').filter({
hasText: electricCheckboxTranslation,
});
}

async openRollingstockModal() {
await this.rollingStockSelectorButton.click();
}

async isAnyRollingstockFound() {
const resultFound = (await this.getResultsFound.textContent()) as string;
expect(Number(resultFound.slice(0, 1)) >= 1).toBeTruthy();
}

async searchRollingstock(rollingstockName: string) {
await this.getRollingStockSearch.fill(rollingstockName);
}

async selectRollingStock(rollingStockName: string) {
await this.getRollingStockSearch.fill(rollingStockName);
const rollingstockItem = this.rollingStockList.getByTestId(`rollingstock-${rollingStockName}`);
await rollingstockItem.click();
await rollingstockItem.locator('.rollingstock-footer-buttons > button').click();
}

getRollingstockCardByTestID(rollingstockTestID: string) {
return this.rollingStockSelectorModal.getByTestId(rollingstockTestID);
}

getRollingStockMiniCardInfo() {
return this.rollingStockMiniCards.locator('.rollingstock-info-end');
}

getRollingStockInfoComfort() {
return this.rollingStockMiniCards.locator('.rollingstock-info-comfort');
}

async closeRollingstockModal() {
await this.rollingStockSelectorModal.locator('.close').click();
}
}
66 changes: 0 additions & 66 deletions front/tests/pages/rollingstock-modal-model.ts

This file was deleted.

Loading
Loading