Skip to content

Commit 810f3dd

Browse files
author
GuustMetz
committed
remove the element check from the evaluate call
1 parent 8d2d301 commit 810f3dd

4 files changed

Lines changed: 22 additions & 30 deletions

File tree

test/public/defaults.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,7 @@ module.exports.pressElement = async (page, selector, jsClick = false) => {
278278
await page.waitForFunction( (sel) => !!document.querySelector(sel), {}, selector);
279279

280280
if (jsClick) {
281-
await page.evaluate((sel) => {
282-
const element = document.querySelector(sel);
283-
if (element) {
284-
element.click();
285-
}
286-
}, selector);
281+
await page.$eval(selector, (element) => element.click());
287282
} else {
288283
await page.click(selector);
289284
}
@@ -982,3 +977,14 @@ module.exports.resetFilters = async (page) => {
982977
{ timeout: 5000 },
983978
);
984979
};
980+
981+
/**
982+
* Fuction that waits for a button to become active
983+
* @param {puppeteer.page} page page handler
984+
* @param {string} selector Css selector for the button.
985+
*/
986+
module.exports.waitForButtonToBecomeActive = async (page, selector) => await page.waitForFunction((sel) => {
987+
const button = document.querySelector(sel);
988+
return button && !button.disabled;
989+
}, {}, selector);
990+

test/public/runs/overview.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const {
4040
getColumnCellsInnerTexts,
4141
resetFilters,
4242
openFilteringPanel,
43+
waitForButtonToBecomeActive,
4344
} = require('../defaults.js');
4445
const { RUN_QUALITIES, RunQualities } = require('../../../lib/domain/enums/RunQualities.js');
4546
const { resetDatabaseContent } = require('../../utilities/resetDatabaseContent.js');
@@ -867,12 +868,6 @@ module.exports = () => {
867868

868869
describe("Export", () => {
869870
const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-data-trigger';
870-
const waitForExportButton = async () =>
871-
await page.waitForFunction((selector) => {
872-
const button = document.querySelector(selector);
873-
return button && !button.disabled;
874-
}, {}, EXPORT_RUNS_TRIGGER_SELECTOR);
875-
876871

877872
before(() => goToPage(page, 'run-overview'));
878873

@@ -891,7 +886,7 @@ module.exports = () => {
891886
let exportModal = await page.$('#export-data-modal');
892887
expect(exportModal).to.be.null;
893888

894-
await waitForExportButton();
889+
await waitForButtonToBecomeActive(EXPORT_RUNS_TRIGGER_SELECTOR);
895890
await page.$eval(EXPORT_RUNS_TRIGGER_SELECTOR, (button) => button.click());
896891
await page.waitForSelector('#export-data-modal', { timeout: 5000 });
897892
exportModal = await page.$('#export-data-modal');
@@ -900,7 +895,7 @@ module.exports = () => {
900895
});
901896

902897
it('should successfully display information when export will be truncated', async () => {
903-
await waitForExportButton();
898+
await waitForButtonToBecomeActive(EXPORT_RUNS_TRIGGER_SELECTOR);
904899
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR, true);
905900

906901
const truncatedExportWarning = await page.waitForSelector('#export-data-modal #truncated-export-warning');
@@ -920,7 +915,7 @@ module.exports = () => {
920915
});
921916

922917
it('should successfully export filtered runs', async () => {
923-
await waitForExportButton();
918+
await waitForButtonToBecomeActive(EXPORT_RUNS_TRIGGER_SELECTOR);
924919
const targetFileName = 'data.json';
925920

926921
// First export

test/public/runs/runsPerLhcPeriod.overview.test.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const {
3232
expectColumnValues,
3333
openFilteringPanel,
3434
resetFilters,
35+
waitForButtonToBecomeActive
3536
} = require('../defaults.js');
3637
const { RUN_QUALITIES, RunQualities } = require('../../../lib/domain/enums/RunQualities.js');
3738
const { resetDatabaseContent } = require('../../utilities/resetDatabaseContent.js');
@@ -77,12 +78,6 @@ module.exports = () => {
7778
});
7879
const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-data-trigger';
7980

80-
const waitForExportButton = async () =>
81-
await page.waitForFunction((selector) => {
82-
const button = document.querySelector(selector);
83-
return button && !button.disabled;
84-
}, {}, EXPORT_RUNS_TRIGGER_SELECTOR);
85-
8681
it('loads the page successfully', async () => {
8782
const response = await goToPage(page, 'runs-per-lhc-period', { queryParameters: { lhcPeriodId: 1 } });
8883

@@ -219,7 +214,7 @@ module.exports = () => {
219214
});
220215

221216
const targetFileName = 'data.json';
222-
await waitForExportButton();
217+
await waitForButtonToBecomeActive(EXPORT_RUNS_TRIGGER_SELECTOR);
223218
// First export
224219
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR, true);
225220
await page.waitForSelector('select.form-control', { timeout: 200 });
@@ -292,7 +287,7 @@ module.exports = () => {
292287
await navigateToRunsPerLhcPeriod(page, 1, 4);
293288

294289
const targetFileName = 'data.csv';
295-
await waitForExportButton();
290+
await waitForButtonToBecomeActive(EXPORT_RUNS_TRIGGER_SELECTOR);
296291
// Export
297292
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
298293
await page.waitForSelector('#export-data-modal');

test/public/runs/runsPerSimulationPass.overview.test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const {
3131
testTableSortingByColumn,
3232
waitForTableLength,
3333
expectColumnValues,
34+
waitForButtonToBecomeActive,
3435
} = require('../defaults.js');
3536

3637
const { expect } = chai;
@@ -76,12 +77,6 @@ module.exports = () => {
7677

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

79-
const waitForExportButton = async () =>
80-
await page.waitForFunction((selector) => {
81-
const button = document.querySelector(selector);
82-
return button && !button.disabled;
83-
}, {}, EXPORT_RUNS_TRIGGER_SELECTOR);
84-
8580
it('loads the page successfully', async () => {
8681
const response = await goToPage(page, 'runs-per-simulation-pass', { queryParameters: { simulationPassId: 2 } });
8782

@@ -246,7 +241,7 @@ module.exports = () => {
246241
const targetFileName = 'data.json';
247242

248243
// Export
249-
await waitForExportButton();
244+
await waitForButtonToBecomeActive(EXPORT_RUNS_TRIGGER_SELECTOR);
250245
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
251246
await page.waitForSelector('#export-data-modal');
252247
await page.waitForSelector('#send:disabled');
@@ -277,6 +272,7 @@ module.exports = () => {
277272
const targetFileName = 'data.csv';
278273

279274
// Export
275+
await waitForButtonToBecomeActive(EXPORT_RUNS_TRIGGER_SELECTOR);
280276
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
281277
await page.waitForSelector('#export-data-modal');
282278
await page.waitForSelector('#send:disabled');

0 commit comments

Comments
 (0)