-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathrunsPerSimulationPass.overview.test.js
More file actions
298 lines (246 loc) · 12.3 KB
/
Copy pathrunsPerSimulationPass.overview.test.js
File metadata and controls
298 lines (246 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
const path = require('path');
const fs = require('fs');
const chai = require('chai');
const {
defaultBefore,
defaultAfter,
expectInnerText,
pressElement,
goToPage,
validateTableData,
fillInput,
validateDate,
expectLink,
reloadPage,
waitForDownload,
waitForNavigation,
expectUrlParams,
testTableSortingByColumn,
waitForTableLength,
expectColumnValues,
} = require('../defaults.js');
const { expect } = chai;
const { qcFlagService } = require('../../../lib/server/services/qualityControlFlag/QcFlagService');
const { resetDatabaseContent } = require('../../utilities/resetDatabaseContent.js');
const { navigateToRunsPerSimulationPass } = require('./navigationUtils.js');
const DETECTORS = [
'CPV',
'EMC',
'FDD',
'FT0',
'FV0',
'HMP',
'ITS',
'MCH',
'MFT',
'MID',
'PHS',
'TOF',
'TPC',
'TRD',
'ZDC',
];
module.exports = () => {
let page;
let browser;
before(async () => {
[page, browser] = await defaultBefore(page, browser);
await page.setViewport({
width: 1200,
height: 720,
deviceScaleFactor: 1,
});
await resetDatabaseContent();
});
after(async () => {
[page, browser] = await defaultAfter(page, browser);
});
it('loads the page successfully', async () => {
const response = await goToPage(page, 'runs-per-simulation-pass', { queryParameters: { simulationPassId: 2 } });
// We expect the page to return the correct status code, making sure the server is running properly
expect(response.status()).to.equal(200);
// We expect the page to return the correct title, making sure there isn't another server running on this port
const title = await page.title();
expect(title).to.equal('AliceO2 Bookkeeping');
await page.waitForSelector('h2');
const headerBreadcrumbs = await page.$$('h2');
expect(await headerBreadcrumbs[0].evaluate((element) => element.innerText)).to.be.equal('Runs per MC');
expect(await headerBreadcrumbs[1].evaluate((element) => element.innerText)).to.be.equal('LHC23k6b');
});
it('shows correct datatypes in respective columns', async () => {
const tableDataValidators = {
runNumber: (number) => !isNaN(number),
fillNumber: (number) => number === '-' || !isNaN(number),
timeO2Start: (date) => date === '-' || validateDate(date),
timeO2End: (date) => date === '-' || validateDate(date),
timeTrgStart: (date) => date === '-' || validateDate(date),
timeTrgEnd: (date) => date === '-' || validateDate(date),
aliceL3Current: (current) => !isNaN(Number(current.replace(/,/g, ''))),
dipoleCurrent: (current) => !isNaN(Number(current.replace(/,/g, ''))),
inelasticInteractionRateAvg: (value) => value === '-' || !isNaN(Number(value.replace(/,/g, ''))),
inelasticInteractionRateAtStart: (value) => value === '-' || !isNaN(Number(value.replace(/,/g, ''))),
inelasticInteractionRateAtMid: (value) => value === '-' || !isNaN(Number(value.replace(/,/g, ''))),
inelasticInteractionRateAtEnd: (value) => value === '-' || !isNaN(Number(value.replace(/,/g, ''))),
...Object.fromEntries(DETECTORS.map((detectorName) => [
detectorName,
(qualityDisplay) => !qualityDisplay || /(QC)|(\d+)/.test(qualityDisplay),
])),
};
await validateTableData(page, new Map(Object.entries(tableDataValidators)));
await expectLink(page, 'tr#row56 .column-ITS a', {
href: 'http://localhost:4000/?page=qc-flag-creation-for-simulation-pass&runNumberDetectorsMap=56:4&simulationPassId=2',
innerText: 'QC',
});
const [tmpQcFlag] = await qcFlagService.create(
[{ flagTypeId: 2 }],
{ runNumber: 56, simulationPassIdentifier: { id: 2 }, detectorIdentifier: { detectorId: 4 } },
{ user: { externalUserId: 1, roles: ['admin'] } }, // Create bad flag
);
await reloadPage(page);
await expectLink(page, 'tr#row56 .column-ITS a', {
href: 'http://localhost:4000/?page=qc-flags-for-simulation-pass&runNumber=56&dplDetectorId=4&simulationPassId=2',
innerText: '0',
});
await page.waitForSelector('tr#row56 .column-ITS a .icon');
await qcFlagService.delete(tmpQcFlag.id);
});
it('should display detector columns in RCT order (AOT/MUON after physical)', async () => {
const headers = await page.$$eval(
'table thead th',
(ths) => ths.map((th) => th.id).filter(Boolean),
);
// See DetectorOrders.RCT in detectorOrders.js
expect(headers.indexOf('VTX')).to.be.greaterThan(headers.indexOf('ZDC'));
expect(headers.indexOf('MUD')).to.be.greaterThan(headers.indexOf('ZDC'));
});
it('should successfully sort by runNumber in ascending and descending manners', async () => {
await testTableSortingByColumn(page, 'runNumber');
});
it('Should display the correct items counter at the bottom of the page', async () => {
await expectInnerText(page, '#firstRowIndex', '1');
await expectInnerText(page, '#lastRowIndex', '3');
await expectInnerText(page, '#totalRowsCount', '3');
});
it('successfully switch to raw timestamp display', async () => {
await expectInnerText(page, '#row56 td:nth-child(3)', '08/08/2019\n20:00:00');
await expectInnerText(page, '#row56 td:nth-child(4)', '08/08/2019\n21:00:00');
await pressElement(page, '#preferences-raw-timestamps', true);
await expectInnerText(page, '#row56 td:nth-child(3)', '1565294400000');
await expectInnerText(page, '#row56 td:nth-child(4)', '1565298000000');
});
it('can set how many runs are available per page', async () => {
const amountSelectorId = '#amountSelector';
const amountSelectorButtonSelector = `${amountSelectorId} button`;
await pressElement(page, amountSelectorButtonSelector);
await page.waitForSelector(`${amountSelectorId} .dropup-menu`);
const amountItems5 = `${amountSelectorId} .dropup-menu .menu-item:first-child`;
await pressElement(page, amountItems5);
await page.waitForSelector(`${amountSelectorId} .dropup-menu`);
await fillInput(page, `${amountSelectorId} input[type=number]`, 1111);
await page.waitForSelector(amountSelectorId);
});
it('notifies if table loading returned an error', async () => {
// eslint-disable-next-line no-return-assign, no-undef
await page.evaluate(() => model.runs.perSimulationPassOverviewModel.pagination.itemsPerPage = 200);
// We expect there to be a fitting error message
const expectedMessage = 'Invalid Attribute: "query.page.limit" must be less than or equal to 100';
await expectInnerText(page, '.alert-danger', expectedMessage);
await page.evaluate(() => {
// eslint-disable-next-line no-undef
model.runs.perSimulationPassOverviewModel.pagination.reset();
// eslint-disable-next-line no-undef
model.runs.perSimulationPassOverviewModel.pagination.notify();
});
await waitForTableLength(page, 3);
});
it('can navigate to a run detail page', async () => {
await waitForNavigation(page, () => pressElement(page, 'tbody tr:first-of-type a'));
expectUrlParams(page, { page: 'run-detail', runNumber: 56 });
await waitForNavigation(page, () => page.goBack());
});
it('should successfully apply detectors notBadFraction filters', async () => {
await navigateToRunsPerSimulationPass(page, 2, 1, 3);
await pressElement(page, '#openFilterToggle', true);
await page.waitForSelector('#detectorsQc-for-1-notBadFraction-operator');
await page.select('#detectorsQc-for-1-notBadFraction-operator', '<=');
await fillInput(page, '#detectorsQc-for-1-notBadFraction-operand', '90', ['change']);
await expectColumnValues(page, 'runNumber', ['106']);
await pressElement(page, '#openFilterToggle', true);
await pressElement(page, '#reset-filters', true);
await expectColumnValues(page, 'runNumber', ['107', '106', '105']);
});
it('should successfully apply detectors notBadFraction filters', async () => {
await navigateToRunsPerSimulationPass(page, 2, 1, 3);
await pressElement(page, '#openFilterToggle', true);
await page.waitForSelector('#detectorsQc-for-1-notBadFraction-operator');
await page.select('#detectorsQc-for-1-notBadFraction-operator', '<=');
await fillInput(page, '#detectorsQc-for-1-notBadFraction-operand', '90', ['change']);
await expectColumnValues(page, 'runNumber', ['106']);
await pressElement(page, '#openFilterToggle', true);
await pressElement(page, '#reset-filters', true);
await expectColumnValues(page, 'runNumber', ['107', '106', '105']);
});
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 pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
await page.waitForSelector('#export-data-modal');
await page.waitForSelector('#send:disabled');
await page.waitForSelector('.form-control');
await page.select('.form-control', 'runQuality', 'runNumber');
await page.waitForSelector('#send:enabled');
await expectInnerText(page, '#send', 'Export');
const downloadPath = await waitForDownload(page, () => pressElement(page, '#send'));
// Check download
const downloadFilesNames = fs.readdirSync(downloadPath);
expect(downloadFilesNames.filter((name) => name == targetFileName)).to.be.lengthOf(1);
const runs = JSON.parse(fs.readFileSync(path.resolve(downloadPath, targetFileName)));
expect(runs).to.be.lengthOf(3);
expect(runs).to.have.deep.all.members([
{ runNumber: 56, runQuality: 'good' },
{ runNumber: 54, runQuality: 'good' },
{ runNumber: 49, runQuality: 'good' },
]);
fs.unlinkSync(path.resolve(downloadPath, targetFileName));
});
it('should successfully export runs with QC flags as CSV', async () => {
await navigateToRunsPerSimulationPass(page, 2, 1, 3);
const targetFileName = 'data.csv';
// Export
await pressElement(page, '#export-data-trigger');
await page.waitForSelector('#export-data-modal');
await page.waitForSelector('#send:disabled');
await page.waitForSelector('.form-control');
await page.select('.form-control', 'runNumber', 'CPV');
await pressElement(page, '#data-export-type-CSV');
await page.waitForSelector('#send:enabled');
const exportButtonText = await page.$eval('#send', (button) => button.innerText);
expect(exportButtonText).to.be.eql('Export');
const downloadPath = await waitForDownload(page, () => pressElement(page, '#send', true));
// Check download
const downloadFilesNames = fs.readdirSync(downloadPath);
expect(downloadFilesNames.filter((name) => name == targetFileName)).to.be.lengthOf(1);
const exportContent = fs.readFileSync(path.resolve(downloadPath, targetFileName)).toString();
expect(exportContent.trim()).to.be.eql([
'runNumber;CPV',
'107;""',
'106;"Bad (from: 1565272000000 to: 1565337000000) | Bad (from: 1565340600000 to: 1565359200000)"',
'105;""',
].join('\r\n'));
fs.unlinkSync(path.resolve(downloadPath, targetFileName));
});
};