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 17, 2024
1 parent a3464b9 commit a60a60e
Show file tree
Hide file tree
Showing 28 changed files with 383 additions and 138 deletions.
3 changes: 1 addition & 2 deletions front/src/common/BootstrapSNCF/SwitchSNCF/SwitchSNCF.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ const SwitchSNCF: FC<SwitchSNCFProps> = ({
<label htmlFor={id} className="switch-control">
<span className="sr-only">On/Off switch</span>
<input
data-testid={name}
id={id}
type="checkbox"
className="sr-only"
onChange={onChange}
checked={checked}
disabled={disabled}
/>
<span className="switch-control-slider" />
<span data-testid={name} className="switch-control-slider" />
</label>
);
case SWITCH_TYPES.options:
Expand Down
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
30 changes: 15 additions & 15 deletions front/tests/001-home-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
import { test, expect } from '@playwright/test';

import { PlaywrightHomePage } from './pages/home-page-model';
import { HomePage } from './pages/home-page-model';

// Describe the test suite for the home page of OSRD
test.describe('Home page OSRD', () => {
let playwrightHomePage: PlaywrightHomePage;
let homePage: HomePage;

test.beforeEach(async ({ page }) => {
// Create an instance of the PlaywrightHomePage class
playwrightHomePage = new PlaywrightHomePage(page);
// Create an instance of the HomePage class
homePage = new HomePage(page);
// Go to the home page of OSRD
await playwrightHomePage.goToHomePage();
await homePage.goToHomePage();
});

test.afterEach(async () => {
// Navigate back to the home page of OSRD
await playwrightHomePage.backToHomePage();
await homePage.backToHomePage();
});

// Test that the home page of OSRD displays links to other pages
test('should display links in the home page', async () => {
await playwrightHomePage.getDisplayLinks();
await homePage.getDisplayLinks();
});

test('should be correctly redirected to the "Operational Studies" page after clicking on the link', async () => {
// Navigate to the "Operational Studies" page
await playwrightHomePage.goToOperationalStudiesPage();
await homePage.goToOperationalStudiesPage();
// Check that the URL of the page matches the expected pattern
await expect(playwrightHomePage.page).toHaveURL(/.*\/operational-studies/);
await expect(homePage.page).toHaveURL(/.*\/operational-studies/);
});

test('should be correctly redirected to the "Map" page after clicking on the link', async () => {
// Navigate to the "Map" page
await playwrightHomePage.goToCartoPage();
await homePage.goToCartoPage();

// Check that the URL of the page matches the expected pattern
await expect(playwrightHomePage.page).toHaveURL(/.*\/map/);
await expect(homePage.page).toHaveURL(/.*\/map/);
});

test('should be correctly redirected to the "Editor" page after clicking on the link', async () => {
// Navigate to the "Editor" page
await playwrightHomePage.goToEditorPage();
await homePage.goToEditorPage();

// Check that the URL of the page matches the expected pattern
await expect(playwrightHomePage.page).toHaveURL(/.*\/editor\/*/);
await expect(homePage.page).toHaveURL(/.*\/editor\/*/);
});

test('should be correctly redirected to the "STDCM" page after clicking on the link', async () => {
// Navigate to the "STDCM" page
await playwrightHomePage.goToSTDCMPage();
await homePage.goToSTDCMPage();

// Check that the URL of the page matches the expected pattern
await expect(playwrightHomePage.page).toHaveURL(/.*\/stdcm/);
await expect(homePage.page).toHaveURL(/.*\/stdcm/);
});
});
26 changes: 13 additions & 13 deletions front/tests/002-project-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { v4 as uuidv4 } from 'uuid';
import type { Project } from 'common/api/osrdEditoastApi';

import projectData from './assets/operationStudies/project.json';
import { deleteApiRequest, getApiRequest, postApiRequest } from './utils/index';
import PlaywrightCommonPage from './pages/common-page-model';
import { PlaywrightHomePage } from './pages/home-page-model';
import CommonPage from './pages/common-page-model';
import { HomePage } from './pages/home-page-model';
import { ProjectPage } from './pages/project-page-model';
import { deleteApiRequest, getApiRequest, postApiRequest } from './utils/index';

let project: Project;

Expand All @@ -25,12 +25,12 @@ test.afterEach(async () => {

test.describe('Test if operationnal study : project workflow is working properly', () => {
test('Create a new project', async ({ page }) => {
const playwrightHomePage = new PlaywrightHomePage(page);
const homePage = new HomePage(page);
const projectPage = new ProjectPage(page);
const commonPage = new PlaywrightCommonPage(page);
const commonPage = new CommonPage(page);

await playwrightHomePage.goToHomePage();
await playwrightHomePage.goToOperationalStudiesPage();
await homePage.goToHomePage();
await homePage.goToOperationalStudiesPage();
await expect(projectPage.getAddProjectBtn).toBeVisible();
await projectPage.openProjectModalCreation();

Expand All @@ -49,9 +49,9 @@ test.describe('Test if operationnal study : project workflow is working properly
await commonPage.setTag(projectData.tags[1]);
await commonPage.setTag(projectData.tags[2]);

const createButton = playwrightHomePage.page.getByTestId('createProject');
const createButton = homePage.page.getByTestId('createProject');
await createButton.click();
await playwrightHomePage.page.waitForURL('**/projects/*');
await homePage.page.waitForURL('**/projects/*');
expect(await projectPage.getProjectName.textContent()).toContain(projectName);
expect(await projectPage.getProjectDescription.textContent()).toContain(
projectData.description
Expand Down Expand Up @@ -79,9 +79,9 @@ test.describe('Test if operationnal study : project workflow is working properly
});

test(' update a project', async ({ page }) => {
const playwrightHomePage = new PlaywrightHomePage(page);
const homePage = new HomePage(page);
const projectPage = new ProjectPage(page);
const commonPage = new PlaywrightCommonPage(page);
const commonPage = new CommonPage(page);

await page.goto('/operational-studies/projects');

Expand All @@ -103,8 +103,8 @@ test.describe('Test if operationnal study : project workflow is working properly

await projectPage.clickProjectUpdateConfirmBtn();

await playwrightHomePage.goToHomePage();
await playwrightHomePage.goToOperationalStudiesPage();
await homePage.goToHomePage();
await homePage.goToOperationalStudiesPage();

await projectPage.openProjectByTestId(`${project.name} (updated)`);

Expand Down
22 changes: 11 additions & 11 deletions front/tests/003-study-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { v4 as uuidv4 } from 'uuid';
import type { Project, Study } from 'common/api/osrdEditoastApi';

import studyData from './assets/operationStudies/study.json';
import { getProject, postApiRequest } from './utils/index';
import PlaywrightCommonPage from './pages/common-page-model';
import { PlaywrightHomePage } from './pages/home-page-model';
import CommonPage from './pages/common-page-model';
import { HomePage } from './pages/home-page-model';
import { StudyPage } from './pages/study-page-model';
import { getProject, postApiRequest } from './utils/index';

let project: Project;
let study: Study;
Expand All @@ -27,9 +27,9 @@ test.beforeEach(async () => {

test.describe('Test if operationnal study: study creation workflow is working properly', () => {
test('Create a new study', async ({ page }) => {
const playwrightHomePage = new PlaywrightHomePage(page);
const homePage = new HomePage(page);
const studyPage = new StudyPage(page);
const commonPage = new PlaywrightCommonPage(page);
const commonPage = new CommonPage(page);

await page.goto(`/operational-studies/projects/${project.id}`);

Expand Down Expand Up @@ -62,9 +62,9 @@ test.describe('Test if operationnal study: study creation workflow is working pr
await commonPage.setTag(project.tags[1]);
await commonPage.setTag(project.tags[2]);

const createButton = playwrightHomePage.page.getByTestId('createStudy');
const createButton = homePage.page.getByTestId('createStudy');
await createButton.click();
await playwrightHomePage.page.waitForURL('**/studies/*');
await homePage.page.waitForURL('**/studies/*');
expect(await studyPage.getStudyName.textContent()).toContain(studyName);
expect(await studyPage.getStudyDescription.textContent()).toContain(studyData.description);
expect(await studyPage.getStudyType.textContent()).toContain(studyData.type);
Expand All @@ -85,7 +85,7 @@ test.describe('Test if operationnal study: study creation workflow is working pr

test(' update a study', async ({ page }) => {
const studyPage = new StudyPage(page);
const commonPage = new PlaywrightCommonPage(page);
const commonPage = new CommonPage(page);

await page.goto(`/operational-studies/projects/${project.id}/studies/${study.id}`);

Expand Down Expand Up @@ -139,7 +139,7 @@ test.describe('Test if operationnal study: study creation workflow is working pr
});

test('Delete a study', async ({ page }) => {
const playwrightHomePage = new PlaywrightHomePage(page);
const homePage = new HomePage(page);
const studyPage = new StudyPage(page);

await page.goto(`/operational-studies/projects/${project.id}/studies/${study.id}`);
Expand All @@ -148,8 +148,8 @@ test.describe('Test if operationnal study: study creation workflow is working pr

await studyPage.clickStudyDeleteConfirmBtn();

await playwrightHomePage.goToHomePage();
await playwrightHomePage.goToOperationalStudiesPage();
await homePage.goToHomePage();
await homePage.goToOperationalStudiesPage();

await expect(studyPage.getStudyByName(studyData.name)).not.toBeVisible();
});
Expand Down
16 changes: 8 additions & 8 deletions front/tests/004-scenario-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { v4 as uuidv4 } from 'uuid';
import type { Infra, Project, Scenario, Study } from 'common/api/osrdEditoastApi';

import scenarioData from './assets/operationStudies/scenario.json';
import { getInfra, getProject, getStudy, postApiRequest } from './utils/index';
import PlaywrightCommonPage from './pages/common-page-model';
import { PlaywrightHomePage } from './pages/home-page-model';
import CommonPage from './pages/common-page-model';
import { HomePage } from './pages/home-page-model';
import ScenarioPage from './pages/scenario-page-model';
import { getInfra, getProject, getStudy, postApiRequest } from './utils/index';

let smallInfra: Infra;
let project: Project;
Expand All @@ -31,9 +31,9 @@ test.beforeEach(async () => {

test.describe('Test if operationnal study : scenario creation workflow is working properly', () => {
test('Create a new scenario', async ({ page }) => {
const playwrightHomePage = new PlaywrightHomePage(page);
const homePage = new HomePage(page);
const scenarioPage = new ScenarioPage(page);
const commonPage = new PlaywrightCommonPage(page);
const commonPage = new CommonPage(page);

await page.goto(`/operational-studies/projects/${project.id}/studies/${study.id}`);

Expand All @@ -55,9 +55,9 @@ test.describe('Test if operationnal study : scenario creation workflow is workin
await commonPage.setTag(scenarioData.tags[2]);

await scenarioPage.setScenarioInfraByName('small_infra_test_e2e');
const createButton = playwrightHomePage.page.getByTestId('createScenario');
const createButton = homePage.page.getByTestId('createScenario');
await createButton.click();
await playwrightHomePage.page.waitForURL('**/scenarios/*');
await homePage.page.waitForURL('**/scenarios/*');
expect(await scenarioPage.getScenarioName.textContent()).toContain(scenarioName);
expect(await scenarioPage.getScenarioDescription.textContent()).toContain(
scenarioData.description
Expand All @@ -67,7 +67,7 @@ test.describe('Test if operationnal study : scenario creation workflow is workin

test('Update a scenario', async ({ page }) => {
const scenarioPage = new ScenarioPage(page);
const commonPage = new PlaywrightCommonPage(page);
const commonPage = new CommonPage(page);

await page.goto(
`/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}`
Expand Down
35 changes: 17 additions & 18 deletions front/tests/005-operational-studies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ 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 './utils/index';
import { PlaywrightHomePage } from './pages/home-page-model';
import { HomePage } from './pages/home-page-model';
import RollingStockSelectorPage from './pages/rolling-stock-selector-page';
import PlaywrightScenarioPage from './pages/scenario-page-model';
import ScenarioPage from './pages/scenario-page-model';
import { getProject, getStudy, getRollingStock, postApiRequest, getInfra } from './utils/index';

let smallInfra: Infra;
let project: Project;
Expand All @@ -33,32 +33,31 @@ test.beforeEach(async () => {

test.describe('Testing if all mandatory elements simulation configuration are loaded in operationnal studies app', () => {
test('Testing pathfinding with rollingstock and composition code', async ({ page }) => {
const playwrightHomePage = new PlaywrightHomePage(page);
const scenarioPage = new PlaywrightScenarioPage(page);

const homePage = new HomePage(page);
const scenarioPage = new ScenarioPage(page);
await page.goto(
`/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}`
);

await scenarioPage.checkInfraLoaded();
await playwrightHomePage.page.getByTestId('scenarios-add-train-schedule-button').click();
await homePage.page.getByTestId('scenarios-add-train-schedule-button').click();

await scenarioPage.setTrainScheduleName('TrainSchedule');
const trainCount = '7';
await scenarioPage.setNumberOfTrains(trainCount);

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

// Voluntarily add spaces and capital letters so we also test the normalization of the search functionality
await playwrightRollingstockModalPage.searchRollingstock(' rollingstock_1500_25000_test_E2E ');
await rollingstockModalPage.searchRollingstock(' rollingstock_1500_25000_test_E2E ');

const rollingstockCard = playwrightRollingstockModalPage.getRollingstockCardByTestID(
const rollingstockCard = rollingstockModalPage.getRollingstockCardByTestID(
`rollingstock-${rollingStock.name}`
);
await expect(rollingstockCard).toHaveClass(/inactive/);
Expand All @@ -67,12 +66,12 @@ test.describe('Testing if all mandatory elements simulation configuration are lo

await rollingstockCard.locator('button').click();

expect(
await playwrightRollingstockModalPage.getRollingStockMiniCardInfo().first().textContent()
).toMatch(rollingStock.name);
expect(
await playwrightRollingstockModalPage.getRollingStockInfoComfort().textContent()
).toMatch(/ConfortSStandard/i);
expect(await rollingstockModalPage.getRollingStockMiniCardInfo().first().textContent()).toMatch(
rollingStock.name
);
expect(await rollingstockModalPage.getRollingStockInfoComfort().textContent()).toMatch(
/ConfortSStandard/i
);

// ***************** Test choice Origin/Destination *****************
await scenarioPage.openTabByDataId('tab-pathfinding');
Expand Down
Loading

0 comments on commit a60a60e

Please sign in to comment.