Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboulais committed Dec 9, 2024
1 parent 9da6e5b commit 7c855d6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
34 changes: 32 additions & 2 deletions test/public/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ module.exports.getInnerText = getInnerText;
* @return {Promise<void>} resolves once the text has been checked
*/
module.exports.expectInnerText = async (page, selector, innerText) => {
const element = await page.waitForSelector(selector);
const elementHandle = await page.waitForSelector(selector);
try {
await page.waitForFunction(
(selector, innerText) => document.querySelector(selector).innerText === innerText,
Expand All @@ -405,8 +405,38 @@ module.exports.expectInnerText = async (page, selector, innerText) => {
innerText,
);
} catch (_) {
throw new Error(`Expected innerText for ${selector} to be "${innerText}", got "${await getInnerText(element)}"`);
const actualInnerText = await getInnerText(elementHandle);
await elementHandle.dispose();
throw new Error(`Expected innerText for ${selector} to be "${innerText}", got "${actualInnerText}"`);
}
await elementHandle.dispose();
};

/**
* Expect a given attribute of an element to have a given value
*
* @param {puppeteer.Page} page the puppeteer page
* @param {string} selector the selector of the element to look for attribute
* @param {string} attributeKey the key of the attribute to check
* @param {string} attributeValue the expected value
* @return {Promise<void>} resolves once the attribute has the expected value
*/
module.exports.expectAttributeValue = async (page, selector, attributeKey, attributeValue) => {
const elementHandle = await page.waitForSelector(selector);
try {
await page.waitForFunction(
(selector, attributeKey, attributeValue) => document.querySelector(selector).getAttribute(attributeKey) === attributeValue,
{},
selector,
attributeKey,
attributeValue,
);
} catch (_) {
const actualAttributeValue = await elementHandle.evaluate((element, attributeKey) => element.getAttribute(attributeKey), attributeKey);
await elementHandle.dispose();
throw new Error(`Expect attribute ${attributeKey} to be ${attributeValue}, got ${actualAttributeValue}`);
}
await elementHandle.dispose();
};

/**
Expand Down
33 changes: 13 additions & 20 deletions test/public/runs/overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ const {
waitForEmptyTable,
waitForDownload,
expectUrlParams,
expectAttributeValue,
} = require('../defaults.js');
const { RUN_QUALITIES, RunQualities } = require('../../../lib/domain/enums/RunQualities.js');
const { resetDatabaseContent } = require('../../utilities/resetDatabaseContent.js');
const { RunDefinition } = require('../../../lib/domain/enums/RunDefinition.js');
const { runService } = require('../../../lib/server/services/run/RunService.js');

const { expect } = chai;

Expand Down Expand Up @@ -268,6 +270,7 @@ module.exports = () => {

// Run 106 has detectors and tags that overflow
await page.type(runNumberInputSelector, '106');
await fillInput(page, runNumberInputSelector, '106');
await waitForTableLength(page, 1);

await checkColumnBalloon(page, 1, 2);
Expand Down Expand Up @@ -442,30 +445,20 @@ module.exports = () => {
await fillInput(page, periodInputsSelectors.toDateSelector, '2021-02-03', ['change']);

// Wait for page to be refreshed
await page.waitForFunction(
(selector) => document.querySelector(selector).getAttribute('min') !== '',
{ timeout: 500 },
periodInputsSelectors.toTimeSelector,
);

expect(await page.$eval(periodInputsSelectors.toTimeSelector, (element) => element.getAttribute('min'))).to.equal('11:12');
expect(await page.$eval(periodInputsSelectors.toDateSelector, (element) => element.getAttribute('min'))).to.equal('2021-02-03');
await expectAttributeValue(page, periodInputsSelectors.toTimeSelector, 'min', '11:12');
await expectAttributeValue(page, periodInputsSelectors.toDateSelector, 'min', '2021-02-03');

expect(await page.$eval(periodInputsSelectors.fromTimeSelector, (element) => element.getAttribute('max'))).to.equal('13:59');
expect(await page.$eval(periodInputsSelectors.fromDateSelector, (element) => element.getAttribute('max'))).to.equal('2021-02-03');
await expectAttributeValue(page, periodInputsSelectors.fromTimeSelector, 'max', '13:59');
await expectAttributeValue(page, periodInputsSelectors.fromDateSelector, 'max', '2021-02-03');

// Setting different dates, still american style input
await fillInput(page, periodInputsSelectors.toDateSelector, '2021-02-05', ['change']);

await page.waitForFunction(
(selector) => document.querySelector(selector).getAttribute('min') === '',
{ timeout: 500 },
periodInputsSelectors.toTimeSelector,
);
expect(await page.$eval(periodInputsSelectors.toDateSelector, (element) => element.getAttribute('min'))).to.equal('2021-02-03');
await expectAttributeValue(page, periodInputsSelectors.toTimeSelector, 'min', '');
await expectAttributeValue(page, periodInputsSelectors.toDateSelector, 'min', '2021-02-03');

expect(await page.$eval(periodInputsSelectors.fromTimeSelector, (element) => element.getAttribute('max'))).to.equal('');
expect(await page.$eval(periodInputsSelectors.fromDateSelector, (element) => element.getAttribute('max'))).to.equal('2021-02-05');
await expectAttributeValue(page, periodInputsSelectors.fromTimeSelector, 'max', '');
await expectAttributeValue(page, periodInputsSelectors.fromDateSelector, 'max', '2021-02-05');
});

it('should successfully filter on duration', async () => {
Expand Down Expand Up @@ -1048,12 +1041,12 @@ module.exports = () => {

await expectLink(page, `${popoverSelector} a:nth-of-type(1)`, {

Check failure on line 1042 in test/public/runs/overview.test.js

View workflow job for this annotation

GitHub Actions / linter

'expectLink' is not defined
href: 'http://localhost:8081/?q={%22partition%22:{%22match%22:%22TDI59So3d%22},'
+ '%22run%22:{%22match%22:%22104%22},%22severity%22:{%22in%22:%22W%20E%20F%22}}',
+ '%22run%22:{%22match%22:%22104%22},%22severity%22:{%22in%22:%22W%20E%20F%22}}',
innerText: 'Infologger FLP',
});
await expectLink(page, `${popoverSelector} a:nth-of-type(2)`, {

Check failure on line 1047 in test/public/runs/overview.test.js

View workflow job for this annotation

GitHub Actions / linter

'expectLink' is not defined
href: 'http://localhost:8082/' +
'?page=layoutShow&runNumber=104&definition=COMMISSIONING&detector=CPV&pdpBeamType=cosmic&runType=COSMICS',
'?page=layoutShow&runNumber=104&definition=COMMISSIONING&detector=CPV&pdpBeamType=cosmic&runType=COSMICS',
innerText: 'QCG',
});

Expand Down
1 change: 1 addition & 0 deletions test/public/runs/runsPerDataPass.overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ module.exports = () => {
});

it('should successfully apply duration filter', async () => {
await navigateToRunsPerDataPass(page, { lhcPeriodId: 2, dataPassId: 2 }, { epectedRowsCount: 3 });
await pressElement(page, '#openFilterToggle');

await page.select('.runDuration-filter select', '>=');
Expand Down

0 comments on commit 7c855d6

Please sign in to comment.