Skip to content
8 changes: 5 additions & 3 deletions test/public/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,20 @@ module.exports.waitForTimeout = waitForTimeout;
*
* @param {puppeteer.Page} page - The puppeteer page where the table is located.
* @param {number} expectedSize - The expected number of table rows, excluding rows marked as loading or empty.
* @param {number} [timeout] - Max wait time in ms; if omitted, uses the page default timeout.
* @return {Promise<void>} Resolves once the expected number of rows is met, or the timeout is reached.
*/
const waitForTableToLength = async (page, expectedSize) => {
const waitForTableToLength = async (page, expectedSize, timeout) => {
try {
const waitOptions = timeout === undefined ? {} : { timeout };
await page.waitForFunction(
(expectedSize) => document.querySelectorAll('table tbody tr:not(.loading-row):not(.empty-row)').length === expectedSize,
{},
waitOptions,
expectedSize,
);
} catch {
const actualSize = (await page.$$('tbody tr')).length;
const isThereLoadingRow = !!(await page.$$('table body tr.loading-row'))
const isThereLoadingRow = (await page.$$('table tbody tr.loading-row')).length > 0;
throw new Error(`Expected table of length ${expectedSize}, but got ${actualSize} ${isThereLoadingRow ? ', loading-row' : ''}`);
}
};
Expand Down
4 changes: 3 additions & 1 deletion test/public/envs/overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ module.exports = () => {
await fillInput(page, selector.fromDateSelector, fromDate, ['change']);
await fillInput(page, selector.toDateSelector, toDate, ['change']);

await waitForTableLength(page, expectedIds.length);
await waitForTableLength(page, expectedIds.length, 5000);
expect(await page.$$eval('tbody tr', (rows) => rows.map((row) => row.id))).to.eql(expectedIds.map(id => `row${id}`));
};

Expand All @@ -442,6 +442,7 @@ module.exports = () => {
['eZF99lH6'],
);
await resetFilters(page);
await waitForTableLength(page, 8, 10000);

await filterOnCreatedAt(
periodInputsSelectors,
Expand All @@ -452,5 +453,6 @@ module.exports = () => {
['GIDO1jdkD', '8E4aZTjY', 'Dxi029djX'],
);
await resetFilters(page);
await waitForTableLength(page, 8, 10000);
});
};
2 changes: 1 addition & 1 deletion test/public/runs/runsPerDataPass.overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ module.exports = () => {
await pressElement(page, amountItems5);

// Expect the amount of visible runs to reduce when the first option (5) is selected
await expectInnerText(page, '.dropup button', 'Rows per page: 5 ');
await waitForTableLength(page, 4);
await expectInnerText(page, '.dropup button', 'Rows per page: 5 ');

// Expect the custom per page input to have red border and text color if wrong value typed
const customPerPageInput = await page.$(`${amountSelectorId} input[type=number]`);
Expand Down
8 changes: 8 additions & 0 deletions test/public/runs/runsPerLhcPeriod.overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module.exports = () => {
...Object.fromEntries(DETECTORS.map((detectorName) => [detectorName, (quality) => expect(quality).oneOf([...RUN_QUALITIES, ''])])),
};

await waitForTableLength(page, 4);
await validateTableData(page, new Map(Object.entries(tableDataValidatorsWithDetectorQualities)));

await waitForNavigation(page, () => pressElement(page, '#synchronousFlags-tab'));
Expand All @@ -122,6 +123,7 @@ module.exports = () => {
])),
};

await waitForTableLength(page, 4);
await validateTableData(page, new Map(Object.entries(tableDataValidatorsWithQualityFromSynchronousFlags)));
await expectInnerText(page, '#row56-FT0', '83');
});
Expand Down Expand Up @@ -153,10 +155,16 @@ module.exports = () => {
const amountSelectorButtonSelector = `${amountSelectorId} button`;
await pressElement(page, amountSelectorButtonSelector);

await fillInput(page, `${amountSelectorId} input[type=number]`, '3', ['input', 'change']);
await waitForTableLength(page, 3);
await expectInnerText(page, '.dropup button', 'Rows per page: 3 ');

await pressElement(page, amountSelectorButtonSelector);
await page.waitForSelector(`${amountSelectorId} .dropup-menu`);

const amountItems5 = `${amountSelectorId} .dropup-menu .menu-item:first-child`;
await pressElement(page, amountItems5, true);
// only 4 runs in LHC Period 1
await waitForTableLength(page, 4);
await expectInnerText(page, '.dropup button', 'Rows per page: 5 ');

Expand Down
Loading