@@ -451,26 +451,34 @@ export async function testExportBackpage(
451
451
page : Page ,
452
452
tab : TabDescription
453
453
) : Promise < void > {
454
+ if ( tab . backpageExportButtons == null || tab . backpageAccessTags == null ) {
455
+ // Fail if this test is ran on a tab without defined backpages
456
+ await expect ( false ) ;
457
+ return ;
458
+ }
454
459
// Goto the specified tab
455
460
await page . goto ( tab . url ) ;
456
461
// Expect to find row with a granted status indicator
457
- const grantedRowLocator = getRowLocatorByAccess ( page , "Granted" ) ;
462
+ const grantedRowLocator = getRowLocatorByAccess (
463
+ page ,
464
+ tab . backpageAccessTags . grantedShortName
465
+ ) ;
458
466
await expect ( grantedRowLocator ) . toBeVisible ( ) ;
459
467
// Click into the selected row
460
- await grantedRowLocator . dispatchEvent ( "click" ) ; //TODO: this is sometimes unreliable and changes the url without changing the tab.
468
+ await grantedRowLocator . dispatchEvent ( "click" ) ;
461
469
await expect (
462
- page . getByText ( tab . backpageExportButtons ? .detailsName ?? "" )
470
+ page . getByText ( tab . backpageExportButtons . detailsName )
463
471
) . toBeVisible ( ) ;
464
472
// Click the "Export" tab
465
473
await page
466
- . getByText ( tab . backpageExportButtons ? .exportTabName ?? "ERROR" , {
474
+ . getByText ( tab . backpageExportButtons . exportTabName , {
467
475
exact : true ,
468
476
} )
469
477
. click ( ) ;
470
- await expect ( page ) . toHaveURL ( tab . backpageExportButtons ?. exportUrl ?? "" ) ;
478
+ await expect ( page ) . toHaveURL ( tab . backpageExportButtons . exportUrlRegExp ) ;
471
479
await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeVisible ( ) ;
472
480
const firstButtonLocator = page . getByRole ( "button" , {
473
- name : "Request Link" ,
481
+ name : tab . backpageExportButtons . firstButtonName ,
474
482
} ) ;
475
483
await expect ( firstButtonLocator ) . toBeEnabled ( ) ;
476
484
// Select all checkboxes on the pages
@@ -498,17 +506,17 @@ export async function testExportBackpage(
498
506
await expect ( firstButtonLocator ) . toBeEnabled ( { timeout : 10000 } ) ;
499
507
await firstButtonLocator . click ( ) ;
500
508
await expect (
501
- page . getByText ( tab . backpageExportButtons ? .firstLoadingMessage ?? "ERROR" , {
509
+ page . getByText ( tab . backpageExportButtons . firstLoadingMessage , {
502
510
exact : true ,
503
511
} )
504
512
) . toBeVisible ( ) ;
505
513
await expect (
506
- page . getByText ( tab . backpageExportButtons ? .secondLandingMessage ?? "ERROR" , {
514
+ page . getByText ( tab . backpageExportButtons . secondLandingMessage , {
507
515
exact : true ,
508
516
} )
509
517
) . toBeVisible ( { timeout : 60000 } ) ;
510
518
const secondButtonLocator = page . getByRole ( "button" , {
511
- name : tab . backpageExportButtons ?. secondButtonName ?? "ERROR" ,
519
+ name : tab . backpageExportButtons ?. secondButtonName ,
512
520
} ) ;
513
521
await expect ( secondButtonLocator ) . toBeEnabled ( ) ;
514
522
// Click the "Open Terra" Button and await a new browser tab
@@ -517,35 +525,40 @@ export async function testExportBackpage(
517
525
const newPage = await newPagePromise ;
518
526
// Expect the new browser tab to look like the Terra page
519
527
await expect (
520
- newPage . getByText ( tab . backpageExportButtons ?. newTabMessage ?? "ERROR" )
528
+ newPage . getByText ( tab . backpageExportButtons ?. newTabMessage )
521
529
) . toBeVisible ( ) ;
522
530
}
523
531
524
532
export async function testBackpageAccess (
525
533
page : Page ,
526
534
tab : TabDescription
527
535
) : Promise < void > {
528
- if ( tab . backpageExportButtons == null ) {
536
+ if ( tab . backpageExportButtons == null || tab . backpageAccessTags == null ) {
529
537
// Fail if this test is ran on a tab without defined backpages
530
538
await expect ( false ) ;
531
539
return ;
532
540
}
533
541
// Goto the specified tab
534
542
await page . goto ( tab . url ) ;
535
543
// Check that the first "Granted" tab has access granted
536
- const grantedRowLocator = getRowLocatorByAccess ( page , "Granted" ) ;
544
+ const grantedRowLocator = getRowLocatorByAccess (
545
+ page ,
546
+ tab . backpageAccessTags . grantedShortName
547
+ ) ;
537
548
await expect ( grantedRowLocator ) . toBeVisible ( ) ;
538
549
await grantedRowLocator . dispatchEvent ( "click" ) ;
539
550
await expect (
540
551
page . getByText ( tab . backpageExportButtons . detailsName )
541
552
) . toBeVisible ( ) ;
542
- await expect ( page . getByText ( "Access Granted" ) ) . toBeVisible ( ) ;
553
+ await expect (
554
+ page . getByText ( tab . backpageAccessTags . grantedLongName )
555
+ ) . toBeVisible ( ) ;
543
556
await page
544
557
. getByText ( tab . backpageExportButtons . exportTabName , {
545
558
exact : true ,
546
559
} )
547
560
. click ( ) ;
548
- await expect ( page ) . toHaveURL ( tab . backpageExportButtons . exportUrl ) ;
561
+ await expect ( page ) . toHaveURL ( tab . backpageExportButtons . exportUrlRegExp ) ;
549
562
await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeVisible ( ) ;
550
563
const requestLinkButtonLocator = page . getByRole ( "button" , {
551
564
name : tab . backpageExportButtons . firstButtonName ,
@@ -554,21 +567,25 @@ export async function testBackpageAccess(
554
567
// Go back to the table page
555
568
await page . getByRole ( "link" , { name : tab . tabName } ) . click ( ) ;
556
569
// Check that the first "Required" tab does not have access granted
557
- const requiredRowLocator = getRowLocatorByAccess ( page , "Required" ) ;
558
- await expect ( requiredRowLocator ) . toBeVisible ( ) ;
559
- await requiredRowLocator . click ( ) ;
560
- await expect ( page . getByText ( "Access Required" ) ) . toBeVisible ( ) ;
570
+ const deniedRowLocator = getRowLocatorByAccess (
571
+ page ,
572
+ tab . backpageAccessTags . deniedShortName
573
+ ) ;
574
+ await expect ( deniedRowLocator ) . toBeVisible ( ) ;
575
+ await deniedRowLocator . dispatchEvent ( "click" ) ;
576
+ await expect (
577
+ page . getByText ( tab . backpageAccessTags . deniedLongName )
578
+ ) . toBeVisible ( ) ;
561
579
await page
562
- . getByText ( tab . backpageExportButtons ? .exportTabName ?? "ERROR" , {
580
+ . getByText ( tab . backpageExportButtons . exportTabName , {
563
581
exact : true ,
564
582
} )
565
583
. click ( ) ;
566
- await expect ( page ) . toHaveURL ( tab . backpageExportButtons ?. exportUrl ?? / E R R O R / ) ;
584
+ await expect ( page ) . toHaveURL ( tab . backpageExportButtons . exportUrlRegExp ) ;
567
585
await expect (
568
- page . getByText (
569
- tab . backpageExportButtons ?. accessNotGrantedMessage ?? "ERROR" ,
570
- { exact : true }
571
- )
586
+ page . getByText ( tab . backpageExportButtons . accessNotGrantedMessage , {
587
+ exact : true ,
588
+ } )
572
589
) . toBeVisible ( ) ;
573
590
}
574
591
@@ -584,19 +601,23 @@ const hoverAndGetText = async (
584
601
columnPosition
585
602
) ;
586
603
const cellText = await cellLocator . innerText ( ) ;
587
-
604
+ // Check if the cell appears to be an Ntag cell
588
605
if (
589
606
columnDescription != undefined &&
590
607
columnDescription . pluralizedLabel != undefined &&
591
608
RegExp ( "\\s*[0-9]+ " + columnDescription . pluralizedLabel + "\\s*" ) . test (
592
609
cellText
593
610
)
594
611
) {
612
+ // Hover over the text of the NTag cell
595
613
await cellLocator . locator ( "*" ) . last ( ) . hover ( ) ;
614
+ // Read the tooltip
596
615
await page . getByRole ( "tooltip" ) . waitFor ( ) ;
597
616
const outputText = ( await page . getByRole ( "tooltip" ) . innerText ( ) ) . trim ( ) ;
617
+ // Hover over a different part of the page to ensure that the tooltip disappears
598
618
await page . getByRole ( "columnheader" ) . first ( ) . hover ( ) ;
599
619
await expect ( page . getByRole ( "tooltip" ) ) . toHaveCount ( 0 ) ;
620
+ // Return the tooltip contents
600
621
return outputText ;
601
622
}
602
623
return cellText . trim ( ) ;
@@ -606,13 +627,14 @@ export async function testBackpageDetails(
606
627
page : Page ,
607
628
tab : TabDescription
608
629
) : Promise < void > {
609
- if ( tab . backpageHeaders == null ) {
630
+ if ( tab . backpageHeaders == null || tab . backpageExportButtons == null ) {
631
+ // If the tab is not set up with backpage info, fail the test
610
632
await expect ( false ) ;
611
- return ; // This is unreachable due to the expect, but typescript doesn't know
633
+ return ;
612
634
}
613
635
await page . goto ( tab . url ) ;
614
636
// Enable test columns
615
- await testSelectableColumns ( page , tab ) ; //TODO: check if this function breaks if selectable columns don't load in order
637
+ await testSelectableColumns ( page , tab ) ;
616
638
const headers : { header : string ; value : string } [ ] = [ ] ;
617
639
const combinedColumns = tab . preselectedColumns . concat ( tab . selectableColumns ) ;
618
640
const filterString = ( x : string | undefined ) : x is string => x !== undefined ;
@@ -628,7 +650,7 @@ export async function testBackpageDetails(
628
650
) . trim ( ) ;
629
651
// If the selected column has an entry on the backpage
630
652
if ( backpageCorrespondingColumns . includes ( columnHeaderName ) ) {
631
- // Get the object of the current column (we have to do it this way, because the combinedColumn list is not ordered)
653
+ // Get the object representing the current column
632
654
const columnObject = combinedColumns . find (
633
655
( x ) => x . name == columnHeaderName
634
656
) ;
@@ -639,7 +661,7 @@ export async function testBackpageDetails(
639
661
( header : BackpageHeader ) =>
640
662
header ?. correspondingColumn ?. name === columnHeaderName
641
663
) ?. name ;
642
- if ( correspondingHeaderName === undefined ) {
664
+ if ( correspondingHeaderName == null ) {
643
665
// Fail the test, because this means there is an incorrect configuraiton in the tab definition
644
666
await expect ( false ) ;
645
667
return ;
@@ -651,7 +673,7 @@ export async function testBackpageDetails(
651
673
await getNthElementTextLocator ( page , 0 , 0 ) . click ( ) ;
652
674
// Expect the details name to be visible
653
675
await expect (
654
- page . getByText ( tab . backpageExportButtons ? .detailsName ?? "ERROR" )
676
+ page . getByText ( tab . backpageExportButtons . detailsName )
655
677
) . toBeVisible ( ) ;
656
678
for ( const headerValue of headers ) {
657
679
// Expect the correct value to be below the correct header in the dataset values table
0 commit comments