Skip to content

Commit 92d65e8

Browse files
committed
fixup! Revert "front: revert: timetable performance"
1 parent 919997a commit 92d65e8

4 files changed

+65
-13
lines changed

front/tests/011-op-times-and-stops-tab.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getTranslations, readJsonFile, waitForInfraStateToBeCached } from './ut
1313
import { getInfra } from './utils/api-setup';
1414
import { cleanWhitespace, cleanWhitespaceInArray } from './utils/dataNormalizer';
1515
import createScenario from './utils/scenario';
16-
import scrollContainer from './utils/scrollHelper';
16+
import { scrollHorizontally } from './utils/scrollHelper';
1717
import { deleteScenario } from './utils/teardown-utils';
1818
import type { StationData } from './utils/types';
1919
import enTranslations from '../public/locales/en/timesStops.json';
@@ -109,7 +109,7 @@ test.describe('Times and Stops Tab Verification', () => {
109109

110110
// Navigate to the Times and Stops tab and scroll to the data sheet
111111
await operationalStudiesPage.clickOnTimesAndStopsTab();
112-
await scrollContainer(page, '.time-stops-datasheet .dsg-container');
112+
await scrollHorizontally(page, '.time-stops-datasheet .dsg-container');
113113
}
114114
);
115115

@@ -171,7 +171,7 @@ test.describe('Times and Stops Tab Verification', () => {
171171
await opOutputTablePage.verifyTimesStopsDataSheetVisibility();
172172

173173
// Scroll and extract output table data for verification
174-
await scrollContainer(page, '.time-stop-outputs .time-stops-datasheet .dsg-container');
174+
await scrollHorizontally(page, '.time-stop-outputs .time-stops-datasheet .dsg-container');
175175
await opOutputTablePage.getOutputTableData(outputExpectedCellData);
176176
});
177177

front/tests/012-op-simulation-settings-tab.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
import { deleteApiRequest, getInfra, setElectricalProfile } from './utils/api-setup';
2828
import { cleanWhitespace } from './utils/dataNormalizer';
2929
import createScenario from './utils/scenario';
30-
import scrollContainer from './utils/scrollHelper';
30+
import { scrollHorizontally } from './utils/scrollHelper';
3131
import { deleteScenario } from './utils/teardown-utils';
3232
import type { StationData } from './utils/types';
3333
import enTranslations from '../public/locales/en/timesStops.json';
@@ -149,7 +149,7 @@ test.describe('Simulation Settings Tab Verification', () => {
149149
await routePage.performPathfindingByTrigram('WS', 'SES', 'MWS');
150150
// Navigate to the Times and Stops tab and fill in required data
151151
await operationalStudiesPage.clickOnTimesAndStopsTab();
152-
await scrollContainer(page, '.time-stops-datasheet .dsg-container');
152+
await scrollHorizontally(page, '.time-stops-datasheet .dsg-container');
153153
}
154154
);
155155

@@ -193,7 +193,7 @@ test.describe('Simulation Settings Tab Verification', () => {
193193
actionName: 'visual assertion',
194194
}
195195
);
196-
await scrollContainer(page, '.time-stop-outputs .time-stops-datasheet .dsg-container');
196+
await scrollHorizontally(page, '.time-stop-outputs .time-stops-datasheet .dsg-container');
197197
await opOutputTablePage.getOutputTableData(expectedCellDataElectricalProfileON);
198198
await opTimetablePage.clickOnTimetableCollapseButton();
199199
// Deactivate electrical profiles and verify output results
@@ -254,7 +254,7 @@ test.describe('Simulation Settings Tab Verification', () => {
254254
actionName: 'visual assertion',
255255
}
256256
);
257-
await scrollContainer(page, '.time-stop-outputs .time-stops-datasheet .dsg-container');
257+
await scrollHorizontally(page, '.time-stop-outputs .time-stops-datasheet .dsg-container');
258258
await opOutputTablePage.getOutputTableData(expectedCellDataCodeCompoON);
259259
await opTimetablePage.clickOnTimetableCollapseButton();
260260
// Remove the composition code option and verify the changes
@@ -325,7 +325,7 @@ test.describe('Simulation Settings Tab Verification', () => {
325325
actionName: 'visual assertion',
326326
}
327327
);
328-
await scrollContainer(page, '.time-stop-outputs .time-stops-datasheet .dsg-container');
328+
await scrollHorizontally(page, '.time-stop-outputs .time-stops-datasheet .dsg-container');
329329
await opOutputTablePage.getOutputTableData(expectedCellDataLinearMargin);
330330
await opTimetablePage.clickOnTimetableCollapseButton();
331331
// Modify the margin to 'Mareco' and verify the changes
@@ -398,7 +398,7 @@ test.describe('Simulation Settings Tab Verification', () => {
398398
actionName: 'visual assertion',
399399
}
400400
);
401-
await scrollContainer(page, '.time-stop-outputs .time-stops-datasheet .dsg-container');
401+
await scrollHorizontally(page, '.time-stop-outputs .time-stops-datasheet .dsg-container');
402402
await opOutputTablePage.getOutputTableData(expectedCellDataForAllSettings);
403403
});
404404
});

front/tests/pages/op-timetable-page-model.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import enTranslations from '../../public/locales/en/operationalStudies/scenario.
55
import frTranslations from '../../public/locales/fr/operationalStudies/scenario.json';
66
import { EXPLICIT_UI_STABILITY_TIMEOUT, SIMULATION_RESULT_TIMEOUT } from '../assets/timeout-const';
77
import { getTranslations } from '../utils';
8+
import { scrollVertically } from '../utils/scrollHelper';
89

910
class OperationalStudiesTimetablePage extends CommonPage {
1011
readonly invalidTrainsMessage: Locator;
@@ -204,11 +205,12 @@ class OperationalStudiesTimetablePage extends CommonPage {
204205
for (let currentTrainIndex = 0; currentTrainIndex < trainCount; currentTrainIndex += 1) {
205206
await this.page.waitForLoadState();
206207
await this.simulationResult.waitFor();
208+
207209
const trainButton = OperationalStudiesTimetablePage.getTrainButton(
208210
this.timetableTrains.nth(currentTrainIndex)
209211
);
210212
await trainButton.click({ position: { x: 5, y: 5 } });
211-
await this.waitForSimulationResults();
213+
await scrollVertically(this.page, '.scenario-timetable-trains');
212214
await this.verifySimulationResultsVisibility();
213215
}
214216
}

front/tests/utils/scrollHelper.ts

+53-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface ScrollOptions {
1414
* @param ScrollOptions - Optional scroll configuration including step size, timeout, and scroll offset threshold.
1515
* @returns {Promise<void>} - Resolves once the container has been fully scrolled.
1616
*/
17-
const scrollContainer = async (
17+
export const scrollHorizontally = async (
1818
page: Page,
1919
containerSelector: string,
2020
{ stepSize = 300, timeout = 20, scrollOffsetThreshold = 200 }: ScrollOptions = {}
@@ -38,7 +38,7 @@ const scrollContainer = async (
3838
container
3939
);
4040

41-
// Exit early if there's little or no scrollable content
41+
// Exit early if there's a little or no scrollable content
4242
if (scrollWidth <= clientWidth + scrollOffsetThreshold) {
4343
await container.dispose();
4444
return;
@@ -64,4 +64,54 @@ const scrollContainer = async (
6464
await container.dispose();
6565
};
6666

67-
export default scrollContainer;
67+
/**
68+
* Scroll a specified container element vertically by a small step.
69+
*
70+
* @param page - The Playwright page object.
71+
* @param containerSelector - The CSS selector for the scrollable container element.
72+
* @param ScrollOptions - Optional scroll configuration including step size and scroll offset threshold.
73+
* @returns {Promise<void>} - Resolves once a small scroll action is performed.
74+
*/
75+
export const scrollVertically = async (
76+
page: Page,
77+
containerSelector: string,
78+
{ stepSize = 30, scrollOffsetThreshold = 47 }: ScrollOptions = {}
79+
): Promise<void> => {
80+
// Locate the scrollable container on the page
81+
await page.waitForSelector(containerSelector);
82+
const container = await page.evaluateHandle(
83+
(selector: string) => document.querySelector(selector),
84+
containerSelector
85+
);
86+
87+
// Retrieve the scrollable height and visible height of the container
88+
const { scrollHeight, clientHeight } = await page.evaluate(
89+
(containerElement) =>
90+
containerElement
91+
? {
92+
scrollHeight: containerElement.scrollHeight,
93+
clientHeight: containerElement.clientHeight,
94+
}
95+
: { scrollHeight: 0, clientHeight: 0 },
96+
container
97+
);
98+
99+
// Exit early if there's a little or no scrollable content
100+
if (scrollHeight <= clientHeight + scrollOffsetThreshold) {
101+
await container.dispose();
102+
return;
103+
}
104+
105+
// Perform a small vertical scroll
106+
await page.evaluate(
107+
({ containerElement, step }) => {
108+
if (containerElement) {
109+
containerElement.scrollTop += step;
110+
}
111+
},
112+
{ containerElement: container, step: stepSize }
113+
);
114+
115+
// Clean up the handle after scrolling is complete
116+
await container.dispose();
117+
};

0 commit comments

Comments
 (0)