11import { expect , Locator , Page } from "@playwright/test" ;
22import { ColumnDescription , TabDescription } from "./testInterfaces" ;
3+ import { TEST_IDS } from "@databiosphere/findable-ui/lib/tests/testIds" ;
4+ import { KEYBOARD_KEYS , MUI_CLASSES } from "./features/common/constants" ;
35
46/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
57
@@ -1038,7 +1040,10 @@ export async function filterAndTestLastPagePagination(
10381040) : Promise < boolean > {
10391041 // Filter to reduce the number of pages that must be selected
10401042 await page . goto ( tab . url ) ;
1041- await page . getByText ( filterRegex ( filterName ) ) . click ( ) ;
1043+ await page
1044+ . getByTestId ( TEST_IDS . FILTERS )
1045+ . getByText ( filterRegex ( filterName ) )
1046+ . click ( ) ;
10421047 await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeVisible ( ) ;
10431048 const filterTexts = await page
10441049 . getByRole ( "button" )
@@ -1069,25 +1074,41 @@ export async function filterAndTestLastPagePagination(
10691074 return false ;
10701075 }
10711076 const minFilterValue = Math . min ( ...validFilterCounts ) ;
1077+
1078+ const results = await page
1079+ . getByTestId ( TEST_IDS . TABLE_PAGINATION_RESULTS )
1080+ . textContent ( ) ;
1081+
10721082 await page
10731083 . getByRole ( "button" )
10741084 . filter ( { hasText : RegExp ( `${ minFilterValue } [\\s]*$` ) } )
10751085 . click ( ) ;
1076- await page . locator ( "body" ) . click ( ) ;
1077- await expect ( getFirstRowNthColumnCellLocator ( page , 0 ) ) . toBeVisible ( ) ;
1086+
1087+ await expect
1088+ . poll (
1089+ async ( ) =>
1090+ await page . getByTestId ( TEST_IDS . TABLE_PAGINATION_RESULTS ) . textContent ( )
1091+ )
1092+ . not . toEqual ( results ) ;
1093+
1094+ await page . keyboard . press ( KEYBOARD_KEYS . ESCAPE ) ;
10781095
10791096 // Should start on first page, and there should be multiple pages available
10801097 await expect (
1081- page . locator ( ".MuiPaper-table" ) . getByText ( PAGE_COUNT_REGEX , { exact : true } )
1098+ page
1099+ . getByTestId ( TEST_IDS . TABLE_PAGINATION_PAGE )
1100+ . getByText ( PAGE_COUNT_REGEX , { exact : true } )
10821101 ) . toHaveText ( / P a g e 1 o f \d + / ) ;
10831102 await expect (
1084- page . locator ( ".MuiPaper-table" ) . getByText ( PAGE_COUNT_REGEX , { exact : true } )
1103+ page
1104+ . getByTestId ( TEST_IDS . TABLE_PAGINATION_PAGE )
1105+ . getByText ( PAGE_COUNT_REGEX , { exact : true } )
10851106 ) . not . toHaveText ( "Page 1 of 1" ) ;
10861107
10871108 // Detect number of pages
10881109 const splitStartingPageText = (
10891110 await page
1090- . locator ( ".MuiPaper-table" )
1111+ . getByTestId ( TEST_IDS . TABLE_PAGINATION_PAGE )
10911112 . getByText ( PAGE_COUNT_REGEX , { exact : true } )
10921113 . innerText ( )
10931114 ) . split ( " " ) ;
@@ -1098,30 +1119,37 @@ export async function filterAndTestLastPagePagination(
10981119 for ( let i = 2 ; i < maxPages + 1 ; i ++ ) {
10991120 // (dispatchevent necessary because the filter menu sometimes interrupts the click event)
11001121 await page
1101- . getByRole ( "button" )
1102- . filter ( { has : page . getByTestId ( FORWARD_BUTTON_TEST_ID ) } )
1122+ . getByTestId ( TEST_IDS . TABLE_PAGINATION )
1123+ . locator ( MUI_CLASSES . ICON_BUTTON )
1124+ . last ( )
11031125 . dispatchEvent ( "click" ) ;
11041126 await expect ( getFirstRowNthColumnCellLocator ( page , 0 ) ) . toBeVisible ( ) ;
11051127 // Expect the page count to have incremented
1106- await expect ( page . getByText ( PAGE_COUNT_REGEX , { exact : true } ) ) . toHaveText (
1107- `Page ${ i } of ${ maxPages } `
1108- ) ;
1128+ await expect (
1129+ page
1130+ . getByTestId ( TEST_IDS . TABLE_PAGINATION_PAGE )
1131+ . getByText ( PAGE_COUNT_REGEX , { exact : true } )
1132+ ) . toHaveText ( `Page ${ i } of ${ maxPages } ` ) ;
11091133 }
11101134 // Expect to be on the last page
1111- await expect ( page . getByText ( PAGE_COUNT_REGEX , { exact : true } ) ) . toContainText (
1112- `Page ${ maxPages } of ${ maxPages } `
1113- ) ;
1135+ await expect (
1136+ page
1137+ . getByTestId ( TEST_IDS . TABLE_PAGINATION_PAGE )
1138+ . getByText ( PAGE_COUNT_REGEX , { exact : true } )
1139+ ) . toContainText ( `Page ${ maxPages } of ${ maxPages } ` ) ;
11141140 // Expect the back button to be enabled on the last page
11151141 await expect (
11161142 page
1117- . getByRole ( "button" )
1118- . filter ( { has : page . getByTestId ( BACK_BUTTON_TEST_ID ) } )
1143+ . getByTestId ( TEST_IDS . TABLE_PAGINATION )
1144+ . locator ( MUI_CLASSES . ICON_BUTTON )
1145+ . first ( )
11191146 ) . toBeEnabled ( ) ;
11201147 // Expect the forward button to be disabled
11211148 await expect (
11221149 page
1123- . getByRole ( "button" )
1124- . filter ( { has : page . getByTestId ( FORWARD_BUTTON_TEST_ID ) } )
1150+ . getByTestId ( TEST_IDS . TABLE_PAGINATION )
1151+ . locator ( MUI_CLASSES . ICON_BUTTON )
1152+ . last ( )
11251153 ) . toBeDisabled ( ) ;
11261154 return true ;
11271155}
@@ -1142,7 +1170,9 @@ export async function testPaginationContent(
11421170 "true"
11431171 ) ;
11441172
1145- const firstElementTextLocator = getFirstRowNthColumnCellLocator ( page , 0 ) ;
1173+ await page . getByTestId ( TEST_IDS . TABLE_FIRST_CELL ) . waitFor ( ) ;
1174+
1175+ const firstElementTextLocator = page . getByTestId ( TEST_IDS . TABLE_FIRST_CELL ) ;
11461176
11471177 // Should start on first page
11481178 await expect ( page . getByText ( PAGE_COUNT_REGEX , { exact : true } ) ) . toHaveText (
@@ -1158,8 +1188,9 @@ export async function testPaginationContent(
11581188 // Click the next button
11591189 // dispatchEvent necessary because the table loading component sometimes interrupts a click event
11601190 await page
1161- . getByRole ( "button" )
1162- . filter ( { has : page . getByTestId ( FORWARD_BUTTON_TEST_ID ) } )
1191+ . getByTestId ( TEST_IDS . TABLE_PAGINATION )
1192+ . locator ( MUI_CLASSES . ICON_BUTTON )
1193+ . last ( )
11631194 . dispatchEvent ( "click" ) ;
11641195 // Expect the page count to have incremented
11651196 await expect ( page . getByText ( PAGE_COUNT_REGEX , { exact : true } ) ) . toHaveText (
@@ -1168,15 +1199,17 @@ export async function testPaginationContent(
11681199 // Expect the back button to be enabled
11691200 await expect (
11701201 page
1171- . getByRole ( "button" )
1172- . filter ( { has : page . getByTestId ( BACK_BUTTON_TEST_ID ) } )
1202+ . getByTestId ( TEST_IDS . TABLE_PAGINATION )
1203+ . locator ( MUI_CLASSES . ICON_BUTTON )
1204+ . first ( )
11731205 ) . toBeEnabled ( ) ;
11741206 // Expect the forwards button to be enabled
11751207 if ( i != maxPages ) {
11761208 await expect (
11771209 page
1178- . getByRole ( "button" )
1179- . filter ( { has : page . getByTestId ( FORWARD_BUTTON_TEST_ID ) } )
1210+ . getByTestId ( TEST_IDS . TABLE_PAGINATION )
1211+ . locator ( MUI_CLASSES . ICON_BUTTON )
1212+ . last ( )
11801213 ) . toBeEnabled ( ) ;
11811214 }
11821215 // Expect the first entry to have changed on the new page
@@ -1191,9 +1224,11 @@ export async function testPaginationContent(
11911224 for ( let i = 0 ; i < maxPages - 1 ; i ++ ) {
11921225 const OldFirstTableEntry = FirstTableEntries [ maxPages - i - 2 ] ;
11931226 await page
1194- . getByRole ( "button" )
1195- . filter ( { has : page . getByTestId ( BACK_BUTTON_TEST_ID ) } )
1227+ . getByTestId ( TEST_IDS . TABLE_PAGINATION )
1228+ . locator ( MUI_CLASSES . ICON_BUTTON )
1229+ . first ( )
11961230 . click ( ) ;
1231+ await page . getByTestId ( TEST_IDS . TABLE_PAGINATION_RESULTS ) . waitFor ( ) ;
11971232 // Expect page number to be correct
11981233 await expect ( page . getByText ( PAGE_COUNT_REGEX , { exact : true } ) ) . toHaveText (
11991234 RegExp ( `Page ${ maxPages - i - 1 } of \\d+` )
0 commit comments