Skip to content

Commit

Permalink
front: refacto old e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: maymanaf <[email protected]>

front: add op simulation settings e2e test

Signed-off-by: maymanaf <[email protected]>
  • Loading branch information
Maymanaf committed Oct 22, 2024
1 parent a21994d commit 6b02ebf
Show file tree
Hide file tree
Showing 58 changed files with 2,864 additions and 2,704 deletions.
2 changes: 1 addition & 1 deletion front/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default defineConfig({
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry up to 3 times on CI, and 1 time otherwise */
retries: process.env.CI ? 3 : 1,
retries: process.env.CI ? 2 : 1,
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function BreadCrumbs({ project, study, scenario }: Props) {

{project && study && (
<>
<div className="text-truncate" title={project.name}>
<div data-testid="project-breadcrumbs" className="text-truncate" title={project.name}>
<Link to={`/operational-studies/projects/${project.id}`}> {project.name}</Link>
</div>
<span className="text-muted">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const ScenarioDescription = ({
</button>
</div>
<button
data-testid="editScenario"
data-testid="edit-scenario"
className="update-scenario"
type="button"
aria-label={t('editScenario')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const Project = () => {
<div className="project-details-title-name">
{project.name}
<button
data-testid="project-update-button"
className="project-details-title-modify-button"
type="button"
onClick={() =>
Expand Down
4 changes: 3 additions & 1 deletion front/src/common/BootstrapSNCF/CardSNCF/CardSNCF.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const Card = ({ link, img, title, disabledLink = false, openInNewTab = false }:
>
<img className="card-img-top" alt={title} src={img} />
<div className="card-body text-center">
<h5 className="card-title mb-0 text-base font-weight-normal">{title}</h5>
<h5 data-testid="page-title" className="card-title mb-0 text-base font-weight-normal">
{title}
</h5>
</div>
</Link>
);
Expand Down
7 changes: 6 additions & 1 deletion front/src/common/BootstrapSNCF/ChipsSNCF.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export default function ChipsSNCF({
return (
<div role="list" key={nextId()}>
<div className="chips-group" role="listitem">
<span className={`chips chips-label pr-1 ${chipColor}`}>{label}</span>
<span
data-testid="scenario-details-tag"
className={`chips chips-label pr-1 ${chipColor}`}
>
{label}
</span>
<button
type="button"
className={`chips chips-btn chips-only-icon ${chipColor}`}
Expand Down
2 changes: 1 addition & 1 deletion front/src/common/BootstrapSNCF/NavBarSNCF.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const LegacyNavBarSNCF = ({ appName, logo = getLogo() }: Props) => {
<div className="mastheader">
<div className="mastheader-logo flex-grow-0">
<Link to="/">
<img src={logo} alt="OSRD Logo" />
<img src={logo} data-testid="osrd-logo" alt="OSRD Logo" />
</Link>
</div>
<header role="banner" className="mastheader-title d-flex flex-grow-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function InfraSelectorModalBodyStandard({
<div className="text-center small text-muted infras-count">
{infrasList && t('infraManagement:infrasFound', { count: infrasList.length })}
</div>
<div className="infraslist" data-testid="infraslist">
<div className="infraslist" data-testid="infra-list">
{infrasList.map((infra) => (
<button
data-testid={`infraslist-item-${infra.id}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ export default function AddOrEditProjectModal({
<div className="d-flex justify-content-end w-100">
{editionMode && (
<button
data-testid="delete-project"
className="btn btn-outline-danger mr-auto"
type="button"
onClick={removeProject}
Expand All @@ -450,7 +451,7 @@ export default function AddOrEditProjectModal({
</button>
{editionMode ? (
<button
data-testid="updateProject"
data-testid="update-project"
className="btn btn-warning"
type="button"
onClick={updateProject}
Expand All @@ -462,7 +463,7 @@ export default function AddOrEditProjectModal({
</button>
) : (
<button
data-testid="createProject"
data-testid="create-project"
className="btn btn-primary"
type="button"
onClick={createProject}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ const AddOrEditScenarioModal = ({ editionMode = false, scenario }: AddOrEditScen
<div className="d-flex justify-content-end w-100 mt-3">
{editionMode && (
<button
data-testid="deleteScenario"
data-testid="delete-scenario"
className="btn btn-sm btn-outline-danger mr-auto"
type="button"
onClick={removeScenario}
Expand All @@ -385,7 +385,7 @@ const AddOrEditScenarioModal = ({ editionMode = false, scenario }: AddOrEditScen
</button>
{editionMode ? (
<button
data-testid="updateScenario"
data-testid="update-scenario"
className="btn btn-sm btn-warning"
type="button"
onClick={updateScenario}
Expand All @@ -397,7 +397,7 @@ const AddOrEditScenarioModal = ({ editionMode = false, scenario }: AddOrEditScen
</button>
) : (
<button
data-testid="createScenario"
data-testid="create-scenario"
className="btn btn-sm btn-primary"
type="button"
onClick={createScenario}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function StudyCard() {

return (
<div
data-testid="addScenario"
data-testid="add-scenario-button"
className="scenario-card empty"
role="button"
tabIndex={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { describe, it, expect } from 'vitest';

import { LIST_VALUES, CHART_AXES } from 'modules/simulationResult/consts';

import simulationTrain from '../../../../../../tests/assets/operationStudies/simulationTrain';
import train from '../../../../../../tests/assets/operationStudies/trainExample';
import simulationTrain from '../../../../../assets/operationStudies/simulationTrain';
import train from '../../../../../assets/operationStudies/trainExample';
import { interpolateOnTime, getAxis } from '../ChartHelpers';

describe('interpolateOnTime', () => {
Expand Down
71 changes: 35 additions & 36 deletions front/tests/001-home-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';

import HomePage from './pages/home-page-model';
import test from './test-logger';
import enTranslations from '../public/locales/en/home/home.json';
import frTranslations from '../public/locales/fr/home/home.json';

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

test.beforeEach(async ({ page }) => {
// Create an instance of the HomePage class
let OSRDLanguage: string;
test.beforeEach('Navigate to the home page', async ({ page }) => {
homePage = new HomePage(page);
// Go to the home page of OSRD
await homePage.goToHomePage();
OSRDLanguage = await homePage.getOSRDLanguage();
});

test.afterEach(async () => {
// Navigate back to the home page of OSRD
test.afterEach('Returns to the home page', async () => {
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 homePage.getDisplayLinks();
/** *************** Test 1 **************** */
test('Verify the links for different pages in Home Page', async () => {
// Determine the correct translations based on the selected language
const translations = OSRDLanguage === 'English' ? enTranslations : frTranslations;

// List of expected links on the home page
const expectedLinks = [
translations.operationalStudies,
translations.stdcm,
translations.editor,
translations.rollingStockEditor,
translations.map,
];

// Verify that the displayed links match the expected ones
await expect(homePage.linksTitle).toHaveText(expectedLinks);
});

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

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

// Check that the URL of the page matches the expected pattern
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
/** *************** Test 4 **************** */
test('Verify redirection to to the Infrastructure editor page', async () => {
await homePage.goToEditorPage();

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

test('should be correctly redirected to the "STDCM" page after clicking on the link', async ({
context,
}) => {
// Start waiting for new page before clicking. Note no await.
const pagePromise = context.waitForEvent('page');

// Navigate to the "STDCM" page
await homePage.goToSTDCMPage();

const newPage = await pagePromise;

// Check that the URL of the page matches the expected pattern
await expect(newPage).toHaveURL(/.*\/stdcm/);
/** *************** Test 5 **************** */
test('Verify redirection to to the STDCM page', async ({ context }) => {
const stdcmPage = await homePage.goToSTDCMPage(context);
await expect(stdcmPage).toHaveURL(/.*\/stdcm/);
});
});
Loading

0 comments on commit 6b02ebf

Please sign in to comment.