1
1
import { expect , type Locator , type Page } from '@playwright/test' ;
2
2
3
3
import CommonPage from './common-page-model' ;
4
+ import {
5
+ DEFAULT_PACED_TRAIN_SETTINGS ,
6
+ PACED_TRAIN_SETTINGS_TEST ,
7
+ } from '../assets/operational-studies-const' ;
4
8
import readJsonFile from '../utils/file-utils' ;
9
+ import type { ManageTrainScheduleTranslations , PacedTrainSettings } from '../utils/types' ;
5
10
6
11
const manageTrainScheduleTranslation : { trainAdded : string } = readJsonFile (
7
12
'public/locales/fr/operationalStudies/manageTrainSchedule.json'
@@ -24,9 +29,29 @@ class OperationalStudiesPage extends CommonPage {
24
29
25
30
private readonly trainCountInput : Locator ;
26
31
27
- private readonly trainScheduleNameInput : Locator ;
32
+ private readonly operationStudiesSettings : Locator ;
28
33
29
- private readonly addTrainScheduleButton : Locator ;
34
+ private readonly userSettings : Locator ;
35
+
36
+ private readonly modalCloseButton : Locator ;
37
+
38
+ private readonly pacedTrainSwitch : Locator ;
39
+
40
+ private readonly definePacedTrainCheckbox : Locator ;
41
+
42
+ private readonly definePacedTrainCheckboxLabel : Locator ;
43
+
44
+ private readonly pacedTrainTimeRangeDurationInput : Locator ;
45
+
46
+ private readonly pacedTrainCadenceInput : Locator ;
47
+
48
+ private readonly trainNameInput : Locator ;
49
+
50
+ private readonly trainInitialSpeedInput : Locator ;
51
+
52
+ private readonly trainTagsInput : Locator ;
53
+
54
+ private readonly addTrainButton : Locator ;
30
55
31
56
private readonly trainTimetable : Locator ;
32
57
@@ -42,11 +67,21 @@ class OperationalStudiesPage extends CommonPage {
42
67
this . routeTab = page . getByTestId ( 'tab-pathfinding' ) ;
43
68
this . simulationSettingsTab = page . getByTestId ( 'tab-simulation-settings' ) ;
44
69
this . timesAndStopsTab = page . getByTestId ( 'tab-timesStops' ) ;
45
- this . startTimeField = page . locator ( '#trainSchedule-startTime ' ) ;
70
+ this . startTimeField = page . locator ( '#train-start-time ' ) ;
46
71
this . returnSimulationResultButton = page . getByTestId ( 'return-simulation-result' ) ;
47
72
this . trainCountInput = page . locator ( '#osrdconf-traincount' ) ;
48
- this . addTrainScheduleButton = page . getByTestId ( 'add-train-schedules' ) ;
49
- this . trainScheduleNameInput = page . locator ( '#trainSchedule-name' ) ;
73
+ this . operationStudiesSettings = page . getByTestId ( 'dropdown-sncf' ) ;
74
+ this . userSettings = page . getByTestId ( 'user-settings-btn' ) ;
75
+ this . modalCloseButton = page . getByTestId ( 'modal-close-button' ) ;
76
+ this . pacedTrainSwitch = page . getByTestId ( 'paced-train-switch' ) ;
77
+ this . definePacedTrainCheckbox = page . locator ( '#define-paced-train' ) ;
78
+ this . definePacedTrainCheckboxLabel = page . locator ( 'label[for="define-paced-train"]' ) ;
79
+ this . pacedTrainTimeRangeDurationInput = page . locator ( '#paced-train-time-range-duration' ) ;
80
+ this . pacedTrainCadenceInput = page . locator ( '#paced-train-cadence' ) ;
81
+ this . addTrainButton = page . getByTestId ( 'add-train' ) ;
82
+ this . trainNameInput = page . locator ( '#train-name' ) ;
83
+ this . trainInitialSpeedInput = page . locator ( '#train-initial-speed' ) ;
84
+ this . trainTagsInput = page . getByTestId ( 'chips-input' ) ;
50
85
51
86
this . trainTimetable = page
52
87
. locator ( '.scenario-timetable-trains' )
@@ -118,14 +153,117 @@ class OperationalStudiesPage extends CommonPage {
118
153
await this . trainCountInput . fill ( trainCount ) ;
119
154
}
120
155
156
+ // TODO Paced train : remove this (and all related locator and data-testid) in https://github.com/OpenRailAssociation/osrd/issues/10791
157
+ async checkPacedTrainSwitch ( ) {
158
+ await expect ( this . operationStudiesSettings ) . toBeVisible ( ) ;
159
+ await this . operationStudiesSettings . click ( ) ;
160
+
161
+ await expect ( this . userSettings ) . toBeVisible ( ) ;
162
+ await this . userSettings . click ( ) ;
163
+
164
+ await expect ( this . pacedTrainSwitch ) . toBeVisible ( ) ;
165
+ await expect ( this . pacedTrainSwitch ) . not . toBeChecked ( ) ;
166
+ await this . pacedTrainSwitch . click ( ) ;
167
+ await expect ( this . pacedTrainSwitch ) . toBeChecked ( ) ;
168
+
169
+ await this . modalCloseButton . click ( ) ;
170
+ }
171
+
172
+ async checkInputsAndButtons ( translations : ManageTrainScheduleTranslations , date : string ) {
173
+ await expect ( this . addTrainButton ) . toBeVisible ( ) ;
174
+ await expect ( this . addTrainButton ) . toHaveText ( translations . addTrainSchedule ) ;
175
+ await expect ( this . definePacedTrainCheckboxLabel ) . toBeVisible ( ) ;
176
+ await expect ( this . definePacedTrainCheckboxLabel ) . toHaveText (
177
+ translations . pacedTrains . defineService
178
+ ) ;
179
+ await expect ( this . definePacedTrainCheckbox ) . not . toBeChecked ( ) ;
180
+ await expect ( this . returnSimulationResultButton ) . toBeVisible ( ) ;
181
+ await expect ( this . trainNameInput ) . toBeVisible ( ) ;
182
+
183
+ await expect ( this . startTimeField ) . toBeVisible ( ) ;
184
+ const startTimeDate = new Date ( await this . startTimeField . inputValue ( ) ) ;
185
+ const scenarioCreationDate = new Date ( date ) ;
186
+ const isSameDate =
187
+ startTimeDate . getFullYear ( ) === scenarioCreationDate . getFullYear ( ) &&
188
+ startTimeDate . getMonth ( ) === scenarioCreationDate . getMonth ( ) &&
189
+ startTimeDate . getDate ( ) === scenarioCreationDate . getDate ( ) ;
190
+ expect ( isSameDate ) . toBe ( true ) ;
191
+
192
+ await expect ( this . trainInitialSpeedInput ) . toBeVisible ( ) ;
193
+ await expect ( this . trainInitialSpeedInput ) . toHaveValue ( '0' ) ;
194
+
195
+ await expect ( this . trainTagsInput ) . toBeVisible ( ) ;
196
+ }
197
+
198
+ async checkTabs ( ) {
199
+ await expect ( this . rollingStockTab ) . toBeVisible ( ) ;
200
+ await expect ( this . routeTab ) . toBeVisible ( ) ;
201
+ await expect ( this . timesAndStopsTab ) . toBeVisible ( ) ;
202
+ await expect ( this . simulationSettingsTab ) . toBeVisible ( ) ;
203
+
204
+ await expect ( this . rollingStockTab ) . toHaveClass ( / a c t i v e / ) ;
205
+ await this . verifyTabWarningPresence ( ) ;
206
+ }
207
+
208
+ async checkPacedTrainModeAndVerifyInputs ( translations : ManageTrainScheduleTranslations ) {
209
+ await this . definePacedTrainCheckboxLabel . click ( ) ;
210
+ await expect ( this . addTrainButton ) . toHaveText ( translations . addPacedTrain ) ;
211
+ await expect ( this . pacedTrainTimeRangeDurationInput ) . toBeVisible ( ) ;
212
+ await expect ( this . pacedTrainTimeRangeDurationInput ) . toHaveValue (
213
+ DEFAULT_PACED_TRAIN_SETTINGS . timeRangeDuration
214
+ ) ;
215
+ await expect ( this . pacedTrainCadenceInput ) . toBeVisible ( ) ;
216
+ await expect ( this . pacedTrainCadenceInput ) . toHaveValue ( DEFAULT_PACED_TRAIN_SETTINGS . cadence ) ;
217
+ }
218
+
219
+ async testPacedTrainMode ( translations : ManageTrainScheduleTranslations ) {
220
+ await this . setTimeRangeDuration ( PACED_TRAIN_SETTINGS_TEST . timeRangeDuration ) ;
221
+ await this . setCadence ( PACED_TRAIN_SETTINGS_TEST . cadence ) ;
222
+ await this . definePacedTrainCheckboxLabel . click ( ) ;
223
+ await expect ( this . addTrainButton ) . toHaveText ( translations . addTrainSchedule ) ;
224
+ await expect ( this . pacedTrainTimeRangeDurationInput ) . not . toBeVisible ( ) ;
225
+ await expect ( this . pacedTrainCadenceInput ) . not . toBeVisible ( ) ;
226
+
227
+ await this . definePacedTrainCheckboxLabel . click ( ) ;
228
+ await expect ( this . addTrainButton ) . toHaveText ( translations . addPacedTrain ) ;
229
+ await expect ( this . pacedTrainTimeRangeDurationInput ) . toBeVisible ( ) ;
230
+ await expect ( this . pacedTrainTimeRangeDurationInput ) . toHaveValue (
231
+ PACED_TRAIN_SETTINGS_TEST . timeRangeDuration
232
+ ) ;
233
+ await expect ( this . pacedTrainCadenceInput ) . toBeVisible ( ) ;
234
+ await expect ( this . pacedTrainCadenceInput ) . toHaveValue ( PACED_TRAIN_SETTINGS_TEST . cadence ) ;
235
+ }
236
+
237
+ async fillPacedTrainSettings ( {
238
+ name,
239
+ startTime,
240
+ timeRangeDuration,
241
+ cadence,
242
+ } : PacedTrainSettings ) {
243
+ await this . setTrainScheduleName ( name ) ;
244
+ await this . setTrainStartTime ( startTime ) ;
245
+ await this . setTimeRangeDuration ( timeRangeDuration ) ;
246
+ await this . setCadence ( cadence ) ;
247
+ }
248
+
249
+ async setTimeRangeDuration ( timeRangeDuration : string ) {
250
+ await this . pacedTrainTimeRangeDurationInput . fill ( timeRangeDuration ) ;
251
+ await expect ( this . pacedTrainTimeRangeDurationInput ) . toHaveValue ( timeRangeDuration ) ;
252
+ }
253
+
254
+ async setCadence ( cadence : string ) {
255
+ await this . pacedTrainCadenceInput . fill ( cadence ) ;
256
+ await expect ( this . pacedTrainCadenceInput ) . toHaveValue ( cadence ) ;
257
+ }
258
+
121
259
async addTrainSchedule ( ) {
122
- await this . addTrainScheduleButton . click ( ) ;
260
+ await this . addTrainButton . click ( ) ;
123
261
await this . closeToastNotification ( ) ;
124
262
}
125
263
126
264
async setTrainScheduleName ( name : string ) {
127
- await this . trainScheduleNameInput . fill ( name ) ;
128
- await expect ( this . trainScheduleNameInput ) . toHaveValue ( name ) ;
265
+ await this . trainNameInput . fill ( name ) ;
266
+ await expect ( this . trainNameInput ) . toHaveValue ( name ) ;
129
267
}
130
268
131
269
async checkNumberOfTrains ( number : number ) {
0 commit comments