1
1
import { expect , Locator , Page } from "@playwright/test" ;
2
2
import { 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" ;
3
5
4
6
/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
5
7
@@ -1038,7 +1040,10 @@ export async function filterAndTestLastPagePagination(
1038
1040
) : Promise < boolean > {
1039
1041
// Filter to reduce the number of pages that must be selected
1040
1042
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 ( ) ;
1042
1047
await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeVisible ( ) ;
1043
1048
const filterTexts = await page
1044
1049
. getByRole ( "button" )
@@ -1069,25 +1074,41 @@ export async function filterAndTestLastPagePagination(
1069
1074
return false ;
1070
1075
}
1071
1076
const minFilterValue = Math . min ( ...validFilterCounts ) ;
1077
+
1078
+ const results = await page
1079
+ . getByTestId ( TEST_IDS . TABLE_PAGINATION_RESULTS )
1080
+ . textContent ( ) ;
1081
+
1072
1082
await page
1073
1083
. getByRole ( "button" )
1074
1084
. filter ( { hasText : RegExp ( `${ minFilterValue } [\\s]*$` ) } )
1075
1085
. 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 ) ;
1078
1095
1079
1096
// Should start on first page, and there should be multiple pages available
1080
1097
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 } )
1082
1101
) . toHaveText ( / P a g e 1 o f \d + / ) ;
1083
1102
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 } )
1085
1106
) . not . toHaveText ( "Page 1 of 1" ) ;
1086
1107
1087
1108
// Detect number of pages
1088
1109
const splitStartingPageText = (
1089
1110
await page
1090
- . locator ( ".MuiPaper-table" )
1111
+ . getByTestId ( TEST_IDS . TABLE_PAGINATION_PAGE )
1091
1112
. getByText ( PAGE_COUNT_REGEX , { exact : true } )
1092
1113
. innerText ( )
1093
1114
) . split ( " " ) ;
@@ -1098,30 +1119,37 @@ export async function filterAndTestLastPagePagination(
1098
1119
for ( let i = 2 ; i < maxPages + 1 ; i ++ ) {
1099
1120
// (dispatchevent necessary because the filter menu sometimes interrupts the click event)
1100
1121
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 ( )
1103
1125
. dispatchEvent ( "click" ) ;
1104
1126
await expect ( getFirstRowNthColumnCellLocator ( page , 0 ) ) . toBeVisible ( ) ;
1105
1127
// 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 } ` ) ;
1109
1133
}
1110
1134
// 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 } ` ) ;
1114
1140
// Expect the back button to be enabled on the last page
1115
1141
await expect (
1116
1142
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 ( )
1119
1146
) . toBeEnabled ( ) ;
1120
1147
// Expect the forward button to be disabled
1121
1148
await expect (
1122
1149
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 ( )
1125
1153
) . toBeDisabled ( ) ;
1126
1154
return true ;
1127
1155
}
@@ -1142,7 +1170,9 @@ export async function testPaginationContent(
1142
1170
"true"
1143
1171
) ;
1144
1172
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 ) ;
1146
1176
1147
1177
// Should start on first page
1148
1178
await expect ( page . getByText ( PAGE_COUNT_REGEX , { exact : true } ) ) . toHaveText (
@@ -1158,8 +1188,9 @@ export async function testPaginationContent(
1158
1188
// Click the next button
1159
1189
// dispatchEvent necessary because the table loading component sometimes interrupts a click event
1160
1190
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 ( )
1163
1194
. dispatchEvent ( "click" ) ;
1164
1195
// Expect the page count to have incremented
1165
1196
await expect ( page . getByText ( PAGE_COUNT_REGEX , { exact : true } ) ) . toHaveText (
@@ -1168,15 +1199,17 @@ export async function testPaginationContent(
1168
1199
// Expect the back button to be enabled
1169
1200
await expect (
1170
1201
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 ( )
1173
1205
) . toBeEnabled ( ) ;
1174
1206
// Expect the forwards button to be enabled
1175
1207
if ( i != maxPages ) {
1176
1208
await expect (
1177
1209
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 ( )
1180
1213
) . toBeEnabled ( ) ;
1181
1214
}
1182
1215
// Expect the first entry to have changed on the new page
@@ -1191,9 +1224,11 @@ export async function testPaginationContent(
1191
1224
for ( let i = 0 ; i < maxPages - 1 ; i ++ ) {
1192
1225
const OldFirstTableEntry = FirstTableEntries [ maxPages - i - 2 ] ;
1193
1226
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 ( )
1196
1230
. click ( ) ;
1231
+ await page . getByTestId ( TEST_IDS . TABLE_PAGINATION_RESULTS ) . waitFor ( ) ;
1197
1232
// Expect page number to be correct
1198
1233
await expect ( page . getByText ( PAGE_COUNT_REGEX , { exact : true } ) ) . toHaveText (
1199
1234
RegExp ( `Page ${ maxPages - i - 1 } of \\d+` )
0 commit comments