@@ -47,6 +47,25 @@ export const getFirstRowNthColumnCellLocator = (
47
47
return getMthRowNthColumnCellLocator ( page , 0 , columnIndex ) ;
48
48
} ;
49
49
50
+ /**
51
+ * Get a locator to the cell in the first row's nth column
52
+ * @param page - a Playwright page object
53
+ * @param columnIndex - the zero-indexed column to return
54
+ * @returns a Playwright locator object to the selected cell
55
+ **/
56
+ export const getLastRowNthColumnTextLocator = (
57
+ page : Page ,
58
+ columnIndex : number
59
+ ) : Locator => {
60
+ return page
61
+ . getByRole ( "rowgroup" )
62
+ . nth ( 1 )
63
+ . getByRole ( "row" )
64
+ . last ( )
65
+ . getByRole ( "cell" )
66
+ . nth ( columnIndex ) ;
67
+ } ;
68
+
50
69
/**
51
70
* Tests that the tab url goes to a valid page and that the correct tab (and only
52
71
* the correct tab) appears selected
@@ -59,7 +78,9 @@ export async function testUrl(
59
78
tab : TabDescription ,
60
79
otherTabs : TabDescription [ ]
61
80
) : Promise < void > {
81
+ // Go to the selected tab
62
82
await page . goto ( tab . url ) ;
83
+ // Check that the selected tab appears selected and the other tabs appear deselected
63
84
await expect (
64
85
page . getByRole ( "tab" ) . getByText ( tab . tabName , { exact : true } )
65
86
) . toHaveAttribute ( "aria-selected" , "true" , { timeout : 25000 } ) ;
@@ -72,35 +93,36 @@ export async function testUrl(
72
93
}
73
94
}
74
95
75
- // Run the "Expect each tab to become selected, to go to the correct url, and to show all of its columns when selected" test
76
96
/**
77
97
* Checks that all preselected columns listed in the tab object are visible in the correct order
78
98
* @param page - a Playwright page object
79
- * @param tab - the tab object to test
99
+ * @param startTab - the tab object to start testing on
100
+ * @param endTab - the tab to select during the test
80
101
*/
81
- export async function testTab ( page : Page , tab : TabDescription ) : Promise < void > {
82
- await expect (
83
- page
84
- . getByRole ( "rowgroup" )
85
- . nth ( 1 )
86
- . getByRole ( "row" )
87
- . nth ( 1 )
88
- . getByRole ( "cell" )
89
- . nth ( 1 )
90
- ) . toBeVisible ( ) ;
91
- await page . getByRole ( "tab" ) . getByText ( tab . tabName , { exact : true } ) . click ( ) ;
92
- await expect ( page ) . toHaveURL ( tab . url , { timeout : 25000 } ) ; // Long timeout because some tabs take a long time to load
93
- await expect ( page . getByRole ( "tab" ) . getByText ( tab . tabName ) ) . toHaveAttribute (
102
+ export async function testTab (
103
+ page : Page ,
104
+ startTab : TabDescription ,
105
+ endTab : TabDescription
106
+ ) : Promise < void > {
107
+ // Run the "Expect each tab to become selected, to go to the correct url, and to show all of its columns when selected" test
108
+ await page . goto ( startTab . url ) ;
109
+ await expect ( getFirstRowNthColumnCellLocator ( page , 1 ) ) . toBeVisible ( ) ;
110
+ await page
111
+ . getByRole ( "tab" )
112
+ . getByText ( endTab . tabName , { exact : true } )
113
+ . click ( ) ;
114
+ await expect ( page ) . toHaveURL ( endTab . url , { timeout : 25000 } ) ; // Long timeout because some tabs take a long time to load
115
+ await expect ( page . getByRole ( "tab" ) . getByText ( endTab . tabName ) ) . toHaveAttribute (
94
116
"aria-selected" ,
95
117
"true"
96
118
) ;
97
- if ( tab . emptyFirstColumn ) {
119
+ if ( endTab . emptyFirstColumn ) {
98
120
await expect ( page . getByRole ( "columnheader" ) ) . toHaveText (
99
- [ " " ] . concat ( tab . preselectedColumns . map ( ( x ) => x . name ) )
121
+ [ " " ] . concat ( endTab . preselectedColumns . map ( ( x ) => x . name ) )
100
122
) ;
101
123
} else {
102
124
await expect ( page . getByRole ( "columnheader" ) ) . toHaveText (
103
- tab . preselectedColumns . map ( ( x ) => x . name )
125
+ endTab . preselectedColumns . map ( ( x ) => x . name )
104
126
) ;
105
127
}
106
128
}
@@ -135,21 +157,17 @@ export async function testSortAzul(
135
157
page ,
136
158
columnIndex
137
159
) ;
138
- const lastElementTextLocator = page
139
- . getByRole ( "rowgroup" )
140
- . nth ( 1 )
141
- . getByRole ( "row" )
142
- . last ( )
143
- . getByRole ( "cell" )
144
- . nth ( columnIndex ) ;
145
- // Locator for the sort button for the tab
160
+ const lastElementTextLocator = getLastRowNthColumnTextLocator (
161
+ page ,
162
+ columnIndex
163
+ ) ;
164
+ // Locator for the sort button
146
165
const columnSortLocator = page
147
166
. getByRole ( "columnheader" , {
148
167
exact : true ,
149
168
name : tab . preselectedColumns [ columnPosition ] . name ,
150
169
} )
151
170
. getByRole ( "button" ) ;
152
-
153
171
// Expect the first and last cells to be visible and have text
154
172
await expect ( firstElementTextLocator ) . toBeVisible ( ) ;
155
173
await expect ( lastElementTextLocator ) . toBeVisible ( ) ;
@@ -183,7 +201,6 @@ export async function testSortCatalog(
183
201
) : Promise < void > {
184
202
// Get the current tab, and go to it's URL
185
203
await page . goto ( tab . url ) ;
186
- // For each column
187
204
for (
188
205
let columnPosition = 0 ;
189
206
columnPosition < tab . preselectedColumns . length ;
@@ -231,10 +248,14 @@ export async function testSelectableColumns(
231
248
page : Page ,
232
249
tab : TabDescription
233
250
) : Promise < void > {
251
+ // Navigate to the tab
234
252
await page . goto ( tab . url ) ;
253
+ // Select the "Edit Columns" menu
235
254
await page . getByRole ( "button" ) . getByText ( "Edit Columns" ) . click ( ) ;
236
255
await expect ( page . getByRole ( "menu" ) ) . toBeVisible ( ) ;
256
+ // Enable each selectable tab
237
257
for ( const column of tab . selectableColumns ) {
258
+ // Locate the checkbox for each column
238
259
const checkboxLocator = page
239
260
. getByRole ( "menu" )
240
261
. locator ( "*" )
@@ -244,13 +265,16 @@ export async function testSelectableColumns(
244
265
. filter ( { has : page . getByText ( column . name , { exact : true } ) } ) ,
245
266
} )
246
267
. getByRole ( "checkbox" ) ;
268
+ // Expect each column to be enabled and unchecked for selectable tabs
247
269
await expect ( checkboxLocator ) . toBeEnabled ( ) ;
248
270
await expect ( checkboxLocator ) . not . toBeChecked ( ) ;
271
+ // Expect clicking the checkbox to function
249
272
await checkboxLocator . click ( ) ;
250
273
await expect ( checkboxLocator ) . toBeChecked ( ) ;
251
274
}
252
275
await page . getByRole ( "document" ) . click ( ) ;
253
276
await expect ( page . getByRole ( "menu" ) ) . not . toBeVisible ( ) ;
277
+ // Expect all selectable tabs to be enabled
254
278
await expect ( page . getByRole ( "columnheader" ) ) . toContainText (
255
279
tab . selectableColumns . map ( ( x ) => x . name )
256
280
) ;
@@ -516,8 +540,8 @@ export async function testClearAll(
516
540
) : Promise < void > {
517
541
await page . goto ( tab . url ) ;
518
542
const selectedFilterNamesList = [ ] ;
543
+ // Select each filter and get the names of the actual filter text
519
544
for ( const filterName of filterNames ) {
520
- // Select the passed filter names
521
545
await page . getByText ( filterRegex ( filterName ) ) . dispatchEvent ( "click" ) ;
522
546
await getFirstFilterButtonLocator ( page ) . getByRole ( "checkbox" ) . click ( ) ;
523
547
await expect (
@@ -537,6 +561,7 @@ export async function testClearAll(
537
561
page . locator ( "#sidebar-positioner" ) . getByText ( filterName )
538
562
) . toHaveCount ( 0 ) ;
539
563
}
564
+ // Ensure that the filters still show as unchecked
540
565
for ( let i = 0 ; i < filterNames . length ; i ++ ) {
541
566
await page . getByText ( filterRegex ( filterNames [ i ] ) ) . dispatchEvent ( "click" ) ;
542
567
await expect (
0 commit comments