Skip to content

Commit

Permalink
front: add route 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 0a3210d commit 13353da
Show file tree
Hide file tree
Showing 34 changed files with 879 additions and 420 deletions.
2 changes: 1 addition & 1 deletion front/src/common/BootstrapSNCF/NavBarSNCF.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const LegacyNavBarSNCF = ({ appName, logo = getLogo() }: Props) => {
<span className="mr-2">
{i18n.language && getUnicodeFlagIcon(language2flag(i18n.language))}
</span>
{t(`language.${i18n.language}`)}
<span data-testid="language-info">{t(`language.${i18n.language}`)} </span>
</button>,
<button
data-testid="user-settings-btn"
Expand Down
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 @@ -26,7 +26,7 @@ const DestinationV2 = ({ zoomToFeaturePoint }: DestinationProps) => {
<span className="text-warning mr-2">
<IoFlag />
</span>
{t('noDestinationChosen')}
<span data-testid="no-destination-chosen-text">{t('noDestinationChosen')}</span>
</>
);

Expand All @@ -42,13 +42,14 @@ const DestinationV2 = ({ zoomToFeaturePoint }: DestinationProps) => {
tabIndex={0}
className="flex-grow-1"
>
<strong className="mr-1 text-nowrap">
<strong data-testid="destination-op-info" className="mr-1 text-nowrap">
{/* If destination doesn't have name, we know that it has been added by click on map and has a track property */}
{destination?.name ||
(destination && 'track' in destination && destination.track.split('-')[0])}
</strong>
</div>
<button
data-testid="delete-destination-button"
className="btn btn-sm btn-only-icon btn-white ml-auto"
type="button"
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const OriginV2 = ({ zoomToFeaturePoint }: OriginProps) => {
role="button"
tabIndex={0}
>
<strong className="mr-1 text-nowrap">
<strong data-testid="origin-op-info" className="mr-1 text-nowrap">
{/* If origin doesn't have name, we know that it has been added by click on map and has a track property */}
{origin?.name || (origin && 'track' in origin && origin.track.split('-')[0])}
</strong>
Expand Down Expand Up @@ -87,7 +87,7 @@ const OriginV2 = ({ zoomToFeaturePoint }: OriginProps) => {
<span className="text-success mr-2">
<RiMapPin2Fill />
</span>
{t('noOriginChosen')}
<span data-testid="no-origin-chosen-text">{t('noOriginChosen')}</span>
</>
);

Expand All @@ -99,6 +99,7 @@ const OriginV2 = ({ zoomToFeaturePoint }: OriginProps) => {
</span>
<span className="flex-grow-1">{originPointName}</span>
<button
data-testid="delete-origin-button"
className="btn btn-sm btn-only-icon btn-white"
type="button"
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const ViasV2 = ({ zoomToFeaturePoint, shouldManageStopDuration }: DisplayViasV2P
>
{(providedDraggable) => (
<div
data-testid="drooped-via-info"
ref={providedDraggable.innerRef}
{...providedDraggable.draggableProps}
{...providedDraggable.dragHandleProps}
Expand All @@ -59,12 +60,14 @@ const ViasV2 = ({ zoomToFeaturePoint, shouldManageStopDuration }: DisplayViasV2P
tabIndex={0}
>
<small className="font-weight-bold text-muted mr-1">{index + 1}</small>
<small className="mr-1 text-nowrap">
<small data-testid="via-dropped-name" className="mr-1 text-nowrap">
{`${via.name || `KM ${via.positionOnPath && (Math.round(via.positionOnPath) / 1000000).toFixed(3)}`}`}
</small>
{via.ch && <small>{via.ch}</small>}
{via.ch && <small data-testid="via-dropped-ch">{via.ch}</small>}
{'uic' in via && (
<small className="text-muted ml-3">{formatUicToCi(via.uic)}</small>
<small data-testid="via-dropped-uic" className="text-muted ml-3">
{formatUicToCi(via.uic)}
</small>
)}
</div>
{shouldManageStopDuration && (
Expand All @@ -75,6 +78,7 @@ const ViasV2 = ({ zoomToFeaturePoint, shouldManageStopDuration }: DisplayViasV2P
/>
)}
<button
data-testid="delete-via-button"
className="btn btn-sm btn-only-icon btn-white ml-auto"
type="button"
onClick={() => dispatch(deleteViaV2(index))}
Expand Down
13 changes: 11 additions & 2 deletions front/src/modules/pathfinding/components/Itinerary/ItineraryV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const ItineraryV2 = ({
<div className="d-flex flex-row flex-wrap">
{pathProperties && pathProperties.suggestedOperationalPoints && (
<button
data-testid="add-waypoints-button"
className="col my-1 text-white btn bg-info btn-sm"
type="button"
onClick={() =>
Expand All @@ -108,12 +109,18 @@ const ItineraryV2 = ({
<Plus />
</button>
)}
<button className="col ml-1 my-1 btn bg-warning btn-sm" type="button" onClick={inverseOD}>
<button
data-testid="reverse-itinerary-button"
className="col ml-1 my-1 btn bg-warning btn-sm"
type="button"
onClick={inverseOD}
>
<span className="mr-1">{t('inverseOD')}</span>
<ArrowSwitch />
</button>
<Tipped mode="right">
<button
data-testid="delete-itinerary-button"
type="button"
className="ml-1 mt-1 btn-danger btn btn-sm"
aria-label={t('deleteRoute')}
Expand All @@ -135,7 +142,9 @@ const ItineraryV2 = ({
shouldManageStopDuration={shouldManageStopDuration}
/>
) : (
<small className="ml-4">{t('noPlaceChosen')}</small>
<small data-testid="no-waypoint-chosen-text" className="ml-4">
{t('noPlaceChosen')}
</small>
)}
</div>
<DestinationV2 zoomToFeaturePoint={zoomToFeaturePoint} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ const ModalSuggestedVias = ({ suggestedVias }: ModalSuggestedViasProps) => {
{op.uic && <small className="suggested-via-uic text-muted">{formatUicToCi(op.uic)}</small>}
<div className="ml-auto">
{op.positionOnPath && (
<small className="mr-2">{`KM ${(Math.round(op.positionOnPath) / 1000000).toFixed(3)}`}</small>
<small
data-testid="suggested-via-distance"
className="mr-2"
>{`KM ${(Math.round(op.positionOnPath) / 1000000).toFixed(3)}`}</small>
)}
{!isInVias ? (
<button
data-testid="suggested-via-add-button"
className="btn btn-sm btn-only-icon"
type="button"
aria-label={t('addVia')}
Expand All @@ -77,6 +81,7 @@ const ModalSuggestedVias = ({ suggestedVias }: ModalSuggestedViasProps) => {
</button>
) : (
<button
data-testid="suggested-via-delete-button"
className="btn btn-sm btn-only-icon"
type="button"
aria-label={t('removeVia')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const Pathfinding = ({ pathProperties, setPathProperties }: PathfindingProps) =>

{!pathProperties && isPathFindingActive ? (
<div
data-testid="pathfinding-no-state"
className={cx('content pathfinding-none', { 'mt-2': infra && infra.state !== 'CACHED' })}
>
{t('pathfindingNoState')}
Expand All @@ -103,7 +104,7 @@ const Pathfinding = ({ pathProperties, setPathProperties }: PathfindingProps) =>
<span className="lead">
<Alert />
</span>
<span className="flex-grow-1">
<span data-testid="missing-params-info" className="flex-grow-1">
{t('pathfindingMissingParams', { missingElements })}
</span>
</div>
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 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';
import PlaywrightCommonPage from './pages/common-page-model';
import { PlaywrightHomePage } from './pages/home-page-model';
import { ProjectPage } from './pages/project-page-model';

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 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';
import PlaywrightCommonPage from './pages/common-page-model';
import { PlaywrightHomePage } from './pages/home-page-model';
import { StudyPage } from './pages/study-page-model';

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
Loading

0 comments on commit 13353da

Please sign in to comment.