@@ -363,7 +363,7 @@ export async function testFilterPersistence(
363
363
const filterNameMatch = ( await filterToSelectLocator . innerText ( ) )
364
364
. trim ( )
365
365
. match ( / ^ \S * / ) ;
366
- if ( filterNameMatch == null ) {
366
+ if ( ! filterNameMatch ) {
367
367
// This means that the selected filter did not have any non-whitespace text
368
368
// associated with it, making the test impossible to complete.
369
369
console . log ( "ERROR: Filter name is blank, so the test cannot continue" ) ;
@@ -542,7 +542,13 @@ export async function testClearAll(
542
542
}
543
543
}
544
544
545
- const getRowLocatorByAccess = ( page : Page , access : string ) : Locator =>
545
+ /**
546
+ * Get the first link to a backpage with specified backpage access
547
+ * @param page - a Playright page locator
548
+ * @param access - the string denoting the level of access desired
549
+ * @returns a Pla
550
+ */
551
+ const getBackpageLinkLocatorByAccess = ( page : Page , access : string ) : Locator =>
546
552
page
547
553
. getByRole ( "row" )
548
554
. filter ( { has : page . getByRole ( "cell" , { name : access } ) } )
@@ -551,21 +557,29 @@ const getRowLocatorByAccess = (page: Page, access: string): Locator =>
551
557
. first ( )
552
558
. getByRole ( "link" ) ;
553
559
554
- // Backpages tests
560
+ /**
561
+ * Test the export process for the specified tab
562
+ * @param context - a Playwright browser context object
563
+ * @param page - a Playwright page object
564
+ * @param tab - the tab to test on
565
+ */
555
566
export async function testExportBackpage (
556
567
context : BrowserContext ,
557
568
page : Page ,
558
569
tab : TabDescription
559
570
) : Promise < void > {
560
- if ( tab . backpageExportButtons == null || tab . backpageAccessTags == null ) {
571
+ if (
572
+ tab . backpageExportButtons === undefined ||
573
+ tab . backpageAccessTags === undefined
574
+ ) {
561
575
// Fail if this test is ran on a tab without defined backpages
562
576
await expect ( false ) ;
563
577
return ;
564
578
}
565
579
// Goto the specified tab
566
580
await page . goto ( tab . url ) ;
567
581
// Expect to find row with a granted status indicator
568
- const grantedRowLocator = getRowLocatorByAccess (
582
+ const grantedRowLocator = getBackpageLinkLocatorByAccess (
569
583
page ,
570
584
tab . backpageAccessTags . grantedShortName
571
585
) ;
@@ -583,34 +597,41 @@ export async function testExportBackpage(
583
597
. click ( ) ;
584
598
await expect ( page ) . toHaveURL ( tab . backpageExportButtons . exportUrlRegExp ) ;
585
599
await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeVisible ( ) ;
586
- const firstButtonLocator = page . getByRole ( "button" , {
587
- name : tab . backpageExportButtons . firstButtonName ,
600
+ const exportRequestButtonLocator = page . getByRole ( "button" , {
601
+ name : tab . backpageExportButtons . exportRequestButtonText ,
588
602
} ) ;
589
- await expect ( firstButtonLocator ) . toBeEnabled ( ) ;
590
- // Select all checkboxes on the pages
591
- const checkboxLocators = await page . getByRole ( "checkbox" ) . all ( ) ;
592
- for ( const checkboxLocator of checkboxLocators ) {
593
- if ( ! ( await checkboxLocator . isChecked ( ) ) ) {
594
- await checkboxLocator . click ( ) ;
595
- await expect ( checkboxLocator ) . toBeChecked ( ) ;
596
- await expect ( checkboxLocator ) . toBeEnabled ( { timeout : 10000 } ) ;
597
- }
603
+ await expect ( exportRequestButtonLocator ) . toBeEnabled ( ) ;
604
+ // Select all checkboxes that are not in a table
605
+ const allNonTableCheckboxLocators = await page
606
+ . locator ( "input[type='checkbox']:not(table input[type='checkbox'])" )
607
+ . all ( ) ;
608
+ for ( const checkboxLocator of allNonTableCheckboxLocators ) {
609
+ await checkboxLocator . click ( ) ;
610
+ await expect ( checkboxLocator ) . toBeChecked ( ) ;
611
+ await expect ( checkboxLocator ) . toBeEnabled ( { timeout : 10000 } ) ;
598
612
}
599
- await expect ( firstButtonLocator ) . toBeEnabled ( { timeout : 10000 } ) ;
600
- // Uncheck all checkboxes except one in each table, to reduce overhead
613
+ // Check one checkbox in each table
601
614
for ( const tableLocator of await page . getByRole ( "table" ) . all ( ) ) {
602
- const checkboxLocatorsInTable = await tableLocator
615
+ const allInTableCheckboxLocators = await tableLocator
603
616
. getByRole ( "checkbox" )
604
617
. all ( ) ;
605
- for ( const checkboxLocator of checkboxLocatorsInTable . slice ( 2 ) ) {
606
- await checkboxLocator . click ( ) ;
607
- await expect ( checkboxLocator ) . not . toBeChecked ( ) ;
608
- await expect ( checkboxLocator ) . toBeEnabled ( { timeout : 10000 } ) ;
618
+ const secondCheckboxInTableLocator = allInTableCheckboxLocators [ 1 ] ;
619
+ await secondCheckboxInTableLocator . click ( ) ;
620
+ await expect ( secondCheckboxInTableLocator ) . toBeChecked ( ) ;
621
+ await expect ( secondCheckboxInTableLocator ) . toBeEnabled ( { timeout : 10000 } ) ;
622
+ const otherInTableCheckboxLocators = [
623
+ allInTableCheckboxLocators [ 0 ] ,
624
+ ...allInTableCheckboxLocators . slice ( 2 ) ,
625
+ ] ;
626
+ // Make sure that no other checkboxes are selected
627
+ for ( const otherCheckboxLocator of otherInTableCheckboxLocators ) {
628
+ await expect ( otherCheckboxLocator ) . not . toBeChecked ( ) ;
629
+ await expect ( otherCheckboxLocator ) . toBeEnabled ( ) ;
609
630
}
610
631
}
611
- // Click the "Request Link" button
612
- await expect ( firstButtonLocator ) . toBeEnabled ( { timeout : 10000 } ) ;
613
- await firstButtonLocator . click ( ) ;
632
+ // Click the Export Request button
633
+ await expect ( exportRequestButtonLocator ) . toBeEnabled ( { timeout : 10000 } ) ;
634
+ await exportRequestButtonLocator . click ( ) ;
614
635
await expect (
615
636
page . getByText ( tab . backpageExportButtons . firstLoadingMessage , {
616
637
exact : true ,
@@ -621,33 +642,42 @@ export async function testExportBackpage(
621
642
exact : true ,
622
643
} )
623
644
) . toBeVisible ( { timeout : 60000 } ) ;
624
- const secondButtonLocator = page . getByRole ( "button" , {
625
- name : tab . backpageExportButtons ?. secondButtonName ,
645
+ const exportActionButtonLocator = page . getByRole ( "button" , {
646
+ name : tab . backpageExportButtons ?. exportActionButtonText ,
626
647
} ) ;
627
- await expect ( secondButtonLocator ) . toBeEnabled ( ) ;
628
- // Click the "Open Terra" Button and await a new browser tab
648
+ await expect ( exportActionButtonLocator ) . toBeEnabled ( ) ;
649
+ // Click the Export Action Button and await a new browser tab
629
650
const newPagePromise = context . waitForEvent ( "page" ) ;
630
- await secondButtonLocator . click ( ) ;
651
+ await exportActionButtonLocator . click ( ) ;
631
652
const newPage = await newPagePromise ;
632
- // Expect the new browser tab to look like the Terra page
653
+ // Expect the new browser tab to display the new tab content
633
654
await expect (
634
655
newPage . getByText ( tab . backpageExportButtons ?. newTabMessage )
635
656
) . toBeVisible ( ) ;
636
657
}
637
658
659
+ /**
660
+ * Test that export access is available on entries where access shows as available
661
+ * and is not on entries where access shows as unavailable
662
+ * @param page - a Playwright page objext
663
+ * @param tab - the Tab to test on
664
+ */
638
665
export async function testBackpageAccess (
639
666
page : Page ,
640
667
tab : TabDescription
641
668
) : Promise < void > {
642
- if ( tab . backpageExportButtons == null || tab . backpageAccessTags == null ) {
669
+ if (
670
+ tab . backpageExportButtons === undefined ||
671
+ tab . backpageAccessTags === undefined
672
+ ) {
643
673
// Fail if this test is ran on a tab without defined backpages
644
674
await expect ( false ) ;
645
675
return ;
646
676
}
647
677
// Goto the specified tab
648
678
await page . goto ( tab . url ) ;
649
679
// Check that the first "Granted" tab has access granted
650
- const grantedRowLocator = getRowLocatorByAccess (
680
+ const grantedRowLocator = getBackpageLinkLocatorByAccess (
651
681
page ,
652
682
tab . backpageAccessTags . grantedShortName
653
683
) ;
@@ -667,13 +697,13 @@ export async function testBackpageAccess(
667
697
await expect ( page ) . toHaveURL ( tab . backpageExportButtons . exportUrlRegExp ) ;
668
698
await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeVisible ( ) ;
669
699
const requestLinkButtonLocator = page . getByRole ( "button" , {
670
- name : tab . backpageExportButtons . firstButtonName ,
700
+ name : tab . backpageExportButtons . exportRequestButtonText ,
671
701
} ) ;
672
702
await expect ( requestLinkButtonLocator ) . toBeEnabled ( ) ;
673
703
// Go back to the table page
674
704
await page . getByRole ( "link" , { name : tab . tabName } ) . click ( ) ;
675
705
// Check that the first "Required" tab does not have access granted
676
- const deniedRowLocator = getRowLocatorByAccess (
706
+ const deniedRowLocator = getBackpageLinkLocatorByAccess (
677
707
page ,
678
708
tab . backpageAccessTags . deniedShortName
679
709
) ;
@@ -695,6 +725,15 @@ export async function testBackpageAccess(
695
725
) . toBeVisible ( ) ;
696
726
}
697
727
728
+ /**
729
+ * Get the text from a cell by reading the tooltip if it appears to be an N-tag
730
+ * cell or by reading the text if it does not appear to be
731
+ * @param page - a Playwright Page object
732
+ * @param columnDescription - a columnDescription object for the column
733
+ * @param rowPosition - the zero-indexed position of the row
734
+ * @param columnPosition - the zero-indexed position of the column
735
+ * @returns - a Promise with the cell's text
736
+ */
698
737
const hoverAndGetText = async (
699
738
page : Page ,
700
739
columnDescription : ColumnDescription | undefined ,
@@ -709,8 +748,8 @@ const hoverAndGetText = async (
709
748
const cellText = await cellLocator . innerText ( ) ;
710
749
// Check if the cell appears to be an Ntag cell
711
750
if (
712
- columnDescription != undefined &&
713
- columnDescription . pluralizedLabel != undefined &&
751
+ ! columnDescription != = undefined &&
752
+ columnDescription ? .pluralizedLabel != = undefined &&
714
753
RegExp ( "\\s*[0-9]+ " + columnDescription . pluralizedLabel + "\\s*" ) . test (
715
754
cellText
716
755
)
@@ -729,11 +768,19 @@ const hoverAndGetText = async (
729
768
return cellText . trim ( ) ;
730
769
} ;
731
770
771
+ /**
772
+ * Check that the details in the backpage sidebar match information in the data table
773
+ * @param page - a Playwright page object
774
+ * @param tab - the tab to test on
775
+ */
732
776
export async function testBackpageDetails (
733
777
page : Page ,
734
778
tab : TabDescription
735
779
) : Promise < void > {
736
- if ( tab . backpageHeaders == null || tab . backpageExportButtons == null ) {
780
+ if (
781
+ tab . backpageHeaders === undefined ||
782
+ tab . backpageExportButtons === undefined
783
+ ) {
737
784
// If the tab is not set up with backpage info, fail the test
738
785
await expect ( false ) ;
739
786
return ;
@@ -767,8 +814,8 @@ export async function testBackpageDetails(
767
814
( header : BackpageHeader ) =>
768
815
header ?. correspondingColumn ?. name === columnHeaderName
769
816
) ?. name ;
770
- if ( correspondingHeaderName == null ) {
771
- // Fail the test, because this means there is an incorrect configuraiton in the tab definition
817
+ if ( correspondingHeaderName === undefined ) {
818
+ // Fail the test, because this means there is an incorrect configuration in the tab definition
772
819
await expect ( false ) ;
773
820
return ;
774
821
}
0 commit comments