Skip to content

Commit 507d0f5

Browse files
[O2B-1193] - Runs Per LHC Period export bugfix (#1455)
* fix edndpoint constracion * add test * amend * t * change selector * extend test * amend * docs * ch paginaion * linter * use seeder data * update * Update test/utilities/waitForDownload.js Co-authored-by: Martin Boulais <31805063+martinboulais@users.noreply.github.com> --------- Co-authored-by: Martin Boulais <31805063+martinboulais@users.noreply.github.com>
1 parent 4cd0b02 commit 507d0f5

3 files changed

Lines changed: 71 additions & 5 deletions

File tree

lib/public/views/Runs/Overview/RunsOverviewModel.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,7 @@ export class RunsOverviewModel extends OverviewPageModel {
957957
this._allRuns = RemoteData.loading();
958958
this.notify();
959959

960-
const params = this._getFilterQueryParams();
961-
962-
const endpoint = `/api/runs?${new URLSearchParams(params).toString()}`;
960+
const endpoint = this.getRootEndpoint();
963961

964962
try {
965963
const { items } = await getRemoteDataSlice(endpoint);

test/public/runs/runsPerPeriod.overview.test.js

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14+
const path = require('path');
15+
const fs = require('fs');
1416
const chai = require('chai');
1517
const {
1618
defaultBefore,
@@ -21,8 +23,10 @@ const {
2123
goToPage,
2224
reloadPage,
2325
} = require('../defaults');
24-
const { RUN_QUALITIES } = require('../../../lib/domain/enums/RunQualities.js');
26+
const { RUN_QUALITIES, RunQualities } = require('../../../lib/domain/enums/RunQualities.js');
2527
const { waitForTimeout } = require('../defaults.js');
28+
const { waitForDownload } = require('../../utilities/waitForDownload');
29+
const { RunDefinition } = require('../../../lib/server/services/run/getRunDefinition');
2630

2731
const { expect } = chai;
2832

@@ -199,4 +203,65 @@ module.exports = () => {
199203
expect(urlParameters).to.contain('page=run-detail');
200204
expect(urlParameters).to.contain(`runNumber=${expectedRunNumber}`);
201205
});
206+
207+
const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-runs-trigger';
208+
209+
it('should successfully export all runs per lhc Period', async () => {
210+
await goToPage(page, 'runs-per-lhc-period', { queryParameters: { lhcPeriodName: 'LHC22a' } });
211+
212+
const downloadPath = path.resolve('./download');
213+
214+
await page.evaluate(() => {
215+
// eslint-disable-next-line no-undef
216+
model.runs.perLhcPeriodOverviewModel.pagination.itemsPerPage = 2;
217+
});
218+
219+
// Check accessibility on frontend
220+
const session = await page.target().createCDPSession();
221+
await session.send('Browser.setDownloadBehavior', {
222+
behavior: 'allow',
223+
downloadPath: downloadPath,
224+
eventsEnabled: true,
225+
});
226+
227+
const targetFileName = 'runs.json';
228+
229+
// First export
230+
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
231+
await page.waitForSelector('select.form-control', { timeout: 200 });
232+
await page.select('select.form-control', 'runQuality', 'runNumber', 'definition', 'lhcPeriod');
233+
await expectInnerText(page, '#send:enabled', 'Export');
234+
await Promise.all([
235+
waitForDownload(session),
236+
pressElement(page, '#send:enabled'),
237+
]);
238+
239+
// Check download
240+
const downloadFilesNames = fs.readdirSync(downloadPath);
241+
expect(downloadFilesNames.filter((name) => name == targetFileName)).to.be.lengthOf(1);
242+
const runs = JSON.parse(fs.readFileSync(path.resolve(downloadPath, targetFileName)));
243+
244+
expect(runs).to.have.all.deep.members([
245+
{
246+
runNumber: 49,
247+
runQuality: RunQualities.GOOD,
248+
definition: RunDefinition.Physics,
249+
lhcPeriod: 'LHC22a',
250+
},
251+
{
252+
runNumber: 54,
253+
runQuality: RunQualities.GOOD,
254+
definition: RunDefinition.Physics,
255+
lhcPeriod: 'LHC22a',
256+
},
257+
{
258+
runNumber: 56,
259+
runQuality: RunQualities.GOOD,
260+
definition: RunDefinition.Physics,
261+
lhcPeriod: 'LHC22a',
262+
},
263+
]);
264+
265+
fs.unlinkSync(path.resolve(downloadPath, targetFileName));
266+
});
202267
};

test/utilities/waitForDownload.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
/**
1515
* Create promise which is resolved when last initiated download is completed and rejected when canceled
1616
* @param {CDPSession} session puppetear CDP session
17+
* @param {object} options options altering behaviour
18+
* @param {number} [options.timeout = 5000] timeout (ms) to reject if not downloaded
1719
* @return {Promise} promise
1820
* !!! Downloading requires to set 'Browser.setDownloadBehavior' behaviour on the given CDP session
1921
*/
20-
async function waitForDownload(session) {
22+
async function waitForDownload(session, { timeout = 5000 } = {}) {
2123
return new Promise((resolve, reject) => {
2224
session.on('Browser.downloadProgress', (event) => {
2325
if (event.state === 'completed') {
@@ -26,6 +28,7 @@ async function waitForDownload(session) {
2628
reject('download canceled');
2729
}
2830
});
31+
setTimeout(() => reject('Download timeout after ${timeout}'), timeout);
2932
});
3033
}
3134

0 commit comments

Comments
 (0)