-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy path011-op-times-and-stops-tab.spec.ts
236 lines (206 loc) · 8.96 KB
/
011-op-times-and-stops-tab.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import { test, expect } from '@playwright/test';
import type { Project, Scenario, Study } from 'common/api/osrdEditoastApi';
import HomePage from './pages/home-page-model';
import OperationalStudiesInputTablePage from './pages/op-input-table-page-model';
import OperationalStudiesOutputTablePage from './pages/op-output-table-page-model';
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, cleanWhitespaceInArray, type StationData } from './utils/dataNormalizer';
import setupScenario from './utils/scenario';
import scrollContainer from './utils/scrollHelper';
import enTranslations from '../public/locales/en/timesStops.json';
import frTranslations from '../public/locales/fr/timesStops.json';
let project: Project;
let study: Study;
let scenario: Scenario;
let selectedLanguage: string;
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'
);
const updatedInputsData: CellData[] = readJsonFile(
'./tests/assets/operationStudies/timesAndStops/updatedInputs.json'
);
const outputExpectedCellData: StationData[] = readJsonFile(
'./tests/assets/operationStudies/timesAndStops/expectedOutputsCellsData.json'
);
const inputExpectedData = readJsonFile(
'./tests/assets/operationStudies/timesAndStops/expectedInputsCellsData.json'
);
const updatedCellData = readJsonFile(
'./tests/assets/operationStudies/timesAndStops/updatedInputsCellsData.json'
);
const expectedViaValues = [
{ name: 'Mid_West_station', ch: 'BV', uic: '3', km: 'KM 11.850' },
{ name: 'Mid_East_station', ch: 'BV', uic: '4', km: 'KM 26.300' },
];
test.beforeEach(async ({ page }) => {
// Create a new scenario
({ project, study, scenario } = await setupScenario());
// Navigate to home page and retrieve the language setting
const homePage = new HomePage(page);
await homePage.goToHomePage();
selectedLanguage = await homePage.getOSRDLanguage();
// Go to the specific operational study scenario page
await page.goto(
`/operational-studies/projects/${project.id}/studies/${study.id}/scenarios/${scenario.id}`
);
});
test.describe('Times and Stops Tab Verification', () => {
// Set viewport to avoid scrolling issues and ensure elements are attached to the DOM
test.use({ viewport: { width: 1920, height: 1080 } });
test('should correctly set and display times and stops tables', async ({ page }) => {
// Page models
const [
opInputTablePage,
opTimetablePage,
opOutputTablePage,
operationalStudiesPage,
scenarioPage,
] = [
new OperationalStudiesInputTablePage(page),
new OperationalStudiesTimetablePage(page),
new OperationalStudiesOutputTablePage(page),
new OperationalStudiesPage(page),
new ScenarioPage(page),
];
// Setup the initial train configuration and schedule
await scenarioPage.checkInfraLoaded();
await operationalStudiesPage.clickOnAddTrainBtn();
await scenarioPage.setTrainScheduleName('Train-name-e2e-test');
await page.waitForTimeout(500);
await operationalStudiesPage.setTrainStartTime('11:22:40');
await operationalStudiesPage.selectRollingStock(dualRollingStockName);
// Perform pathfinding
await scenarioPage.openTabByDataId('tab-pathfinding');
await operationalStudiesPage.performPathfindingByTrigram('WS', 'NES');
// Navigate to the Times and Stops tab and scroll into view
await scenarioPage.openTabByDataId('tab-timesStops');
await scrollContainer(page, '.time-stops-datasheet .dsg-container');
// Set column names based on the selected language
const translations = selectedLanguage === 'English' ? enTranslations : frTranslations;
const expectedColumnNames = cleanWhitespaceInArray([
translations.name,
translations.ch,
translations.arrivalTime,
translations.stopTime,
translations.departureTime,
translations.receptionOnClosedSignal,
translations.shortSlipDistance,
translations.theoreticalMargin,
]);
// Verify that the actual column headers match the expected headers
const actualColumnHeaders = cleanWhitespaceInArray(
await opInputTablePage.columnHeaders.allInnerTexts()
);
expect(actualColumnHeaders).toEqual(expectedColumnNames);
// Validate the initial active row count
await opInputTablePage.verifyActiveRowsCount(2);
// Fill in table cells based on the predefined cell data
for (const cell of initialInputsData) {
const translatedHeader = cleanWhitespace(translations[cell.header]);
await opInputTablePage.fillTableCellByStationAndHeader(
cell.stationName,
translatedHeader,
cell.value,
selectedLanguage,
cell.marginForm
);
}
// Verify the table after modification
await opInputTablePage.verifyActiveRowsCount(4);
await opInputTablePage.verifyDeleteButtons(2);
await opInputTablePage.verifyInputTableData(inputExpectedData);
// Switch to Pathfinding tab and validate waypoints
await scenarioPage.openTabByDataId('tab-pathfinding');
for (const [viaIndex, expectedValue] of expectedViaValues.entries()) {
const droppedWaypoint = operationalStudiesPage.droppedWaypoints.nth(viaIndex);
await OperationalStudiesPage.validateAddedWaypoint(
droppedWaypoint,
expectedValue.name,
expectedValue.ch,
expectedValue.uic
);
}
// Add the train schedule and verify simulation results
await scenarioPage.addTrainSchedule();
await scenarioPage.returnSimulationResult();
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);
});
test('should correctly update and clear input table row', async ({ page }) => {
// Page models
const [opInputTablePage, operationalStudiesPage, scenarioPage] = [
new OperationalStudiesInputTablePage(page),
new OperationalStudiesPage(page),
new ScenarioPage(page),
];
// Setup initial train configuration
await scenarioPage.checkInfraLoaded();
await operationalStudiesPage.clickOnAddTrainBtn();
await scenarioPage.setTrainScheduleName('Train-name-e2e-test');
await page.waitForTimeout(500);
await operationalStudiesPage.setTrainStartTime('11:22:40');
await operationalStudiesPage.selectRollingStock(dualRollingStockName);
// Perform pathfinding and navigate to Times and Stops tab
await scenarioPage.openTabByDataId('tab-pathfinding');
await operationalStudiesPage.performPathfindingByTrigram('WS', 'NES');
await scenarioPage.openTabByDataId('tab-timesStops');
await scrollContainer(page, '.time-stops-datasheet .dsg-container');
const translations = selectedLanguage === 'English' ? enTranslations : frTranslations;
// Fill in table cells based on the predefined cell data
for (const cell of initialInputsData) {
const translatedHeader = cleanWhitespace(translations[cell.header]);
await opInputTablePage.fillTableCellByStationAndHeader(
cell.stationName,
translatedHeader,
cell.value,
selectedLanguage,
cell.marginForm
);
}
await opInputTablePage.verifyInputTableData(inputExpectedData);
// Update table inputs
await opInputTablePage.verifyActiveRowsCount(4);
for (const cell of updatedInputsData) {
const translatedHeader = cleanWhitespace(translations[cell.header]);
await opInputTablePage.fillTableCellByStationAndHeader(
cell.stationName,
translatedHeader,
cell.value,
selectedLanguage,
cell.marginForm
);
}
// Delete a row and validate row count
await opInputTablePage.verifyDeleteButtons(2);
await opInputTablePage.deleteButtons.nth(0).click();
await opInputTablePage.verifyActiveRowsCount(4);
await opInputTablePage.verifyDeleteButtons(1);
await opInputTablePage.verifyInputTableData(updatedCellData);
// Switch to Pathfinding tab and validate waypoints
await scenarioPage.openTabByDataId('tab-pathfinding');
for (const [viaIndex, expectedValue] of expectedViaValues.entries()) {
const droppedWaypoint = operationalStudiesPage.droppedWaypoints.nth(viaIndex);
await OperationalStudiesPage.validateAddedWaypoint(
droppedWaypoint,
expectedValue.name,
expectedValue.ch,
expectedValue.uic
);
}
});
});