Skip to content

Commit d749d57

Browse files
authored
[O2B-1148] Runs filtering is not considered in runs export (#1392)
* fix * add test * change selector * extend test * extend test * amend remove waitForTimeout
1 parent 8dae228 commit d749d57

3 files changed

Lines changed: 117 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ export class RunsOverviewModel extends OverviewPageModel {
7070
return `/api/runs?${paramsString}`;
7171
}
7272

73+
// eslint-disable-next-line valid-jsdoc
74+
/**
75+
* @inheritdoc
76+
*/
77+
async load() {
78+
this._allRuns = RemoteData.NotAsked();
79+
super.load();
80+
}
81+
7382
/**
7483
* Create the export with the variables set in the model, handling errors appropriately
7584
* @param {object[]} runs The source content.

test/public/runs/overview.test.js

Lines changed: 76 additions & 0 deletions
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,
@@ -26,6 +28,7 @@ const {
2628
const { RunDefinition } = require('../../../lib/server/services/run/getRunDefinition.js');
2729
const { RUN_QUALITIES, RunQualities } = require('../../../lib/domain/enums/RunQualities.js');
2830
const { fillInput, getPopoverContent, getInnerText } = require('../defaults.js');
31+
const { waitForDownload } = require('../../utilities/waitForDownload');
2932

3033
const { expect } = chai;
3134

@@ -1057,6 +1060,79 @@ module.exports = () => {
10571060
expect(await page.$eval(EXPORT_RUNS_TRIGGER_SELECTOR, (button) => button.disabled)).to.be.true;
10581061
});
10591062

1063+
it('should successfully export filtered runs', async () => {
1064+
await goToPage(page, 'run-overview');
1065+
1066+
const downloadPath = path.resolve('./download');
1067+
1068+
// Check accessibility on frontend
1069+
const session = await page.target().createCDPSession();
1070+
await session.send('Browser.setDownloadBehavior', {
1071+
behavior: 'allow',
1072+
downloadPath: downloadPath,
1073+
eventsEnabled: true,
1074+
});
1075+
1076+
let downloadFilesNames;
1077+
const targetFileName = 'runs.json';
1078+
let runs;
1079+
let exportModal;
1080+
1081+
// First export
1082+
await page.$eval(EXPORT_RUNS_TRIGGER_SELECTOR, (button) => button.click());
1083+
await page.waitForSelector('#export-runs-modal');
1084+
exportModal = await page.$('#export-runs-modal');
1085+
expect(exportModal).to.not.be.null;
1086+
const exportButtonText = await page.$eval('#send', (button) => button.innerText);
1087+
expect(exportButtonText).to.be.eql('Export');
1088+
1089+
await page.select('.form-control', 'runQuality', 'runNumber');
1090+
await page.$eval('#send', (button) => button.click());
1091+
1092+
await waitForDownload(session);
1093+
1094+
// Check download
1095+
downloadFilesNames = fs.readdirSync(downloadPath);
1096+
expect(downloadFilesNames.filter((name) => name == targetFileName)).to.be.lengthOf(1);
1097+
runs = JSON.parse(fs.readFileSync(path.resolve(downloadPath, targetFileName)));
1098+
1099+
expect(runs).to.be.lengthOf(100);
1100+
expect(runs.every(({ runQuality, runNumber, ...otherProps }) =>
1101+
runQuality && runNumber && Object.keys(otherProps).length === 0)).to.be.true;
1102+
downloadFilesNames = fs.readdirSync(downloadPath);
1103+
fs.unlinkSync(path.resolve(downloadPath, targetFileName));
1104+
downloadFilesNames = fs.readdirSync(downloadPath);
1105+
1106+
// Second export
1107+
1108+
// Apply filtering
1109+
const filterInputSelectorPrefix = '#runQualityCheckbox';
1110+
const badFilterSelector = `${filterInputSelectorPrefix}bad`;
1111+
1112+
await pressElement(page, '#openFilterToggle');
1113+
await page.waitForSelector(badFilterSelector);
1114+
await page.$eval(badFilterSelector, (element) => element.click());
1115+
await page.waitForSelector('div.atom-spinner');
1116+
await page.waitForSelector(EXPORT_RUNS_TRIGGER_SELECTOR);
1117+
1118+
///// Download
1119+
await page.$eval(EXPORT_RUNS_TRIGGER_SELECTOR, (button) => button.click());
1120+
await page.waitForSelector('#export-runs-modal');
1121+
exportModal = await page.$('#export-runs-modal');
1122+
expect(exportModal).to.not.be.null;
1123+
1124+
await page.select('.form-control', 'runQuality', 'runNumber');
1125+
await page.$eval('#send', (button) => button.click());
1126+
1127+
await waitForDownload(session);
1128+
1129+
// Check download
1130+
downloadFilesNames = fs.readdirSync(downloadPath);
1131+
expect(downloadFilesNames.filter((name) => name == targetFileName)).to.be.lengthOf(1);
1132+
runs = JSON.parse(fs.readFileSync(path.resolve(downloadPath, targetFileName)));
1133+
expect(runs).to.have.all.deep.members([{ runNumber: 2, runQuality: 'bad' }, { runNumber: 1, runQuality: 'bad' }]);
1134+
});
1135+
10601136
it('should successfully navigate to the LHC fill details page', async () => {
10611137
await reloadPage(page);
10621138

test/utilities/waitForDownload.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
/**
15+
* Create promise which is resolved when last initiated download is completed and rejected when canceled
16+
* @param {CDPSession} session puppetear CDP session
17+
* @return {Promise} promise
18+
* !!! Downloading requires to set 'Browser.setDownloadBehavior' behaviour on the given CDP session
19+
*/
20+
async function waitForDownload(session) {
21+
return new Promise((resolve, reject) => {
22+
session.on('Browser.downloadProgress', (event) => {
23+
if (event.state === 'completed') {
24+
resolve();
25+
} else if (event.state === 'canceled') {
26+
reject();
27+
}
28+
});
29+
});
30+
}
31+
32+
exports.waitForDownload = waitForDownload;

0 commit comments

Comments
 (0)