1
1
import { BrowserContext , expect , Locator , Page } from "@playwright/test" ;
2
- import { backpageHeader , TabDescription } from "./testInterfaces" ;
2
+ import {
3
+ BackpageHeader ,
4
+ ColumnDescription ,
5
+ TabDescription ,
6
+ } from "./testInterfaces" ;
3
7
4
8
/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
5
9
@@ -471,9 +475,7 @@ export async function testExportBackpage(
471
475
await expect ( firstButtonLocator ) . toBeEnabled ( ) ;
472
476
// Select all checkboxes on the pages
473
477
const checkboxLocators = await page . getByRole ( "checkbox" ) . all ( ) ;
474
- console . log ( checkboxLocators ) ;
475
478
for ( const checkboxLocator of checkboxLocators ) {
476
- console . log ( checkboxLocator ) ;
477
479
if ( ! ( await checkboxLocator . isChecked ( ) ) ) {
478
480
await checkboxLocator . click ( ) ;
479
481
await expect ( checkboxLocator ) . toBeChecked ( ) ;
@@ -570,13 +572,43 @@ export async function testBackpageAccess(
570
572
) . toBeVisible ( ) ;
571
573
}
572
574
575
+ const hoverAndGetText = async (
576
+ page : Page ,
577
+ columnDescription : ColumnDescription | undefined ,
578
+ rowPosition : number ,
579
+ columnPosition : number
580
+ ) : Promise < string > => {
581
+ const cellLocator = getNthElementTextLocator (
582
+ page ,
583
+ rowPosition ,
584
+ columnPosition
585
+ ) ;
586
+ const cellText = await cellLocator . innerText ( ) ;
587
+
588
+ if (
589
+ columnDescription != undefined &&
590
+ columnDescription . pluralizedLabel != undefined &&
591
+ RegExp ( "\\s*[0-9]+ " + columnDescription . pluralizedLabel + "\\s*" ) . test (
592
+ cellText
593
+ )
594
+ ) {
595
+ await cellLocator . locator ( "*" ) . last ( ) . hover ( ) ;
596
+ await page . getByRole ( "tooltip" ) . waitFor ( ) ;
597
+ const outputText = ( await page . getByRole ( "tooltip" ) . innerText ( ) ) . trim ( ) ;
598
+ await page . getByRole ( "columnheader" ) . first ( ) . hover ( ) ;
599
+ await expect ( page . getByRole ( "tooltip" ) ) . toHaveCount ( 0 ) ;
600
+ return outputText ;
601
+ }
602
+ return cellText . trim ( ) ;
603
+ } ;
604
+
573
605
export async function testBackpageDetails (
574
606
page : Page ,
575
607
tab : TabDescription
576
608
) : Promise < void > {
577
609
if ( tab . backpageHeaders == null ) {
578
610
await expect ( false ) ;
579
- return ; // This is unreachable, but typescript doesn't know without it
611
+ return ; // This is unreachable due to the expect , but typescript doesn't know
580
612
}
581
613
await page . goto ( tab . url ) ;
582
614
// Enable test columns
@@ -585,33 +617,39 @@ export async function testBackpageDetails(
585
617
const combinedColumns = tab . preselectedColumns . concat ( tab . selectableColumns ) ;
586
618
const filterString = ( x : string | undefined ) : x is string => x !== undefined ;
587
619
// Get the columns that correspond with a header on the backpage details
588
- const headerCorrespondingColumns : string [ ] = tab . backpageHeaders
620
+ const backpageCorrespondingColumns : string [ ] = tab . backpageHeaders
589
621
. map ( ( header ) => header ?. correspondingColumn ?. name )
590
622
. filter ( filterString )
591
623
. map ( ( x ) => x . trim ( ) ) ;
592
624
for ( let i = 0 ; i < combinedColumns . length ; i ++ ) {
593
- const headerColumnText = (
625
+ // Get the name of the current column
626
+ const columnHeaderName = (
594
627
await page . getByRole ( "columnheader" ) . nth ( i ) . innerText ( )
595
628
) . trim ( ) ;
596
- if ( headerCorrespondingColumns . includes ( headerColumnText ) ) {
597
- const headerEntryText = await getNthElementTextLocator (
598
- page ,
599
- 1 ,
600
- i
601
- ) . innerText ( ) ;
629
+ // If the selected column has an entry on the backpage
630
+ 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)
632
+ const columnObject = combinedColumns . find (
633
+ ( x ) => x . name == columnHeaderName
634
+ ) ;
635
+ // Get the entry text
636
+ const tableEntryText = await hoverAndGetText ( page , columnObject , 0 , i ) ;
637
+ // Get the name of the corresponding header on the backpage
602
638
const correspondingHeaderName = tab . backpageHeaders . find (
603
- ( header : backpageHeader ) =>
604
- header ?. correspondingColumn ?. name === headerColumnText
639
+ ( header : BackpageHeader ) =>
640
+ header ?. correspondingColumn ?. name === columnHeaderName
605
641
) ?. name ;
606
642
if ( correspondingHeaderName === undefined ) {
607
643
// Fail the test, because this means there is an incorrect configuraiton in the tab definition
608
644
await expect ( false ) ;
609
645
return ;
610
646
}
611
- headers . push ( { header : correspondingHeaderName , value : headerEntryText } ) ;
647
+ headers . push ( { header : correspondingHeaderName , value : tableEntryText } ) ;
612
648
}
613
649
}
614
- await getNthElementTextLocator ( page , 1 , 0 ) . click ( ) ;
650
+ // Go to the backpage
651
+ await getNthElementTextLocator ( page , 0 , 0 ) . click ( ) ;
652
+ // Expect the details name to be visible
615
653
await expect (
616
654
page . getByText ( tab . backpageExportButtons ?. detailsName ?? "ERROR" )
617
655
) . toBeVisible ( ) ;
0 commit comments