Skip to content
39 changes: 32 additions & 7 deletions test/public/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,26 @@ exports.waitForNavigation = waitForNavigation;
* @returns {Promise} Whether the element was clickable or not.
*/
module.exports.pressElement = async (page, selector, jsClick = false) => {
const elementHandler = await page.waitForSelector(selector);
await page.waitForFunction(
(sel, isJsClick) => {
const element = document.querySelector(sel);

if (!element) {
return false;
}
// Moving the click to outside the function causes it to fail for unknown reasons
if (isJsClick) {
element.click();
}

if (jsClick) {
await elementHandler.evaluate((element) => element.click());
} else {
await elementHandler.click(selector);
return true;
},
{},
selector, jsClick
);

if (!jsClick) {
await page.click(selector);
}
};

Expand Down Expand Up @@ -855,10 +869,10 @@ module.exports.testTableSortingByColumn = async (page, columnId) => {
* @return {Promise<void>} resolve once data was successfully validated
*/
module.exports.validateTableData = async (page, validators) => {
await page.waitForSelector('table tbody');
for (const [columnId, validator] of validators) {
await page.waitForSelector(`table tbody .column-${columnId}`);

const columnData = await getColumnCellsInnerTexts(page, columnId);
expect(columnData, `Too few values for column ${columnId} or there is no such column`).to.be.length.greaterThan(0);
expect(
columnData.every((cellData) => validator(cellData)),
`Invalid data in column ${columnId}: (${columnData})`,
Expand Down Expand Up @@ -977,3 +991,14 @@ module.exports.resetFilters = async (page) => {
{ timeout: 5000 },
);
};

/**
* Fuction that waits for a button to become active
* @param {puppeteer.page} page page handler
* @param {string} selector Css selector for the button.
*/
module.exports.waitForButtonToBecomeActive = async (page, selector) => await page.waitForFunction((sel) => {
const button = document.querySelector(sel);
return button && !button.disabled;
}, {}, selector);

4 changes: 4 additions & 0 deletions test/public/runs/overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const {
getColumnCellsInnerTexts,
resetFilters,
openFilteringPanel,
waitForButtonToBecomeActive,
} = require('../defaults.js');
const { RUN_QUALITIES, RunQualities } = require('../../../lib/domain/enums/RunQualities.js');
const { resetDatabaseContent } = require('../../utilities/resetDatabaseContent.js');
Expand Down Expand Up @@ -885,6 +886,7 @@ module.exports = () => {
let exportModal = await page.$('#export-data-modal');
expect(exportModal).to.be.null;

await waitForButtonToBecomeActive(page, EXPORT_RUNS_TRIGGER_SELECTOR);
await page.$eval(EXPORT_RUNS_TRIGGER_SELECTOR, (button) => button.click());
await page.waitForSelector('#export-data-modal', { timeout: 5000 });
exportModal = await page.$('#export-data-modal');
Expand All @@ -893,6 +895,7 @@ module.exports = () => {
});

it('should successfully display information when export will be truncated', async () => {
await waitForButtonToBecomeActive(page, EXPORT_RUNS_TRIGGER_SELECTOR);
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR, true);

const truncatedExportWarning = await page.waitForSelector('#export-data-modal #truncated-export-warning');
Expand All @@ -912,6 +915,7 @@ module.exports = () => {
});

it('should successfully export filtered runs', async () => {
await waitForButtonToBecomeActive(page, EXPORT_RUNS_TRIGGER_SELECTOR);
const targetFileName = 'data.json';

// First export
Expand Down
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 @@ -665,8 +665,8 @@ module.exports = () => {
// Press again actions dropdown to re-trigger render
await pressElement(page, '#actions-dropdown-button .popover-trigger', true);
setConfirmationDialogToBeAccepted(page);
await pressElement(page, `${popoverSelector} button:nth-child(4)`, true);
const oldTable = await page.waitForSelector('table').then((table) => table.evaluate((t) => t.innerHTML));
await pressElement(page, `${popoverSelector} button:nth-child(4)`, true);
await pressElement(page, '#actions-dropdown-button .popover-trigger', true);
await waitForTableLength(page, 3, undefined, oldTable);
// Processing of data might take a bit of time, but then expect QC flag button to be there
Expand Down
9 changes: 5 additions & 4 deletions test/public/runs/runsPerLhcPeriod.overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const {
expectColumnValues,
openFilteringPanel,
resetFilters,
waitForButtonToBecomeActive
} = require('../defaults.js');
const { RUN_QUALITIES, RunQualities } = require('../../../lib/domain/enums/RunQualities.js');
const { resetDatabaseContent } = require('../../utilities/resetDatabaseContent.js');
Expand Down Expand Up @@ -75,6 +76,7 @@ module.exports = () => {
after(async () => {
[page, browser] = await defaultAfter(page, browser);
});
const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-data-trigger';

it('loads the page successfully', async () => {
const response = await goToPage(page, 'runs-per-lhc-period', { queryParameters: { lhcPeriodId: 1 } });
Expand Down Expand Up @@ -204,7 +206,6 @@ module.exports = () => {
await waitForTableLength(page, 4);
});

const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-data-trigger';

it('should successfully export all runs per lhc Period', async () => {
await page.evaluate(() => {
Expand All @@ -213,7 +214,7 @@ module.exports = () => {
});

const targetFileName = 'data.json';

await waitForButtonToBecomeActive(page, EXPORT_RUNS_TRIGGER_SELECTOR);
// First export
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR, true);
await page.waitForSelector('select.form-control', { timeout: 200 });
Expand Down Expand Up @@ -286,9 +287,9 @@ module.exports = () => {
await navigateToRunsPerLhcPeriod(page, 1, 4);

const targetFileName = 'data.csv';

await waitForButtonToBecomeActive(page, EXPORT_RUNS_TRIGGER_SELECTOR);
// Export
await pressElement(page, '#export-data-trigger');
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
await page.waitForSelector('#export-data-modal');
await page.waitForSelector('#send:disabled');
await page.waitForSelector('.form-control');
Expand Down
9 changes: 6 additions & 3 deletions test/public/runs/runsPerSimulationPass.overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const {
testTableSortingByColumn,
waitForTableLength,
expectColumnValues,
waitForButtonToBecomeActive,
} = require('../defaults.js');

const { expect } = chai;
Expand Down Expand Up @@ -74,6 +75,8 @@ module.exports = () => {
[page, browser] = await defaultAfter(page, browser);
});

const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-data-trigger';

it('loads the page successfully', async () => {
const response = await goToPage(page, 'runs-per-simulation-pass', { queryParameters: { simulationPassId: 2 } });

Expand Down Expand Up @@ -235,11 +238,10 @@ module.exports = () => {

it('should successfully export runs', async () => {
await navigateToRunsPerSimulationPass(page, 1, 2, 3);
const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-data-trigger';

const targetFileName = 'data.json';

// Export
await waitForButtonToBecomeActive(page, EXPORT_RUNS_TRIGGER_SELECTOR);
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
await page.waitForSelector('#export-data-modal');
await page.waitForSelector('#send:disabled');
Expand Down Expand Up @@ -270,7 +272,8 @@ module.exports = () => {
const targetFileName = 'data.csv';

// Export
await pressElement(page, '#export-data-trigger');
await waitForButtonToBecomeActive(page, EXPORT_RUNS_TRIGGER_SELECTOR);
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
await page.waitForSelector('#export-data-modal');
await page.waitForSelector('#send:disabled');
await page.waitForSelector('.form-control');
Expand Down
Loading