diff --git a/test/public/defaults.js b/test/public/defaults.js index bb7ae4b811..443de2bacf 100644 --- a/test/public/defaults.js +++ b/test/public/defaults.js @@ -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} 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' : ''}`); } }; diff --git a/test/public/envs/overview.test.js b/test/public/envs/overview.test.js index 1b9fa872c6..02b5511cf2 100644 --- a/test/public/envs/overview.test.js +++ b/test/public/envs/overview.test.js @@ -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}`)); }; @@ -442,6 +442,7 @@ module.exports = () => { ['eZF99lH6'], ); await resetFilters(page); + await waitForTableLength(page, 8, 10000); await filterOnCreatedAt( periodInputsSelectors, @@ -452,5 +453,6 @@ module.exports = () => { ['GIDO1jdkD', '8E4aZTjY', 'Dxi029djX'], ); await resetFilters(page); + await waitForTableLength(page, 8, 10000); }); }; diff --git a/test/public/runs/runsPerDataPass.overview.test.js b/test/public/runs/runsPerDataPass.overview.test.js index 090384e0f6..0735f5bbb6 100644 --- a/test/public/runs/runsPerDataPass.overview.test.js +++ b/test/public/runs/runsPerDataPass.overview.test.js @@ -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]`); diff --git a/test/public/runs/runsPerLhcPeriod.overview.test.js b/test/public/runs/runsPerLhcPeriod.overview.test.js index 3a00301943..113aceb06a 100644 --- a/test/public/runs/runsPerLhcPeriod.overview.test.js +++ b/test/public/runs/runsPerLhcPeriod.overview.test.js @@ -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')); @@ -122,6 +123,7 @@ module.exports = () => { ])), }; + await waitForTableLength(page, 4); await validateTableData(page, new Map(Object.entries(tableDataValidatorsWithQualityFromSynchronousFlags))); await expectInnerText(page, '#row56-FT0', '83'); }); @@ -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 ');