Skip to content

Commit 76225f1

Browse files
[O2B-1181] Add tests for no-anonymous logs toggle (#1477)
* [O2B-1181] Add tests for no-anonymous logs toggle * Fix linter and tests
1 parent 0e845b2 commit 76225f1

10 files changed

Lines changed: 93 additions & 57 deletions

File tree

lib/database/seeders/20200508094502-logs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ module.exports = {
963963
origin: 'process',
964964
parent_log_id: 117,
965965
root_log_id: 117,
966-
user_id: 2,
966+
user_id: null,
967967
text: 'Run #1 stopped',
968968
created_at: new Date('2019-11-11 12:00:00 PM'),
969969
},

lib/public/components/common/table/rows.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ import { noDataRow } from './noDataRow.js';
2424
*/
2525
const cell = (rowId, column, rowData) => {
2626
const cellData = rowData[column.key];
27-
const { key, balloon = false, noEllipsis = false } = column;
27+
const {
28+
key,
29+
balloon = false,
30+
noEllipsis = false,
31+
size = '',
32+
classes = '',
33+
} = column;
2834
const format = column.format || ((text) => text);
2935

3036
const cellContent = format(cellData, rowData);
@@ -38,7 +44,8 @@ const cell = (rowId, column, rowData) => {
3844
};
3945

4046
// Keep value.size for retro-compatibility purpose
41-
return h(`td.${column.size} ${column.classes}`, {
47+
const concatenatedClasses = [size.split('.'), classes.split('.'), `column-${key}`].filter((className) => className).join('.');
48+
return h(`td.${concatenatedClasses}`, {
4249
id: columnId,
4350
key: columnId,
4451
}, isBalloon ? overflowBalloon(cellContent, { stretch: true }) : h(`${noEllipsis ? '' : '.w-wrapped'}`, allParams, cellContent));

lib/public/views/Logs/Overview/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const logOverviewScreen = ({ logs: { overviewModel: logsOverviewModel } }) => {
3636
));
3737

3838
return h('', [
39-
h('.flex-row.justify-between.header-container.pv2', [
39+
h('#main-action-bar.flex-row.justify-between.header-container.pv2', [
4040
h('.flex-row.g3', [
4141
filtersPanelPopover(logsOverviewModel, logsActiveColumns),
4242
excludeAnonymousLogAuthorToggle(logsOverviewModel.authorFilter),

test/lib/server/services/log/getLogsByUserInPeriod.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = () => {
2828
}
2929
{
3030
const logs = await getLogsByUserInPeriod({ id: 2 }, { from: limit1, to: limit2 });
31-
expect(logs).to.lengthOf(113);
31+
expect(logs).to.lengthOf(112);
3232
expect(logs.every(({ user }) => user.id === 2)).to.be.true;
3333
}
3434
{

test/public/dataPasses/overviewPerLhcPeriod.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const {
1616
defaultBefore,
1717
defaultAfter,
1818
goToPage,
19-
getAllDataFields,
19+
getColumnCellsInnerTexts,
2020
fillInput,
2121
waitForTimeout,
2222
validateTableData,
@@ -126,7 +126,7 @@ module.exports = () => {
126126
await waitForTimeout(300);
127127

128128
// Expect the names to be in alphabetical order
129-
const firstNames = await getAllDataFields(page, 'name');
129+
const firstNames = await getColumnCellsInnerTexts(page, 'name');
130130
expect(firstNames).to.have.all.deep.ordered.members(firstNames.sort());
131131
});
132132

@@ -144,7 +144,7 @@ module.exports = () => {
144144
await waitForTimeout(300);
145145

146146
// Expect the year to be in order
147-
const firstReconstructedEventsCounts = await getAllDataFields(page, 'reconstructedEventsCount');
147+
const firstReconstructedEventsCounts = await getColumnCellsInnerTexts(page, 'reconstructedEventsCount');
148148
expect(firstReconstructedEventsCounts).to.have.all.deep.ordered.members(firstReconstructedEventsCounts.sort());
149149
});
150150

@@ -162,7 +162,7 @@ module.exports = () => {
162162
await waitForTimeout(300);
163163

164164
// Expect the avgCenterOfMassEnergy to be in order
165-
const firstOutputSize = await getAllDataFields(page, 'outputSize');
165+
const firstOutputSize = await getColumnCellsInnerTexts(page, 'outputSize');
166166
expect(firstOutputSize).to.have.all.deep.ordered.members(firstOutputSize.sort());
167167
});
168168

@@ -177,15 +177,15 @@ module.exports = () => {
177177

178178
await waitForTimeout(100);
179179

180-
let allDataPassesNames = await getAllDataFields(page, 'name');
180+
let allDataPassesNames = await getColumnCellsInnerTexts(page, 'name');
181181
expect(allDataPassesNames).to.has.all.deep.members(['LHC22b_apass1']);
182182

183183
const resetFiltersButton = await page.$('#reset-filters');
184184
expect(resetFiltersButton).to.not.be.null;
185185
await resetFiltersButton.evaluate((button) => button.click());
186186
await waitForTimeout(100);
187187

188-
allDataPassesNames = await getAllDataFields(page, 'name');
188+
allDataPassesNames = await getColumnCellsInnerTexts(page, 'name');
189189
expect(allDataPassesNames).to.has.all.deep.members(['LHC22b_apass1', 'LHC22b_apass2']);
190190
});
191191
};

test/public/defaults.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -256,22 +256,18 @@ module.exports.getFirstRow = async (table, page) => {
256256
};
257257

258258
/**
259-
* Special method built to gather all currently visible table entities from a specific column into an array
260-
* @param {Object} page An object representing the browser page being used by Puppeteer
261-
* @param {string} key The key for the column to gather entities of
262-
* @return {Promise<Array>} An array containing all table entities of a column, in the order displayed by the browser
263-
*/
264-
module.exports.getAllDataFields = async (page, key) => {
265-
const allData = await page.$$('td');
266-
return await allData.reduce(async (accumulator, data) => {
267-
const id = await page.evaluate((element) => element.id, data);
268-
if (id.endsWith(`-${key}`)) {
269-
const text = await page.evaluate((element) => element.innerText, data);
270-
(await accumulator).push(text);
271-
}
272-
return accumulator;
273-
}, []);
274-
};
259+
* Return the inner text of all the cells of a given column of the first table found in the page
260+
*
261+
* @param {puppeteer.Page} page the puppeteer page
262+
* @param {string} key the key of the column from which data must be retrieved
263+
* @return {Promise<string[]>} resolves with the list of all cells inner texts
264+
*/
265+
const getColumnCellsInnerTexts = async (page, key) => page.$$eval(
266+
`table tbody .column-${key}`,
267+
(cells) => cells.map((cell) => cell.innerText),
268+
);
269+
270+
module.exports.getColumnCellsInnerTexts = getColumnCellsInnerTexts;
275271

276272
/**
277273
* Evaluate and return the text content of a given element handler
@@ -498,24 +494,24 @@ module.exports.testTableSortingByColumn = async (page, columnId) => {
498494
const sortingPreviewIndicator = await page.$(`#${columnId}-sort-preview`);
499495
expect(Boolean(sortingPreviewIndicator)).to.be.true;
500496

501-
const notOrderData = await this.getAllDataFields(page, columnId);
497+
const notOrderData = await getColumnCellsInnerTexts(page, columnId);
502498

503499
// Sort in ASCENDING manner
504500
await this.waitForTableDataReload(page, () => this.pressElement(`th#${columnId}`));
505501

506-
let targetColumnValues = await this.getAllDataFields(page, columnId);
502+
let targetColumnValues = await getColumnCellsInnerTexts(page, columnId);
507503
expect(targetColumnValues, `Too few values for ${columnId} column or there is no such column`).to.be.length.greaterThan(1);
508504
expect(targetColumnValues).to.have.all.deep.ordered.members(targetColumnValues.sort());
509505

510506
// Sort in DESCSENDING manner
511507
await this.waitForTableDataReload(page, () => this.pressElement(`th#${columnId}`));
512508

513-
targetColumnValues = await this.getAllDataFields(page, columnId);
509+
targetColumnValues = await getColumnCellsInnerTexts(page, columnId);
514510
expect(targetColumnValues, `Too few values for ${columnId} column or there is no such column`).to.be.length.greaterThan(1);
515511
expect(targetColumnValues).to.have.all.deep.ordered.members(targetColumnValues.sort().reverse());
516512

517513
// Revoke sorting
518-
targetColumnValues = await this.getAllDataFields(page, columnId);
514+
targetColumnValues = await getColumnCellsInnerTexts(page, columnId);
519515
expect(targetColumnValues).to.have.all.ordered.members(notOrderData);
520516
};
521517

@@ -529,7 +525,7 @@ module.exports.testTableSortingByColumn = async (page, columnId) => {
529525
module.exports.validateTableData = async (page, validators) => {
530526
await page.waitForSelector('table tbody');
531527
for (const [columnId, validator] of validators) {
532-
const columnData = await this.getAllDataFields(page, columnId);
528+
const columnData = await getColumnCellsInnerTexts(page, columnId);
533529
expect(columnData, `Too few values for column ${columnId} or there is no such column`).to.be.length.greaterThan(0);
534530
expect(
535531
columnData.every((cellData) => validator(cellData)),

test/public/lhcPeriods/overview.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const {
1616
defaultBefore,
1717
defaultAfter,
1818
goToPage,
19-
getAllDataFields,
19+
getColumnCellsInnerTexts,
2020
fillInput,
2121
} = require('../defaults');
2222
const { waitForTimeout } = require('../defaults.js');
@@ -145,7 +145,7 @@ module.exports = () => {
145145
await waitForTimeout(300);
146146

147147
// Expect the names to be in alphabetical order
148-
const firstNames = await getAllDataFields(page, 'name');
148+
const firstNames = await getColumnCellsInnerTexts(page, 'name');
149149
expect(firstNames).to.have.all.deep.ordered.members(firstNames.sort());
150150
});
151151

@@ -163,7 +163,7 @@ module.exports = () => {
163163
await waitForTimeout(300);
164164

165165
// Expect the year to be in order
166-
const firstYears = await getAllDataFields(page, 'year');
166+
const firstYears = await getColumnCellsInnerTexts(page, 'year');
167167
expect(firstYears).to.have.all.deep.ordered.members(firstYears.sort());
168168
});
169169

@@ -181,7 +181,7 @@ module.exports = () => {
181181
await waitForTimeout(300);
182182

183183
// Expect the avgCenterOfMassEnergy to be in order
184-
const firstAvgCeneterOfMassEnergies = await getAllDataFields(page, 'avgCenterOfMassEnergy');
184+
const firstAvgCeneterOfMassEnergies = await getColumnCellsInnerTexts(page, 'avgCenterOfMassEnergy');
185185
expect(firstAvgCeneterOfMassEnergies).to.have.all.deep.ordered.members(firstAvgCeneterOfMassEnergies.sort());
186186
});
187187

@@ -196,15 +196,15 @@ module.exports = () => {
196196

197197
await waitForTimeout(100);
198198

199-
let allLhcPeriodNameCellsContent = await getAllDataFields(page, 'name');
199+
let allLhcPeriodNameCellsContent = await getColumnCellsInnerTexts(page, 'name');
200200
expect(allLhcPeriodNameCellsContent).to.has.all.deep.members(['LHC22a']);
201201

202202
const resetFiltersButton = await page.$('#reset-filters');
203203
expect(resetFiltersButton).to.not.be.null;
204204
await resetFiltersButton.evaluate((button) => button.click());
205205
await waitForTimeout(100);
206206

207-
allLhcPeriodNameCellsContent = await getAllDataFields(page, 'name');
207+
allLhcPeriodNameCellsContent = await getColumnCellsInnerTexts(page, 'name');
208208
expect(allLhcPeriodNameCellsContent).to.has.all.deep.members(['LHC22a', 'LHC22b', 'LHC23f']);
209209
});
210210

@@ -219,7 +219,7 @@ module.exports = () => {
219219

220220
await waitForTimeout(100);
221221

222-
const allLhcPeriodYears = await getAllDataFields(page, 'year');
222+
const allLhcPeriodYears = await getColumnCellsInnerTexts(page, 'year');
223223
expect([...new Set(allLhcPeriodYears)]).to.has.all.members(['2022']);
224224
});
225225

@@ -234,7 +234,7 @@ module.exports = () => {
234234

235235
await waitForTimeout(100);
236236

237-
const allLhcPeriodBeamTypes = await getAllDataFields(page, 'beamTypes');
237+
const allLhcPeriodBeamTypes = await getColumnCellsInnerTexts(page, 'beamTypes');
238238
expect([...new Set(allLhcPeriodBeamTypes)]).to.has.all.members(['XeXe']);
239239
});
240240
};

test/public/logs/overview.test.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ const {
1919
pressElement,
2020
goToPage,
2121
getFirstRow,
22-
getAllDataFields,
22+
getColumnCellsInnerTexts,
2323
checkColumnBalloon,
2424
} = require('../defaults');
25-
const { reloadPage, waitForNetworkIdleAndRedraw, fillInput, getInnerText, getPopoverSelector, waitForTimeout } = require('../defaults.js');
25+
const {
26+
reloadPage,
27+
waitForNetworkIdleAndRedraw,
28+
fillInput,
29+
getInnerText,
30+
getPopoverSelector,
31+
waitForTimeout,
32+
waitForTableDataReload,
33+
} = require('../defaults.js');
2634

2735
const { expect } = chai;
2836

@@ -204,7 +212,32 @@ module.exports = () => {
204212
expect(unfilteredNumberOfRows).to.equal(originalNumberOfRows);
205213
});
206214

215+
it('should successfully provide an easy to access button to filter in/out anonymous logs', async () => {
216+
await reloadPage(page);
217+
{
218+
const authors = await getColumnCellsInnerTexts(page, 'author');
219+
expect(authors.some((author) => author === 'Anonymous')).to.be.true;
220+
}
221+
222+
await waitForTableDataReload(page, () => pressElement(page, '#main-action-bar > div:nth-child(1) .switch'));
223+
224+
{
225+
const authors = await getColumnCellsInnerTexts(page, 'author');
226+
expect(authors.every((author) => author !== 'Anonymous')).to.be.true;
227+
}
228+
229+
await waitForTableDataReload(page, () => pressElement(page, '#main-action-bar > div:nth-child(1) .switch'));
230+
231+
{
232+
const authors = await getColumnCellsInnerTexts(page, 'author');
233+
expect(authors.some((author) => author === 'Anonymous')).to.be.true;
234+
}
235+
});
236+
207237
it('can filter by creation date', async () => {
238+
await pressElement(page, '#openFilterToggle');
239+
await waitForTimeout(20);
240+
208241
// Increase the amount of items displayed to see logs count difference above 10
209242
await page.evaluate(() => {
210243
// eslint-disable-next-line no-undef
@@ -509,7 +542,7 @@ module.exports = () => {
509542
await waitForTimeout(300);
510543

511544
// Expect the log titles to be in alphabetical order
512-
const firstTitles = await getAllDataFields(page, 'title');
545+
const firstTitles = await getColumnCellsInnerTexts(page, 'title');
513546
expect(firstTitles).to.deep.equal(firstTitles.sort());
514547
// Hover something else to have title sort displayed
515548
await page.hover('th#author');
@@ -522,15 +555,15 @@ module.exports = () => {
522555
await waitForTimeout(300);
523556

524557
// Expect the log titles to be in reverse alphabetical order
525-
const secondTitles = await getAllDataFields(page, 'title');
558+
const secondTitles = await getColumnCellsInnerTexts(page, 'title');
526559
expect(secondTitles).to.deep.equal(secondTitles.sort((a, b) => b.localeCompare(a)));
527560

528561
// Toggle to clear this sorting
529562
await titleHeader.evaluate((button) => button.click());
530563
await waitForTimeout(300);
531564

532565
// Expect the log titles to no longer be sorted in any way
533-
const thirdTitles = await getAllDataFields(page, 'title');
566+
const thirdTitles = await getColumnCellsInnerTexts(page, 'title');
534567
expect(thirdTitles).to.not.deep.equal(firstTitles);
535568
expect(thirdTitles).to.not.deep.equal(secondTitles);
536569

@@ -540,7 +573,7 @@ module.exports = () => {
540573
await waitForTimeout(300);
541574

542575
// Expect the authors to be in alphabetical order
543-
const firstAuthors = await getAllDataFields(page, 'author');
576+
const firstAuthors = await getColumnCellsInnerTexts(page, 'author');
544577
expect(firstAuthors).to.deep.equal(firstAuthors.sort());
545578

546579
// Sort by creation date in ascending manner
@@ -549,7 +582,7 @@ module.exports = () => {
549582
await waitForTimeout(300);
550583

551584
// Expect the log author column to be unsorted
552-
const secondAuthors = await getAllDataFields(page, 'author');
585+
const secondAuthors = await getColumnCellsInnerTexts(page, 'author');
553586
expect(secondAuthors).to.not.deep.equal(firstAuthors);
554587
});
555588

test/public/simulationPasses/overviewAnchoredSimulationPasses.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const {
1616
defaultBefore,
1717
defaultAfter,
1818
goToPage,
19-
getAllDataFields,
19+
getColumnCellsInnerTexts,
2020
fillInput,
2121
waitForTableDataReload,
2222
validateTableData,
@@ -115,12 +115,12 @@ module.exports = () => {
115115
await pressElement(page, '#openFilterToggle');
116116
await waitForTableDataReload(page, () => fillInput(page, '.name-filter input[type=text]', 'LHC23k6a'));
117117

118-
let allDataPassesNames = await getAllDataFields(page, 'name');
118+
let allDataPassesNames = await getColumnCellsInnerTexts(page, 'name');
119119
expect(allDataPassesNames).to.has.all.deep.members(['LHC23k6a']);
120120

121121
await waitForTableDataReload(page, () => fillInput(page, '.name-filter input[type=text]', 'LHC23k6a, LHC23k6b'));
122122

123-
allDataPassesNames = await getAllDataFields(page, 'name');
123+
allDataPassesNames = await getColumnCellsInnerTexts(page, 'name');
124124
expect(allDataPassesNames).to.has.all.deep.members(['LHC23k6a', 'LHC23k6b']);
125125
});
126126
};

0 commit comments

Comments
 (0)