@@ -19,6 +19,7 @@ const {
1919 getAllDataFields,
2020 fillInput,
2121 waitForTimeout,
22+ validateTableData,
2223} = require ( '../defaults' ) ;
2324
2425const { 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 ) => / ( N o r u n s ) | ( \d + \n R u n s ) / . 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