1111 * or submit itself to any jurisdiction.
1212 */
1313
14+ const path = require ( 'path' ) ;
15+ const fs = require ( 'fs' ) ;
1416const chai = require ( 'chai' ) ;
1517const {
1618 defaultBefore,
@@ -26,6 +28,7 @@ const {
2628const { RunDefinition } = require ( '../../../lib/server/services/run/getRunDefinition.js' ) ;
2729const { RUN_QUALITIES , RunQualities } = require ( '../../../lib/domain/enums/RunQualities.js' ) ;
2830const { fillInput, getPopoverContent, getInnerText } = require ( '../defaults.js' ) ;
31+ const { waitForDownload } = require ( '../../utilities/waitForDownload' ) ;
2932
3033const { 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
0 commit comments