@@ -363,7 +363,7 @@ export async function testFilterPersistence(
363363 const filterNameMatch = ( await filterToSelectLocator . innerText ( ) )
364364 . trim ( )
365365 . match ( / ^ \S * / ) ;
366- if ( filterNameMatch == null ) {
366+ if ( ! filterNameMatch ) {
367367 // This means that the selected filter did not have any non-whitespace text
368368 // associated with it, making the test impossible to complete.
369369 console . log ( "ERROR: Filter name is blank, so the test cannot continue" ) ;
@@ -542,7 +542,13 @@ export async function testClearAll(
542542 }
543543}
544544
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 =>
546552 page
547553 . getByRole ( "row" )
548554 . filter ( { has : page . getByRole ( "cell" , { name : access } ) } )
@@ -551,21 +557,29 @@ const getRowLocatorByAccess = (page: Page, access: string): Locator =>
551557 . first ( )
552558 . getByRole ( "link" ) ;
553559
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+ */
555566export async function testExportBackpage (
556567 context : BrowserContext ,
557568 page : Page ,
558569 tab : TabDescription
559570) : Promise < void > {
560- if ( tab . backpageExportButtons == null || tab . backpageAccessTags == null ) {
571+ if (
572+ tab . backpageExportButtons === undefined ||
573+ tab . backpageAccessTags === undefined
574+ ) {
561575 // Fail if this test is ran on a tab without defined backpages
562576 await expect ( false ) ;
563577 return ;
564578 }
565579 // Goto the specified tab
566580 await page . goto ( tab . url ) ;
567581 // Expect to find row with a granted status indicator
568- const grantedRowLocator = getRowLocatorByAccess (
582+ const grantedRowLocator = getBackpageLinkLocatorByAccess (
569583 page ,
570584 tab . backpageAccessTags . grantedShortName
571585 ) ;
@@ -583,34 +597,41 @@ export async function testExportBackpage(
583597 . click ( ) ;
584598 await expect ( page ) . toHaveURL ( tab . backpageExportButtons . exportUrlRegExp ) ;
585599 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 ,
588602 } ) ;
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 } ) ;
598612 }
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
601614 for ( const tableLocator of await page . getByRole ( "table" ) . all ( ) ) {
602- const checkboxLocatorsInTable = await tableLocator
615+ const allInTableCheckboxLocators = await tableLocator
603616 . getByRole ( "checkbox" )
604617 . 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 ( ) ;
609630 }
610631 }
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 ( ) ;
614635 await expect (
615636 page . getByText ( tab . backpageExportButtons . firstLoadingMessage , {
616637 exact : true ,
@@ -621,33 +642,42 @@ export async function testExportBackpage(
621642 exact : true ,
622643 } )
623644 ) . 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 ,
626647 } ) ;
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
629650 const newPagePromise = context . waitForEvent ( "page" ) ;
630- await secondButtonLocator . click ( ) ;
651+ await exportActionButtonLocator . click ( ) ;
631652 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
633654 await expect (
634655 newPage . getByText ( tab . backpageExportButtons ?. newTabMessage )
635656 ) . toBeVisible ( ) ;
636657}
637658
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+ */
638665export async function testBackpageAccess (
639666 page : Page ,
640667 tab : TabDescription
641668) : Promise < void > {
642- if ( tab . backpageExportButtons == null || tab . backpageAccessTags == null ) {
669+ if (
670+ tab . backpageExportButtons === undefined ||
671+ tab . backpageAccessTags === undefined
672+ ) {
643673 // Fail if this test is ran on a tab without defined backpages
644674 await expect ( false ) ;
645675 return ;
646676 }
647677 // Goto the specified tab
648678 await page . goto ( tab . url ) ;
649679 // Check that the first "Granted" tab has access granted
650- const grantedRowLocator = getRowLocatorByAccess (
680+ const grantedRowLocator = getBackpageLinkLocatorByAccess (
651681 page ,
652682 tab . backpageAccessTags . grantedShortName
653683 ) ;
@@ -667,13 +697,13 @@ export async function testBackpageAccess(
667697 await expect ( page ) . toHaveURL ( tab . backpageExportButtons . exportUrlRegExp ) ;
668698 await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeVisible ( ) ;
669699 const requestLinkButtonLocator = page . getByRole ( "button" , {
670- name : tab . backpageExportButtons . firstButtonName ,
700+ name : tab . backpageExportButtons . exportRequestButtonText ,
671701 } ) ;
672702 await expect ( requestLinkButtonLocator ) . toBeEnabled ( ) ;
673703 // Go back to the table page
674704 await page . getByRole ( "link" , { name : tab . tabName } ) . click ( ) ;
675705 // Check that the first "Required" tab does not have access granted
676- const deniedRowLocator = getRowLocatorByAccess (
706+ const deniedRowLocator = getBackpageLinkLocatorByAccess (
677707 page ,
678708 tab . backpageAccessTags . deniedShortName
679709 ) ;
@@ -695,6 +725,15 @@ export async function testBackpageAccess(
695725 ) . toBeVisible ( ) ;
696726}
697727
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+ */
698737const hoverAndGetText = async (
699738 page : Page ,
700739 columnDescription : ColumnDescription | undefined ,
@@ -709,8 +748,8 @@ const hoverAndGetText = async (
709748 const cellText = await cellLocator . innerText ( ) ;
710749 // Check if the cell appears to be an Ntag cell
711750 if (
712- columnDescription != undefined &&
713- columnDescription . pluralizedLabel != undefined &&
751+ ! columnDescription != = undefined &&
752+ columnDescription ? .pluralizedLabel != = undefined &&
714753 RegExp ( "\\s*[0-9]+ " + columnDescription . pluralizedLabel + "\\s*" ) . test (
715754 cellText
716755 )
@@ -729,11 +768,19 @@ const hoverAndGetText = async (
729768 return cellText . trim ( ) ;
730769} ;
731770
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+ */
732776export async function testBackpageDetails (
733777 page : Page ,
734778 tab : TabDescription
735779) : Promise < void > {
736- if ( tab . backpageHeaders == null || tab . backpageExportButtons == null ) {
780+ if (
781+ tab . backpageHeaders === undefined ||
782+ tab . backpageExportButtons === undefined
783+ ) {
737784 // If the tab is not set up with backpage info, fail the test
738785 await expect ( false ) ;
739786 return ;
@@ -767,8 +814,8 @@ export async function testBackpageDetails(
767814 ( header : BackpageHeader ) =>
768815 header ?. correspondingColumn ?. name === columnHeaderName
769816 ) ?. 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
772819 await expect ( false ) ;
773820 return ;
774821 }
0 commit comments