Skip to content

Commit b594eb5

Browse files
authored
[O2B-1196] Add formatting to Data Passes view (#1466)
* format * correct test
1 parent e6531f6 commit b594eb5

2 files changed

Lines changed: 14 additions & 27 deletions

File tree

lib/public/views/DataPasses/ActiveColumns/dataPassesActiveColumns.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import { h } from '/js/src/index.js';
1515
import { textFilter } from '../../../components/Filters/common/filters/textFilter.js';
1616
import { frontLink } from '../../../components/common/navigation/frontLink.js';
17+
import { formatSizeInBytes } from '../../../utilities/formatting/formatSizeInBytes.js';
18+
import { formatItemsCount } from '../../../utilities/formatting/formatItemsCount.js';
1719

1820
/**
1921
* List of active columns for a generic data passes table
@@ -62,7 +64,7 @@ export const dataPassesActiveColumns = {
6264

6365
reconstructedEventsCount: {
6466
name: 'Reconstructed Events',
65-
format: (reconstructedEventsCount) => reconstructedEventsCount ? reconstructedEventsCount.toLocaleString('en-US') : '-',
67+
format: (reconstructedEventsCount) => reconstructedEventsCount ? formatItemsCount(reconstructedEventsCount) : '-',
6668
visible: true,
6769
sortable: true,
6870
classes: 'w-10',
@@ -71,7 +73,7 @@ export const dataPassesActiveColumns = {
7173
outputSize: {
7274
name: 'Output Size (B)',
7375
visible: true,
74-
format: (outputSize) => outputSize ? outputSize.toLocaleString('en-US') : '-',
76+
format: (outputSize) => outputSize ? formatSizeInBytes(outputSize) : '-',
7577
sortable: true,
7678
classes: 'w-10',
7779
},

test/public/dataPasses/overviewPerLhcPeriod.test.js

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const {
1919
getAllDataFields,
2020
fillInput,
2121
waitForTimeout,
22+
validateTableData,
2223
} = require('../defaults');
2324

2425
const { expect } = chai;
@@ -49,39 +50,23 @@ module.exports = () => {
4950
});
5051

5152
it('shows correct datatypes in respective columns', async () => {
52-
// Expectations of header texts being of a certain datatype
53-
const headerDatatypes = {
53+
await goToPage(page, 'data-passes-per-lhc-period-overview', { queryParameters: { lhcPeriodId: 2 } });
54+
55+
const dataSizeUnits = new Set(['B', 'KB', 'MB', 'GB', 'TB']);
56+
const tableDataValidators = {
5457
name: (name) => periodNameRegex.test(name),
5558
associatedRuns: (display) => /(No runs)|(\d+\nRuns)/.test(display),
5659
anchoredSimulationPasses: (display) => display === 'Anchored',
5760
description: (description) => /(-)|(.+)/.test(description),
5861
reconstructedEventsCount: (reconstructedEventsCount) => !isNaN(reconstructedEventsCount.replace(/,/g, ''))
5962
|| reconstructedEventsCount === '-',
60-
outputSize: (outputSize) => !isNaN(outputSize.replace(/,/g, '')) || outputSize === '-',
63+
outputSize: (outpuSize) => {
64+
const [number, unit] = outpuSize.split(' ');
65+
return !isNaN(number) && dataSizeUnits.has(unit.trim());
66+
},
6167
};
6268

63-
// We find the headers matching the datatype keys
64-
const headers = await page.$$('th');
65-
const headerIndices = {};
66-
for (const [index, header] of headers.entries()) {
67-
const headerContent = await page.evaluate((element) => element.id, header);
68-
const matchingDatatype = Object.keys(headerDatatypes).find((key) => headerContent === key);
69-
if (matchingDatatype !== undefined) {
70-
headerIndices[index] = matchingDatatype;
71-
}
72-
}
73-
74-
// We expect every value of a header matching a datatype key to actually be of that datatype
75-
76-
// Use the third row because it is where statistics are present
77-
const firstRowCells = await page.$$('tr:nth-of-type(3) td');
78-
for (const [index, cell] of firstRowCells.entries()) {
79-
if (index in headerIndices) {
80-
const cellContent = await page.evaluate((element) => element.innerText, cell);
81-
const expectedDatatype = headerDatatypes[headerIndices[index]](cellContent);
82-
expect(expectedDatatype).to.be.true;
83-
}
84-
}
69+
await validateTableData(page, new Map(Object.entries(tableDataValidators)));
8570
});
8671

8772
it('Should display the correct items counter at the bottom of the page', async () => {

0 commit comments

Comments
 (0)