Skip to content

Commit 2589d39

Browse files
committed
front: adapt e2e tests to use tsv2
- e2e tests are now using tsv2 model - remove allowances e2e tests as they are deprecated - rolling stock comfort type properly uses tsv2 model
1 parent 390f484 commit 2589d39

15 files changed

+74
-77
lines changed

front/src/modules/rollingStock/components/RollingStockCard/RollingStockCardButtons.tsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useContext, useEffect, useMemo, useState } from 'react';
33
import { useTranslation } from 'react-i18next';
44
import { useSelector } from 'react-redux';
55

6-
import type { TrainScheduleBase } from 'common/api/osrdEditoastApi';
6+
import type { Comfort } from 'common/api/osrdEditoastApi';
77
import { ModalContext } from 'common/BootstrapSNCF/ModalSNCF/ModalProvider';
88
import OptionsSNCF from 'common/BootstrapSNCF/OptionsSNCF';
99
import type { Option } from 'common/BootstrapSNCF/OptionsSNCF';
@@ -35,11 +35,7 @@ const RollingStockCardButtons = ({
3535
const selectRollingStock = () => {
3636
setOpenedRollingStockCardId(undefined);
3737
dispatch(updateRollingStockID(id));
38-
dispatch(
39-
updateRollingStockComfortV2(
40-
comfort !== 'AC' ? (comfort as TrainScheduleBase['comfort']) : 'AIR_CONDITIONING'
41-
)
42-
);
38+
dispatch(updateRollingStockComfortV2(comfort as Comfort));
4339
closeModal();
4440
};
4541

@@ -63,7 +59,7 @@ const RollingStockCardButtons = ({
6359
value: 'AC',
6460
label: (
6561
<span data-testid="comfort-ac-button" className="rollingstock-footer-button-with-picto">
66-
{comfort2pictogram('AC')} {t('comfortTypes.AC')}
62+
{comfort2pictogram('AIR_CONDITIONING')} {t('comfortTypes.AC')}
6763
</span>
6864
),
6965
});

front/src/modules/rollingStock/components/RollingStockCurve.tsx

+23-12
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ function LegendComfortSwitches(props: {
5050
}) {
5151
const { curvesComfortList, comfortsStates, onComfortsStatesChange } = props;
5252

53-
return curvesComfortList.length > 1 ? (
53+
// TODO: remove this condition when getRollingStock endpoint returns comfort
54+
// with type Comfort instead of RollingStockComfortType */
55+
const curvesComfortListV2 = curvesComfortList.map((comfort) =>
56+
comfort === 'AC' ? 'AIR_CONDITIONING' : comfort
57+
);
58+
59+
return curvesComfortListV2.length > 1 ? (
5460
<span className="d-flex">
55-
{curvesComfortList.map((comfort) => (
61+
{curvesComfortListV2.map((comfort) => (
5662
<span
5763
className={cx('curves-chart-legend-comfort-button', {
5864
active: comfortsStates[comfort],
@@ -68,7 +74,7 @@ function LegendComfortSwitches(props: {
6874
</span>
6975
) : (
7076
<span className="curves-chart-legend-comfort-button active">
71-
{comfort2pictogram(curvesComfortList[0])}
77+
{comfort2pictogram(curvesComfortListV2[0])}
7278
</span>
7379
);
7480
}
@@ -102,9 +108,11 @@ function Legend(props: {
102108
{isOnEditionMode && showPowerRestriction && curve.power_restriction}
103109
{isOnEditionMode && !showPowerRestriction && curve.electrical_profile_level}
104110
{!isOnEditionMode && !showPowerRestriction && curve.mode}
111+
{/* TODO: remove this condition when getRollingStock endpoint returns comfort
112+
with type Comfort instead of RollingStockComfortType */}
105113
{curve.comfort !== STANDARD_COMFORT_LEVEL &&
106114
!isOnEditionMode &&
107-
comfort2pictogram(curve.comfort)}
115+
comfort2pictogram(curve.comfort === 'AC' ? 'AIR_CONDITIONING' : curve.comfort)}
108116
</span>
109117
))}
110118
</span>
@@ -216,13 +224,14 @@ export default function RollingStockCurve({
216224
const [curvesVisibility, setCurvesVisibility] = useState(setupCurvesVisibility(transformedData));
217225

218226
const formatTooltip = (tooltip: PointTooltipProps) => {
227+
const transformedCurve = transformedData[tooltip.point.serieId];
219228
const editionModeTooltipLabel =
220229
isOnEditionMode && showPowerRestriction
221-
? geti18nKeyForNull(transformedData[tooltip.point.serieId]?.powerRestriction)
222-
: geti18nKeyForNull(transformedData[tooltip.point.serieId]?.electricalProfile);
230+
? geti18nKeyForNull(transformedCurve?.powerRestriction)
231+
: geti18nKeyForNull(transformedCurve?.electricalProfile);
223232
return (
224233
<div className="curves-chart-tooltip" style={{ borderColor: tooltip.point.color }}>
225-
{transformedData[tooltip.point.serieId] && (
234+
{transformedCurve && (
226235
<div
227236
className="curves-chart-tooltip-head"
228237
style={{
@@ -231,13 +240,15 @@ export default function RollingStockCurve({
231240
borderColor: tooltip.point.color,
232241
}}
233242
>
234-
{isOnEditionMode
235-
? editionModeTooltipLabel
236-
: transformedData[tooltip.point.serieId].mode}
243+
{isOnEditionMode ? editionModeTooltipLabel : transformedCurve.mode}
237244
<span className="ml-1" />
238-
{transformedData[tooltip.point.serieId].comfort !== STANDARD_COMFORT_LEVEL && (
245+
{transformedCurve.comfort !== STANDARD_COMFORT_LEVEL && (
239246
<span className="curves-chart-tooltip-comfort">
240-
{comfort2pictogram(transformedData[tooltip.point.serieId].comfort)}
247+
{/* TODO: remove this condition when getRollingStock endpoint returns comfort
248+
with type Comfort instead of RollingStockComfortType */}
249+
{comfort2pictogram(
250+
transformedCurve.comfort === 'AC' ? 'AIR_CONDITIONING' : transformedCurve.comfort
251+
)}
241252
</span>
242253
)}
243254
</div>

front/src/modules/rollingStock/components/RollingStockSelector/RollingStockHelpers.tsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { BiLockAlt } from 'react-icons/bi';
44
import { ImFire } from 'react-icons/im';
55
import { IoIosSnow } from 'react-icons/io';
66

7-
import type {
8-
LightRollingStock,
9-
RollingStockComfortType,
10-
RollingStock,
11-
} from 'common/api/osrdEditoastApi';
7+
import type { LightRollingStock, RollingStock, Comfort } from 'common/api/osrdEditoastApi';
128

139
const RollingStockUnit = ({ unit, detail }: { unit: string; detail: string }) => {
1410
if (unit && unit !== 'US') {
@@ -73,9 +69,9 @@ export const RollingStockInfo = ({
7369
);
7470
};
7571

76-
export function comfort2pictogram(comfort: RollingStockComfortType | undefined) {
72+
export function comfort2pictogram(comfort: Comfort | undefined) {
7773
switch (comfort) {
78-
case 'AC':
74+
case 'AIR_CONDITIONING':
7975
return (
8076
<span className="comfort-AC">
8177
<IoIosSnow />

front/src/modules/rollingStock/components/RollingStockSelector/RollingStockSelector.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useRef } from 'react';
33
import { useTranslation } from 'react-i18next';
44

55
import icon from 'assets/pictures/components/train.svg';
6-
import type { RollingStockComfortType, RollingStockWithLiveries } from 'common/api/osrdEditoastApi';
6+
import type { Comfort, RollingStockWithLiveries } from 'common/api/osrdEditoastApi';
77
import { useModal } from 'common/BootstrapSNCF/ModalSNCF';
88
import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img';
99
import {
@@ -15,7 +15,7 @@ import RollingStockModal from 'modules/rollingStock/components/RollingStockSelec
1515
type RollingStockProps = {
1616
condensed?: boolean;
1717
rollingStockSelected?: RollingStockWithLiveries;
18-
rollingStockComfort: RollingStockComfortType;
18+
rollingStockComfort: Comfort;
1919
image?: JSX.Element;
2020
};
2121

front/src/modules/rollingStock/components/RollingStockSelector/useStoreDataForRollingStockSelector.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
44
import { useOsrdConfSelectors } from 'common/osrdContext';
55

66
export const useStoreDataForRollingStockSelector = () => {
7-
const { getRollingStockID, getRollingStockComfort } = useOsrdConfSelectors();
7+
const { getRollingStockID, getRollingStockComfortV2 } = useOsrdConfSelectors();
88
const rollingStockId = useSelector(getRollingStockID);
9-
const rollingStockComfort = useSelector(getRollingStockComfort);
9+
const rollingStockComfort = useSelector(getRollingStockComfortV2);
1010

1111
const { data: rollingStock } = osrdEditoastApi.endpoints.getRollingStockByRollingStockId.useQuery(
1212
{

front/src/reducers/osrdconf/osrdConfCommon/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const defaultCommonConf: OsrdConfState = {
6161
featureInfoClick: { displayPopup: false },
6262
// Corresponds to origin and destination not defined
6363
pathSteps: [null, null],
64-
rollingStockComfortV2: 'STANDARD',
64+
rollingStockComfortV2: 'STANDARD' as const,
6565
startTime: new Date().toISOString(),
6666
};
6767

front/src/reducers/osrdconf/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import type {
66
RollingStockComfortType,
77
PathResponse,
88
AllowanceValue,
9-
TrainScheduleBase,
109
Distribution,
1110
PathfindingInputV2,
11+
Comfort,
1212
} from 'common/api/osrdEditoastApi';
1313
import type { AllowanceForm } from 'modules/trainschedule/components/ManageTrainSchedule/Allowances/types';
1414
import type { InfraState } from 'reducers/infra';
@@ -54,7 +54,7 @@ export interface OsrdConfState extends InfraState {
5454
trainScheduleIDsToModify: number[];
5555
featureInfoClick: { displayPopup: boolean; feature?: Feature; coordinates?: number[] };
5656
pathSteps: (PathStep | null)[];
57-
rollingStockComfortV2?: TrainScheduleBase['comfort'];
57+
rollingStockComfortV2: Comfort;
5858
// Format ISO 8601
5959
startTime: string;
6060
}

front/tests/004-scenario-management.spec.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, expect } from '@playwright/test';
22
import { v4 as uuidv4 } from 'uuid';
33

4-
import type { Infra, Project, Scenario, Study } from 'common/api/osrdEditoastApi';
4+
import type { Infra, Project, Scenario, Study, Timetable } from 'common/api/osrdEditoastApi';
55

66
import scenarioData from './assets/operationStudies/scenario.json';
77
import CommonPage from './pages/common-page-model';
@@ -13,6 +13,7 @@ let smallInfra: Infra;
1313
let project: Project;
1414
let study: Study;
1515
let scenario: Scenario;
16+
let timetable: Timetable;
1617

1718
test.beforeAll(async () => {
1819
smallInfra = (await getInfra()) as Infra;
@@ -21,11 +22,15 @@ test.beforeAll(async () => {
2122
});
2223

2324
test.beforeEach(async () => {
24-
scenario = await postApiRequest(`/api/projects/${project.id}/studies/${study.id}/scenarios`, {
25+
timetable = await postApiRequest(`/api/v2/timetable/`, {
26+
electrical_profile_set_id: null,
27+
});
28+
scenario = await postApiRequest(`/api/v2/projects/${project.id}/studies/${study.id}/scenarios`, {
2529
...scenarioData,
2630
name: `${scenarioData.name} ${uuidv4()}`,
2731
study_id: study.id,
2832
infra_id: smallInfra.id,
33+
timetable_id: timetable.id,
2934
});
3035
});
3136

front/tests/005-operational-studies.spec.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { test, expect } from '@playwright/test';
22
import { v4 as uuidv4 } from 'uuid';
33

4-
import type { Infra, Project, RollingStock, Scenario, Study } from 'common/api/osrdEditoastApi';
4+
import type {
5+
Infra,
6+
Project,
7+
RollingStock,
8+
Scenario,
9+
Study,
10+
Timetable,
11+
} from 'common/api/osrdEditoastApi';
512

613
import scenarioData from './assets/operationStudies/scenario.json';
714
import HomePage from './pages/home-page-model';
@@ -14,6 +21,7 @@ let project: Project;
1421
let study: Study;
1522
let scenario: Scenario;
1623
let rollingStock: RollingStock;
24+
let timetable: Timetable;
1725

1826
test.beforeAll(async () => {
1927
smallInfra = (await getInfra()) as Infra;
@@ -23,11 +31,15 @@ test.beforeAll(async () => {
2331
});
2432

2533
test.beforeEach(async () => {
26-
scenario = await postApiRequest(`/api/projects/${project.id}/studies/${study.id}/scenarios`, {
34+
timetable = await postApiRequest(`/api/v2/timetable/`, {
35+
electrical_profile_set_id: null,
36+
});
37+
scenario = await postApiRequest(`/api/v2/projects/${project.id}/studies/${study.id}/scenarios`, {
2738
...scenarioData,
2839
name: `${scenarioData.name} ${uuidv4()}`,
2940
study_id: study.id,
3041
infra_id: smallInfra.id,
42+
timetable_id: timetable.id,
3143
});
3244
});
3345

front/tests/006-stdcm-page.spec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const studyName = study.name;
1212
const scenarioName = scenario.name;
1313
const rollingStockName = 'rollingstock_1500_25000_test_e2e';
1414

15-
const rollingStockTranslation = manageTrainScheduleTranslation.rollingstock;
15+
const emptyRouteTranslation = manageTrainScheduleTranslation.pathfindingNoState;
1616

1717
test.describe('STDCM page', () => {
1818
test('should configure and launch a stdcm', async ({ page }) => {
@@ -33,17 +33,16 @@ test.describe('STDCM page', () => {
3333
await stdcmPage.selectMiniCard(studyName);
3434
await stdcmPage.selectMiniCard(scenarioName);
3535

36-
// Check no rollingstock is selected and "rollingstock" is in the missing information
37-
await expect(stdcmPage.missingParams).toContainText(rollingStockTranslation);
36+
// Check no route is selected
37+
await expect(stdcmPage.pathfindingNoState).toContainText(emptyRouteTranslation);
3838

3939
// Select a rolling stock
4040
await stdcmPage.openRollingstockModal();
4141
await expect(stdcmPage.rollingStockSelectorModal).toBeVisible();
4242
await stdcmPage.selectRollingStock(rollingStockName);
4343

44-
// Check that the rollingstock is selected and "rollingstock" is not in the missing information anymore
44+
// Check that the rollingstock is selected
4545
await expect(stdcmPage.rollingStockSelectorModal).not.toBeVisible();
46-
await expect(stdcmPage.missingParams).not.toContainText(rollingStockTranslation);
4746

4847
await stdcmPage.selectPathByTrigram('MWS', 'NES');
4948
await stdcmPage.checkPathfindingDistance('34.000 km');

front/tests/007-op-rollingstock-tab.spec.ts

-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
} from 'common/api/osrdEditoastApi';
1212

1313
import scenarioData from './assets/operationStudies/scenario.json';
14-
import HomePage from './pages/home-page-model';
1514
import OperationalStudiesPage from './pages/operational-studies-page-model';
1615
import RollingStockSelectorPage from './pages/rollingstock-selector-page';
1716
import ScenarioPage from './pages/scenario-page-model';
@@ -52,10 +51,6 @@ test.describe('Verifying that all elements in the rolling stock tab are loaded c
5251
const scenarioPage = new ScenarioPage(page);
5352
const rollingStockSelector = new RollingStockSelectorPage(page);
5453

55-
// TODO: DROP TSV1: remove this part
56-
const homePage = new HomePage(page);
57-
await homePage.goToHomePage();
58-
5954
// Navigate to the created scenario page
6055
await page.goto(
6156
`/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}`

front/tests/008-allowances.spec.ts

-26
This file was deleted.

front/tests/global-setup.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs';
22

33
import { test as setup } from '@playwright/test';
4+
import { v4 as uuidv4 } from 'uuid';
45

56
import type {
67
Infra,
@@ -60,9 +61,16 @@ async function createDataForTests() {
6061
budget: 1234567890,
6162
} as StudyCreateForm);
6263

63-
await postApiRequest(`/api/projects/${project.id}/studies/${study.id}/scenarios`, {
64+
const timetable = await postApiRequest(`/api/v2/timetable/`, {
65+
electrical_profile_set_id: null,
66+
});
67+
68+
await postApiRequest(`/api/v2/projects/${project.id}/studies/${study.id}/scenarios`, {
6469
...scenarioData,
70+
name: `${scenarioData.name} ${uuidv4()}`,
71+
study_id: study.id,
6572
infra_id: smallInfra.id,
73+
timetable_id: timetable.id,
6674
});
6775
}
6876

front/tests/pages/stdcm-page-model.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, type Locator, type Page } from '@playwright/test';
33
import SimulationConfPage from './simulation-conf-page';
44

55
class StdcmPage extends SimulationConfPage {
6-
readonly missingParams: Locator;
6+
readonly pathfindingNoState: Locator;
77

88
// Scenario Explorator
99
private scenarioExplorerButton: Locator;
@@ -18,7 +18,7 @@ class StdcmPage extends SimulationConfPage {
1818
constructor(page: Page) {
1919
super(page);
2020

21-
this.missingParams = page.locator('.missing-params');
21+
this.pathfindingNoState = page.getByTestId('pathfinding-no-state');
2222

2323
// Scenario Explorator
2424
this.scenarioExplorerButton = page.getByTestId('scenario-explorator');

0 commit comments

Comments
 (0)