Skip to content

Commit

Permalink
front: add op simulation settings e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: maymanaf <med.aymen.naf@gmail.com>
  • Loading branch information
Maymanaf committed Oct 17, 2024
1 parent 08ee2c5 commit 093d78f
Show file tree
Hide file tree
Showing 53 changed files with 6,917 additions and 502 deletions.
2 changes: 1 addition & 1 deletion front/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default defineConfig({
use: {
browserName: 'webkit',
launchOptions: {
slowMo: 50, // Slows down WebKit interactions by 50 milliseconds
slowMo: 150, // Slows down WebKit interactions by 150 milliseconds
},
},
dependencies: ['setup'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const ScenarioContent = ({
<div className="scenario">
<div className="row scenario-container">
<div
data-testid="scenario-sidemenu"
className={`scenario-sidemenu ${collapsedTimetable ? 'd-none' : 'col-hdp-3 col-xl-4 col-lg-5 col-md-6'}`}
>
<div className="scenario-sidemenu">
Expand Down Expand Up @@ -188,6 +189,7 @@ const ScenarioContent = ({
<>
<div className="scenario-timetable-collapsed">
<button
data-testid="timetable-collapse-button"
className="timetable-collapse-button"
type="button"
aria-label={t('toggleTimetable')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ScenarioDescription = ({
)}
<div className="flex justify-end">
<button
data-testid="scenario-collapse-button"
type="button"
className="scenario-collapse-button"
aria-label={t('toggleTimetable')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ const TimetableTrainCard = ({
(train.notHonoredReason === 'scheduleNotHonored' ? <Clock /> : <Flame />)}
</div>
{train.arrivalTime && (
<div className="scenario-timetable-train-arrival" title={train.arrivalTime}>
<div
data-testid="train-arrival-time"
className="scenario-timetable-train-arrival"
title={train.arrivalTime}
>
{/* TODO: delete the format when the date management `PR` has been passed */}
{dayjs(train.arrivalTime, 'D/MM/YYYY HH:mm:ss').format('HH:mm')}
</div>
Expand Down
2 changes: 1 addition & 1 deletion front/tests/002-project-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test.afterEach(async () => {
await deleteApiRequest(`/api/projects/${project.id}/`);
});

test.describe('Test if operationnal study : project workflow is working properly', () => {
test.describe('Test if project workflow is working properly', () => {
test('Create a new project', async ({ page }) => {
const homePage = new HomePage(page);
const projectPage = new ProjectPage(page);
Expand Down
4 changes: 2 additions & 2 deletions front/tests/003-study-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let project: Project;
let study: Study;

test.beforeAll(async () => {
project = await getProject();
project = await getProject('project_test_e2e');
});

test.beforeEach(async () => {
Expand All @@ -31,7 +31,7 @@ test.beforeEach(async () => {
});
});

test.describe('Test if operationnal study: study creation workflow is working properly', () => {
test.describe('Test if study creation workflow is working properly', () => {
test('Create a new study', async ({ page }) => {
const studyPage = new StudyPage(page);
const commonPage = new CommonPage(page);
Expand Down
2 changes: 1 addition & 1 deletion front/tests/004-scenario-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test.beforeEach(async () => {
({ project, study, scenario } = await setupScenario());
});

test.describe('Test if operationnal study : scenario creation workflow is working properly', () => {
test.describe('Test if scenario creation workflow is working properly', () => {
test('Create a new scenario', async ({ page }) => {
const homePage = new HomePage(page);
const scenarioPage = new ScenarioPage(page);
Expand Down
8 changes: 4 additions & 4 deletions front/tests/005-operational-studies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ let scenario: Scenario;
let rollingStock: RollingStock;

test.beforeAll(async () => {
rollingStock = await getRollingStock();
rollingStock = await getRollingStock('electric_rolling_stock_test_e2e');
});

test.beforeEach(async () => {
({ project, study, scenario } = await setupScenario());
});

test.describe('Testing if all mandatory elements simulation configuration are loaded in operationnal studies app', () => {
test.describe('Testing if all mandatory elements simulation configuration are loaded in operational studies app', () => {
test('Testing pathfinding with rollingstock and composition code', async ({ page }) => {
// Add enough timeout to wait for the infra to be loaded
test.slow();
Expand All @@ -47,7 +47,7 @@ test.describe('Testing if all mandatory elements simulation configuration are lo
await expect(rollingstockModal).toBeVisible();

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

const rollingstockCard = rollingstockModalPage.getRollingstockCardByTestID(
`rollingstock-${rollingStock.name}`
Expand All @@ -72,7 +72,7 @@ test.describe('Testing if all mandatory elements simulation configuration are lo

await scenarioPage.getPathfindingByTriGramSearch('MWS', 'NES');

await scenarioPage.checkPathfindingDistance('34.000 km');
await scenarioPage.checkPathfindingDistance('33.950 km');

// ***************** Test Add Train Schedule *****************
await scenarioPage.addTrainSchedule();
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
Expand Up @@ -10,12 +10,12 @@ import manageTrainScheduleTranslation from '../public/locales/fr/operationalStud
const projectName = project.name;
const studyName = study.name;
const scenarioName = scenario.name;
const rollingStockName = 'rollingstock_1500_25000_test_e2e';
const rollingStockName = 'electric_rolling_stock_test_e2e';

const emptyRouteTranslation = manageTrainScheduleTranslation.pathfindingNoState;

test.describe('STDCM page', () => {
// TODO: Refacto this test for the new stdcm page
// TODO: Refactor this test for the new stdcm page
test.skip('should configure and launch a stdcm', async ({ page }) => {
const stdcmPage = new StdcmPage(page);

Expand Down
6 changes: 3 additions & 3 deletions front/tests/007-op-rollingstock-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ let study: Study;
let scenario: Scenario;
let rollingStock: RollingStock;

const dualModeRollingStockName = 'dual-mode_rollingstock_test_e2e';
const electricRollingStockName = 'rollingstock_1500_25000_test_e2e';
const dualModeRollingStockName = 'dual-mode_rolling_stock_test_e2e';
const electricRollingStockName = 'electric_rolling_stock_test_e2e';

test.beforeAll(async () => {
rollingStock = await getRollingStock();
rollingStock = await getRollingStock(electricRollingStockName);

// Create a new scenario
({ project, study, scenario } = await setupScenario());
Expand Down
6 changes: 3 additions & 3 deletions front/tests/008-train-schedule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ test.describe('Verifying that all elements in the train schedule are loaded corr
await opTimetablePage.verifyTrainCount(20);
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Invalid', 4);
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'All', 20);
await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'Honored', 13);
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Valid', 13);
await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'Not honored', 3);
await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'Honored', 12);
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Valid', 12);
await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'Not honored', 4);
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'Invalid', 0);
await opTimetablePage.filterHonoredAndVerifyTrainCount(selectedLanguage, 'All', 4);
await opTimetablePage.filterValidityAndVerifyTrainCount(selectedLanguage, 'All', 20);
Expand Down
13 changes: 10 additions & 3 deletions front/tests/009-rollingstock-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const rollingstockDetailsPath = path.resolve(
);

const rollingstockDetails = readJsonFile(rollingstockDetailsPath);
const dualModeRollingStockName = 'dual-mode_rollingstock_test_e2e';
const electricRollingStockName = 'rollingstock_1500_25000_test_e2e';
const dualModeRollingStockName = 'dual-mode_rolling_stock_test_e2e';
const electricRollingStockName = 'electric_rolling_stock_test_e2e';

test.describe('Rollingstock editor page', () => {
let uniqueRollingStockName: string;
Expand Down Expand Up @@ -176,7 +176,7 @@ test.describe('Rollingstock editor page', () => {
});
test('should correctly duplicate and delete a rolling stock', async ({ page }) => {
const rollingStockEditorPage = new RollingstockEditorPage(page);

const rollingStockSelectorPage = new RollingStockSelectorPage(page);
await rollingStockEditorPage.navigateToPage();

// Select the rolling stock from global-setup
Expand All @@ -196,6 +196,13 @@ test.describe('Rollingstock editor page', () => {
await expect(
rollingStockEditorPage.page.getByTestId(uniqueDeletedRollingStockName)
).toBeHidden();

// Search for the deleted rolling stock
await rollingStockEditorPage.searchRollingStock(uniqueDeletedRollingStockName);

// Verify that the count of rolling stock is 0 (No results Found)
await expect(rollingStockSelectorPage.getNoRollingStockResult).toBeVisible();
expect(await rollingStockSelectorPage.getRollingStockSearchNumber()).toEqual(0);
});
test('should correctly filter a rolling stock', async ({ page }) => {
const rollingStockEditorPage = new RollingstockEditorPage(page);
Expand Down
2 changes: 1 addition & 1 deletion front/tests/010-op-route-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let study: Study;
let scenario: Scenario;
let selectedLanguage: string;

const electricRollingStockName = 'rollingstock_1500_25000_test_e2e';
const electricRollingStockName = 'electric_rolling_stock_test_e2e';

test.beforeAll(async () => {
// Create a new scenario
Expand Down
31 changes: 16 additions & 15 deletions front/tests/011-op-times-and-stops-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import OperationalStudiesTimetablePage from './pages/op-timetable-page-model';
import OperationalStudiesPage from './pages/operational-studies-page-model';
import ScenarioPage from './pages/scenario-page-model';
import { readJsonFile } from './utils';
import { cleanWhitespace, cleanWhitespaces, type StationData } from './utils/dataNormalizer';
import { cleanWhitespace, cleanWhitespaceInArray, type StationData } from './utils/dataNormalizer';
import setupScenario from './utils/scenario';
import scrollContainer from './utils/scrollHelper';
import enTranslations from '../public/locales/en/timesStops.json';
Expand All @@ -20,7 +20,17 @@ let study: Study;
let scenario: Scenario;
let selectedLanguage: string;

const dualRollingStockName = 'dual-mode_rollingstock_test_e2e';
type TranslationKeys = keyof typeof enTranslations;

// Define CellData interface for table cell data
interface CellData {
stationName: string;
header: TranslationKeys;
value: string;
marginForm?: string;
}

const dualRollingStockName = 'dual-mode_rolling_stock_test_e2e';

const initialInputsData: CellData[] = readJsonFile(
'./tests/assets/operationStudies/timesAndStops/initialInputs.json'
Expand All @@ -43,16 +53,6 @@ const expectedViaValues = [
{ name: 'Mid_East_station', ch: 'BV', uic: '4', km: 'KM 26.300' },
];

type TranslationKeys = keyof typeof enTranslations;

// Define CellData interface for table cell data
interface CellData {
stationName: string;
header: TranslationKeys;
value: string;
marginForm?: string;
}

test.beforeEach(async ({ page }) => {
// Create a new scenario
({ project, study, scenario } = await setupScenario());
Expand Down Expand Up @@ -106,7 +106,7 @@ test.describe('Times and Stops Tab Verification', () => {

// Set column names based on the selected language
const translations = selectedLanguage === 'English' ? enTranslations : frTranslations;
const expectedColumnNames = cleanWhitespaces([
const expectedColumnNames = cleanWhitespaceInArray([
translations.name,
'Ch',
translations.arrivalTime,
Expand All @@ -117,7 +117,7 @@ test.describe('Times and Stops Tab Verification', () => {
]);

// Verify that the actual column headers match the expected headers
const actualColumnHeaders = cleanWhitespaces(
const actualColumnHeaders = cleanWhitespaceInArray(
await opInputTablePage.columnHeaders.allInnerTexts()
);
expect(actualColumnHeaders).toEqual(expectedColumnNames);
Expand Down Expand Up @@ -157,7 +157,8 @@ test.describe('Times and Stops Tab Verification', () => {
// Add the train schedule and verify simulation results
await scenarioPage.addTrainSchedule();
await scenarioPage.returnSimulationResult();
opTimetablePage.verifyTimeStopsDatasheetVisibility();
await opTimetablePage.clickOnScenarioCollapseButton();
await opTimetablePage.verifyTimeStopsDataSheetVisibility();
// Scroll and extract data from output table
await scrollContainer(page, '.osrd-simulation-container .time-stops-datasheet .dsg-container');
await opOutputTablePage.getOutputTableData(outputExpectedCellData, selectedLanguage);
Expand Down
Loading

0 comments on commit 093d78f

Please sign in to comment.