Skip to content

Commit 48cb1ab

Browse files
committed
front: add e2e tests for paced train filter
Signed-off-by: SharglutDev <[email protected]>
1 parent 99469e8 commit 48cb1ab

File tree

9 files changed

+422
-69
lines changed

9 files changed

+422
-69
lines changed

front/public/locales/en/operationalStudies/scenario.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"advancedFilterLabel": "Rolling stock",
5454
"choosePath": "Use this path",
5555
"closeFilter": "Close filter",
56-
"compositionCodes": "Composition codes",
5756
"copy": "copy",
5857
"delete": "Delete",
5958
"deleteSelection": "Delete selected trains",
@@ -88,6 +87,7 @@
8887
"showInvalidTrains": "Invalid",
8988
"showNotHonoredTrains": "Partial",
9089
"showValidTrains": "Valid",
90+
"speedLimitTags": "Composition codes",
9191
"stopsCount_one": "1 stop",
9292
"stopsCount_other": "{{ count }} stops",
9393
"toggleFilters": "Toggle filters display",

front/public/locales/fr/operationalStudies/scenario.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"advancedFilterLabel": "Engin moteur",
5454
"choosePath": "Utiliser ce chemin",
5555
"closeFilter": "Fermer le filtre",
56-
"compositionCodes": "Codes de composition",
5756
"copy": "copie",
5857
"delete": "Supprimer",
5958
"deleteSelection": "Supprimer les trains sélectionnés",
@@ -88,6 +87,7 @@
8887
"showInvalidTrains": "Invalides",
8988
"showNotHonoredTrains": "Partielle",
9089
"showValidTrains": "Valides",
90+
"speedLimitTags": "Codes de composition",
9191
"stopsCount_one": "1 arrêt",
9292
"stopsCount_other": "{{count}} arrêts",
9393
"toggleFilters": "Afficher ou masquer les filtres",

front/src/modules/trainschedule/components/Timetable/FilterPanel.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const FilterPanel = ({ toggleFilterPanel, timetableFilters }: FilterPanelProps)
9494
<Select
9595
getOptionLabel={(option) => option.label}
9696
getOptionValue={(option) => option.value}
97-
id="train-validity"
97+
id="timetable-train-validity-filter"
9898
label={t('timetable.validityFilter')}
9999
narrow
100100
small
@@ -112,7 +112,7 @@ const FilterPanel = ({ toggleFilterPanel, timetableFilters }: FilterPanelProps)
112112
<Select
113113
getOptionLabel={(option) => option.label}
114114
getOptionValue={(option) => option.value}
115-
id="train-type"
115+
id="timetable-train-type-filter"
116116
label={t('timetable.trainType')}
117117
narrow
118118
small
@@ -146,7 +146,7 @@ const FilterPanel = ({ toggleFilterPanel, timetableFilters }: FilterPanelProps)
146146
<Select
147147
getOptionLabel={(option) => option.label}
148148
getOptionValue={(option) => option.value}
149-
id="train-keep-timetable"
149+
id="timetable-train-punctuality-filter"
150150
label={t('timetable.punctuality')}
151151
narrow
152152
small
@@ -164,9 +164,9 @@ const FilterPanel = ({ toggleFilterPanel, timetableFilters }: FilterPanelProps)
164164
/>
165165
</div>
166166
</div>
167-
<div className="compositions-code">
168-
<label htmlFor="composition-tag-filter">{t('timetable.compositionCodes')}</label>
169-
<div className="composition-tag-filter" id="composition-tag-filter">
167+
<div className="speed-limit-tag">
168+
<label htmlFor="timetable-speed-limit-tag-filter">{t('timetable.speedLimitTags')}</label>
169+
<div className="speed-limit-tag-filter" id="timetable-speed-limit-tag-filter">
170170
{uniqueTags.map((tag) => {
171171
const displayTag = tag !== 'NO CODE' ? tag : t('timetable.noSpeedLimitTagsShort');
172172
return (

front/src/modules/trainschedule/components/Timetable/Timetable.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,37 @@ const Timetable = ({
142142
{
143143
...trainSchedulesWithDetails[0],
144144
id: formatEditoastTrainIdToPacedTrainId(12345),
145+
trainName: 'Paced train 1',
146+
labels: ['Paced-Train-Tag-1'],
145147
paced: {
146148
duration: Duration.parse('PT2H'),
147149
step: Duration.parse('PT30M'),
148150
},
149151
},
152+
{
153+
...trainSchedulesWithDetails[0],
154+
id: formatEditoastTrainIdToPacedTrainId(123456),
155+
trainName: 'Paced train 2',
156+
invalidReason: 'rolling_stock_not_found',
157+
isValid: false,
158+
scheduledPointsNotHonored: false,
159+
paced: {
160+
duration: Duration.parse('PT1H'),
161+
step: Duration.parse('PT10M'),
162+
},
163+
},
164+
{
165+
...trainSchedulesWithDetails[0],
166+
id: formatEditoastTrainIdToPacedTrainId(1234567),
167+
trainName: 'Paced train 3',
168+
notHonoredReason: 'scheduleNotHonored',
169+
isValid: true,
170+
scheduledPointsNotHonored: true,
171+
paced: {
172+
duration: Duration.parse('PT2H'),
173+
step: Duration.parse('PT5M'),
174+
},
175+
},
150176
]
151177
: trainSchedulesWithDetails
152178
);

front/src/styles/scss/applications/operationalStudies/_scenario.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@
758758
}
759759
}
760760

761-
.compositions-code {
761+
.speed-limit-tag {
762762
padding-top: 13px;
763763

764764
label {
@@ -767,7 +767,7 @@
767767
font-weight: 600;
768768
margin-bottom: 4px;
769769
}
770-
.composition-tag-filter {
770+
.speed-limit-tag-filter {
771771
display: flex;
772772
flex-wrap: wrap;
773773
gap: 12px;

front/tests/008-train-schedule.spec.ts

Lines changed: 172 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,72 @@ import {
55
trainScheduleScenarioName,
66
trainScheduleStudyName,
77
} from './assets/constants/project-const';
8+
import {
9+
HONORED_ITEMS,
10+
HONORED_TRAINS,
11+
INVALID_AND_NOT_HONORED_TRAINS,
12+
INVALID_ITEMS,
13+
INVALID_TRAINS,
14+
ITEMS_WITH_NO_SPEED_LIMIT_TAG,
15+
LABEL_FILTERED_ITEMS,
16+
NAME_FILTERED_ITEMS,
17+
NOT_HONORED_ITEMS,
18+
NOT_HONORED_PACED_TRAINS,
19+
NOT_HONORED_TRAINS,
20+
ROLLING_STOCK_FILTERED_ITEMS,
21+
TOTAL_ITEMS,
22+
TOTAL_PACED_TRAINS,
23+
TOTAL_TRAINS,
24+
VALID_AND_HONORED_TRAINS,
25+
VALID_ITEMS,
26+
VALID_PACED_TRAINS,
27+
VALID_TRAINS,
28+
} from './assets/constants/timetable-items-count';
829
import test from './logging-fixture';
30+
import OperationalStudiesPage from './pages/operational-studies/operational-studies-page';
931
import ScenarioTimetableSection from './pages/operational-studies/scenario-timetable-section';
10-
import { waitForInfraStateToBeCached } from './utils';
32+
import { getTranslations, waitForInfraStateToBeCached } from './utils';
1133
import { getInfra, getProject, getScenario, getStudy } from './utils/api-utils';
34+
import readJsonFile from './utils/file-utils';
35+
import type { CommonTranslations, TimetableFilterTranslations } from './utils/types';
36+
37+
const enScenarioTranslations: TimetableFilterTranslations = readJsonFile(
38+
'public/locales/en/operationalStudies/scenario.json'
39+
);
40+
const frScenarioTranslations: TimetableFilterTranslations = readJsonFile(
41+
'public/locales/fr/operationalStudies/scenario.json'
42+
);
43+
44+
const enCommonTranslations: CommonTranslations = readJsonFile('public/locales/en/translation.json');
45+
const frCommonTranslations: CommonTranslations = readJsonFile('public/locales/fr/translation.json');
1246

1347
test.describe('Verify train schedule elements and filters', () => {
1448
test.slow();
1549
test.use({ viewport: { width: 1920, height: 1080 } });
1650

1751
let scenarioTimetableSection: ScenarioTimetableSection;
52+
let operationalStudiesPage: OperationalStudiesPage;
1853

1954
let project: Project;
2055
let study: Study;
2156
let scenario: Scenario;
2257
let infra: Infra;
23-
24-
// Constants for expected train counts
25-
const TOTAL_TRAINS = 21;
26-
const VALID_TRAINS = 17;
27-
const INVALID_TRAINS = 4;
28-
const HONORED_TRAINS = 14;
29-
const NOT_HONORED_TRAINS = 3;
30-
const VALID_AND_HONORED_TRAINS = 14;
31-
const INVALID_AND_NOT_HONORED_TRAINS = 0;
58+
let translations: TimetableFilterTranslations & CommonTranslations;
3259

3360
test.beforeAll('Fetch project, study and scenario with train schedule', async () => {
3461
project = await getProject(trainScheduleProjectName);
3562
study = await getStudy(project.id, trainScheduleStudyName);
3663
scenario = await getScenario(project.id, study.id, trainScheduleScenarioName);
3764
infra = await getInfra();
65+
translations = getTranslations({
66+
en: { ...enScenarioTranslations, ...enCommonTranslations },
67+
fr: { ...frScenarioTranslations, ...frCommonTranslations },
68+
});
3869
});
3970

4071
test.beforeEach('Navigate to scenario page before each test', async ({ page }) => {
4172
scenarioTimetableSection = new ScenarioTimetableSection(page);
73+
operationalStudiesPage = new OperationalStudiesPage(page);
4274
await page.goto(
4375
`/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}`
4476
);
@@ -52,31 +84,59 @@ test.describe('Verify train schedule elements and filters', () => {
5284
await scenarioTimetableSection.verifyTrainCount(TOTAL_TRAINS);
5385
await scenarioTimetableSection.verifyInvalidTrainsMessageVisibility();
5486
await scenarioTimetableSection.checkSelectedTimetableTrain();
55-
await scenarioTimetableSection.filterValidityAndVerifyTrainCount('Valid', VALID_TRAINS);
87+
await scenarioTimetableSection.filterValidityAndVerifyTrainCount(
88+
'Valid',
89+
VALID_TRAINS,
90+
translations
91+
);
5692
await scenarioTimetableSection.verifyEachTrainSimulation();
5793
});
5894

95+
// TODO Paced train - remove this test in https://github.com/OpenRailAssociation/osrd/issues/10791
5996
/** *************** Test 2 **************** */
6097
test('Filtering imported trains', async () => {
6198
// Verify train count and apply different filters for validity and honored status
6299
await scenarioTimetableSection.verifyTrainCount(TOTAL_TRAINS);
63-
await scenarioTimetableSection.filterValidityAndVerifyTrainCount('Invalid', INVALID_TRAINS);
64-
await scenarioTimetableSection.filterValidityAndVerifyTrainCount('All', TOTAL_TRAINS);
65-
await scenarioTimetableSection.filterHonoredAndVerifyTrainCount('Honored', HONORED_TRAINS);
100+
await scenarioTimetableSection.filterValidityAndVerifyTrainCount(
101+
'Invalid',
102+
INVALID_TRAINS,
103+
translations
104+
);
105+
await scenarioTimetableSection.filterValidityAndVerifyTrainCount(
106+
'All',
107+
TOTAL_TRAINS,
108+
translations
109+
);
110+
await scenarioTimetableSection.filterHonoredAndVerifyTrainCount(
111+
'Honored',
112+
HONORED_TRAINS,
113+
translations
114+
);
66115
await scenarioTimetableSection.filterValidityAndVerifyTrainCount(
67116
'Valid',
68-
VALID_AND_HONORED_TRAINS
117+
VALID_AND_HONORED_TRAINS,
118+
translations
69119
);
70120
await scenarioTimetableSection.filterHonoredAndVerifyTrainCount(
71121
'Not honored',
72-
NOT_HONORED_TRAINS
122+
NOT_HONORED_TRAINS,
123+
translations
73124
);
74125
await scenarioTimetableSection.filterValidityAndVerifyTrainCount(
75126
'Invalid',
76-
INVALID_AND_NOT_HONORED_TRAINS
127+
INVALID_AND_NOT_HONORED_TRAINS,
128+
translations
129+
);
130+
await scenarioTimetableSection.filterHonoredAndVerifyTrainCount(
131+
'All',
132+
INVALID_TRAINS,
133+
translations
134+
);
135+
await scenarioTimetableSection.filterValidityAndVerifyTrainCount(
136+
'All',
137+
TOTAL_TRAINS,
138+
translations
77139
);
78-
await scenarioTimetableSection.filterHonoredAndVerifyTrainCount('All', INVALID_TRAINS);
79-
await scenarioTimetableSection.filterValidityAndVerifyTrainCount('All', TOTAL_TRAINS);
80140

81141
// Verify train composition filters with predefined filter codes and expected counts
82142
const compositionFilters = [
@@ -87,7 +147,99 @@ test.describe('Verify train schedule elements and filters', () => {
87147
];
88148

89149
for (const filter of compositionFilters) {
90-
await scenarioTimetableSection.clickCodeCompoTrainFilterButton(filter.code, filter.count);
150+
await scenarioTimetableSection.filterSpeedLimitTagAndVerifyTrainCount(
151+
filter.code,
152+
filter.count,
153+
translations
154+
);
91155
}
156+
await scenarioTimetableSection.verifyTrainCount(TOTAL_TRAINS);
157+
});
158+
159+
// TODO Paced train : update this test with real data in https://github.com/OpenRailAssociation/osrd/issues/10615
160+
/** *************** Test 3 **************** */
161+
test('Filtering imported trains and paced trains', async () => {
162+
await operationalStudiesPage.checkPacedTrainSwitch();
163+
164+
// While the back end for paced trains isn't ready, 3 paced trains are hardcoded and
165+
// added to the list of train schedules for testing purposes.
166+
// These 3 paced trains are copy of the first train schedule in the list (1 valid, 1 not invalid, 1 not honored).
167+
await scenarioTimetableSection.verifyTotalItemsLabel(translations, {
168+
totalPacedTrainCount: TOTAL_PACED_TRAINS,
169+
totalTrainScheduleCount: TOTAL_TRAINS,
170+
});
171+
172+
await scenarioTimetableSection.checkTimetableFilterVisibilityLabelDefaultValue(
173+
translations.timetable,
174+
{ inputDefaultValue: '', selectDefaultValue: 'both' }
175+
);
176+
177+
// Name and label filter
178+
await scenarioTimetableSection.filterNameAndVerifyTrainCount(
179+
'Paced Train 1',
180+
NAME_FILTERED_ITEMS
181+
);
182+
await scenarioTimetableSection.filterNameAndVerifyTrainCount(
183+
'Paced-Train-Tag-1',
184+
LABEL_FILTERED_ITEMS
185+
);
186+
187+
// Rolling stock name and details filter
188+
await scenarioTimetableSection.filterRollingStockAndVerifyTrainCount(
189+
'slow_rolling_stock',
190+
ROLLING_STOCK_FILTERED_ITEMS
191+
);
192+
193+
// Validity filter
194+
await scenarioTimetableSection.filterValidityAndVerifyTrainCount(
195+
'Invalid',
196+
INVALID_ITEMS,
197+
translations
198+
);
199+
await scenarioTimetableSection.filterValidityAndVerifyTrainCount(
200+
'Valid',
201+
VALID_ITEMS,
202+
translations
203+
);
204+
205+
// Punctuality filter
206+
await scenarioTimetableSection.filterHonoredAndVerifyTrainCount(
207+
'Honored',
208+
HONORED_ITEMS,
209+
translations
210+
);
211+
await scenarioTimetableSection.filterHonoredAndVerifyTrainCount(
212+
'Not honored',
213+
NOT_HONORED_ITEMS,
214+
translations
215+
);
216+
217+
// Train type filter
218+
await scenarioTimetableSection.filterTrainTypeAndVerifyTrainCount(
219+
'Service',
220+
NOT_HONORED_PACED_TRAINS
221+
);
222+
await scenarioTimetableSection.filterHonoredAndVerifyTrainCount(
223+
'All',
224+
VALID_PACED_TRAINS,
225+
translations
226+
);
227+
await scenarioTimetableSection.filterValidityAndVerifyTrainCount(
228+
'All',
229+
TOTAL_PACED_TRAINS,
230+
translations
231+
);
232+
233+
await scenarioTimetableSection.filterTrainTypeAndVerifyTrainCount('Unique train', TOTAL_TRAINS);
234+
await scenarioTimetableSection.filterTrainTypeAndVerifyTrainCount('All', TOTAL_ITEMS);
235+
236+
// Verify train composition filters with predefined filter codes and expected counts
237+
// TODO Paced train : add a paced train with a unique compo code in https://github.com/OpenRailAssociation/osrd/issues/10615
238+
await scenarioTimetableSection.filterSpeedLimitTagAndVerifyTrainCount(
239+
null,
240+
ITEMS_WITH_NO_SPEED_LIMIT_TAG,
241+
translations
242+
);
243+
await scenarioTimetableSection.verifyTrainCount(TOTAL_ITEMS);
92244
});
93245
});

0 commit comments

Comments
 (0)