Skip to content

Commit

Permalink
front: test e2e - add rolling stock selector page
Browse files Browse the repository at this point in the history
  • Loading branch information
clarani committed Feb 16, 2024
1 parent daf8188 commit 41f5bcc
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 112 deletions.
6 changes: 2 additions & 4 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/RollingStockSelectorPage';
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,9 +38,7 @@ 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.rollingStockSelectorModal;
Expand Down
4 changes: 2 additions & 2 deletions front/tests/006-stdcm-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from '@playwright/test';
import PlaywrightSTDCMPage from './pages/stdcm-page-model';
import StdcmPage from './pages/stdcm-page-model';
import manageTrainScheduleTranslation from '../public/locales/fr/operationalStudies/manageTrainSchedule.json';

import project from './assets/operationStudies/project.json';
Expand All @@ -15,7 +15,7 @@ const rollingStockTranslation = manageTrainScheduleTranslation.rollingstock;

test.describe('STDCM page (enabled)', () => {
test('should correctly display the rolling stock list and select one', async ({ page }) => {
const stdcmPage = new PlaywrightSTDCMPage(page);
const stdcmPage = new StdcmPage(page);

await stdcmPage.navigateToPage();
await expect(stdcmPage.scenarioExplorerModal).not.toBeVisible();
Expand Down
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
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 {
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.

38 changes: 2 additions & 36 deletions front/tests/pages/stdcm-page-model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, Locator, Page } from '@playwright/test';

import BasePage from './base-page';
import RollingStockSelectorPage from './rolling-stock-selector-page';

export default class PlaywrightSTDCMPage extends BasePage {
export default class StdcmPage extends RollingStockSelectorPage {
readonly missingParams: Locator;

// Scenario Explorator
Expand All @@ -12,17 +12,6 @@ export default class PlaywrightSTDCMPage extends BasePage {

private scenarioExplorerMinicards: Locator;

// Rolling stock selector
readonly rollingStockSelectorButton: Locator;

readonly rollingStockSelectorModal: Locator;

private rollingStockList: Locator;

readonly getRollingStockSearch: Locator;

readonly rollingStockListItem: Locator;

// STDCM
private getOriginTimeDelta: Locator;

Expand All @@ -36,13 +25,6 @@ export default class PlaywrightSTDCMPage extends BasePage {
this.scenarioExplorerModal = page.locator('.scenario-explorator-modal');
this.scenarioExplorerMinicards = page.locator('.minicard');

// Rollingstock
this.rollingStockSelectorModal = page.locator('.modal-dialog');
this.rollingStockSelectorButton = page.getByTestId('rollingstock-selector');
this.rollingStockList = page.locator('.rollingstock-search-list');
this.rollingStockListItem = page.locator('.rollingstock-container');
this.getRollingStockSearch = this.rollingStockSelectorModal.locator('#searchfilter');

// STDCM
this.getOriginTimeDelta = page.locator('#osrd-config-time-origin').first();
}
Expand All @@ -63,22 +45,6 @@ export default class PlaywrightSTDCMPage extends BasePage {
await miniCards.first().click();
}

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

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();
}

async closeRollingstockModal() {
await this.rollingStockSelectorModal.locator('.close').click();
}

// STDCM
async setOriginTime(digits: string) {
const splittedDigit = digits.split('');
Expand Down

0 comments on commit 41f5bcc

Please sign in to comment.