@@ -41,6 +41,25 @@ export const getFirstRowNthColumnCellLocator = (
41
41
return getMthRowNthColumnCellLocator ( page , 0 , columnIndex ) ;
42
42
} ;
43
43
44
+ /**
45
+ * Get a locator to the cell in the first row's nth column
46
+ * @param page - a Playwright page object
47
+ * @param columnIndex - the zero-indexed column to return
48
+ * @returns a Playwright locator object to the selected cell
49
+ **/
50
+ export const getLastRowNthColumnTextLocator = (
51
+ page : Page ,
52
+ columnIndex : number
53
+ ) : Locator => {
54
+ return page
55
+ . getByRole ( "rowgroup" )
56
+ . nth ( 1 )
57
+ . getByRole ( "row" )
58
+ . last ( )
59
+ . getByRole ( "cell" )
60
+ . nth ( columnIndex ) ;
61
+ } ;
62
+
44
63
/**
45
64
* Tests that the tab url goes to a valid page and that the correct tab (and only
46
65
* the correct tab) appears selected
@@ -53,7 +72,9 @@ export async function testUrl(
53
72
tab : TabDescription ,
54
73
otherTabs : TabDescription [ ]
55
74
) : Promise < void > {
75
+ // Go to the selected tab
56
76
await page . goto ( tab . url ) ;
77
+ // Check that the selected tab appears selected and the other tabs appear deselected
57
78
await expect (
58
79
page . getByRole ( "tab" ) . getByText ( tab . tabName , { exact : true } )
59
80
) . toHaveAttribute ( "aria-selected" , "true" , { timeout : 25000 } ) ;
@@ -66,35 +87,36 @@ export async function testUrl(
66
87
}
67
88
}
68
89
69
- // Run the "Expect each tab to become selected, to go to the correct url, and to show all of its columns when selected" test
70
90
/**
71
91
* Checks that all preselected columns listed in the tab object are visible in the correct order
72
92
* @param page - a Playwright page object
73
- * @param tab - the tab object to test
93
+ * @param startTab - the tab object to start testing on
94
+ * @param endTab - the tab to select during the test
74
95
*/
75
- export async function testTab ( page : Page , tab : TabDescription ) : Promise < void > {
76
- await expect (
77
- page
78
- . getByRole ( "rowgroup" )
79
- . nth ( 1 )
80
- . getByRole ( "row" )
81
- . nth ( 1 )
82
- . getByRole ( "cell" )
83
- . nth ( 1 )
84
- ) . toBeVisible ( ) ;
85
- await page . getByRole ( "tab" ) . getByText ( tab . tabName , { exact : true } ) . click ( ) ;
86
- await expect ( page ) . toHaveURL ( tab . url , { timeout : 25000 } ) ; // Long timeout because some tabs take a long time to load
87
- await expect ( page . getByRole ( "tab" ) . getByText ( tab . tabName ) ) . toHaveAttribute (
96
+ export async function testTab (
97
+ page : Page ,
98
+ startTab : TabDescription ,
99
+ endTab : TabDescription
100
+ ) : Promise < void > {
101
+ // Run the "Expect each tab to become selected, to go to the correct url, and to show all of its columns when selected" test
102
+ await page . goto ( startTab . url ) ;
103
+ await expect ( getFirstRowNthColumnCellLocator ( page , 1 ) ) . toBeVisible ( ) ;
104
+ await page
105
+ . getByRole ( "tab" )
106
+ . getByText ( endTab . tabName , { exact : true } )
107
+ . click ( ) ;
108
+ await expect ( page ) . toHaveURL ( endTab . url , { timeout : 25000 } ) ; // Long timeout because some tabs take a long time to load
109
+ await expect ( page . getByRole ( "tab" ) . getByText ( endTab . tabName ) ) . toHaveAttribute (
88
110
"aria-selected" ,
89
111
"true"
90
112
) ;
91
- if ( tab . emptyFirstColumn ) {
113
+ if ( endTab . emptyFirstColumn ) {
92
114
await expect ( page . getByRole ( "columnheader" ) ) . toHaveText (
93
- [ " " ] . concat ( tab . preselectedColumns . map ( ( x ) => x . name ) )
115
+ [ " " ] . concat ( endTab . preselectedColumns . map ( ( x ) => x . name ) )
94
116
) ;
95
117
} else {
96
118
await expect ( page . getByRole ( "columnheader" ) ) . toHaveText (
97
- tab . preselectedColumns . map ( ( x ) => x . name )
119
+ endTab . preselectedColumns . map ( ( x ) => x . name )
98
120
) ;
99
121
}
100
122
}
@@ -129,21 +151,17 @@ export async function testSortAzul(
129
151
page ,
130
152
columnIndex
131
153
) ;
132
- const lastElementTextLocator = page
133
- . getByRole ( "rowgroup" )
134
- . nth ( 1 )
135
- . getByRole ( "row" )
136
- . last ( )
137
- . getByRole ( "cell" )
138
- . nth ( columnIndex ) ;
139
- // Locator for the sort button for the tab
154
+ const lastElementTextLocator = getLastRowNthColumnTextLocator (
155
+ page ,
156
+ columnIndex
157
+ ) ;
158
+ // Locator for the sort button
140
159
const columnSortLocator = page
141
160
. getByRole ( "columnheader" , {
142
161
exact : true ,
143
162
name : tab . preselectedColumns [ columnPosition ] . name ,
144
163
} )
145
164
. getByRole ( "button" ) ;
146
-
147
165
// Expect the first and last cells to be visible and have text
148
166
await expect ( firstElementTextLocator ) . toBeVisible ( ) ;
149
167
await expect ( lastElementTextLocator ) . toBeVisible ( ) ;
@@ -177,7 +195,6 @@ export async function testSortCatalog(
177
195
) : Promise < void > {
178
196
// Get the current tab, and go to it's URL
179
197
await page . goto ( tab . url ) ;
180
- // For each column
181
198
for (
182
199
let columnPosition = 0 ;
183
200
columnPosition < tab . preselectedColumns . length ;
@@ -225,10 +242,14 @@ export async function testSelectableColumns(
225
242
page : Page ,
226
243
tab : TabDescription
227
244
) : Promise < void > {
245
+ // Navigate to the tab
228
246
await page . goto ( tab . url ) ;
247
+ // Select the "Edit Columns" menu
229
248
await page . getByRole ( "button" ) . getByText ( "Edit Columns" ) . click ( ) ;
230
249
await expect ( page . getByRole ( "menu" ) ) . toBeVisible ( ) ;
250
+ // Enable each selectable tab
231
251
for ( const column of tab . selectableColumns ) {
252
+ // Locate the checkbox for each column
232
253
const checkboxLocator = page
233
254
. getByRole ( "menu" )
234
255
. locator ( "*" )
@@ -238,13 +259,16 @@ export async function testSelectableColumns(
238
259
. filter ( { has : page . getByText ( column . name , { exact : true } ) } ) ,
239
260
} )
240
261
. getByRole ( "checkbox" ) ;
262
+ // Expect each column to be enabled and unchecked for selectable tabs
241
263
await expect ( checkboxLocator ) . toBeEnabled ( ) ;
242
264
await expect ( checkboxLocator ) . not . toBeChecked ( ) ;
265
+ // Expect clicking the checkbox to function
243
266
await checkboxLocator . click ( ) ;
244
267
await expect ( checkboxLocator ) . toBeChecked ( ) ;
245
268
}
246
269
await page . getByRole ( "document" ) . click ( ) ;
247
270
await expect ( page . getByRole ( "menu" ) ) . not . toBeVisible ( ) ;
271
+ // Expect all selectable tabs to be enabled
248
272
await expect ( page . getByRole ( "columnheader" ) ) . toContainText (
249
273
tab . selectableColumns . map ( ( x ) => x . name )
250
274
) ;
@@ -510,8 +534,8 @@ export async function testClearAll(
510
534
) : Promise < void > {
511
535
await page . goto ( tab . url ) ;
512
536
const selectedFilterNamesList = [ ] ;
537
+ // Select each filter and get the names of the actual filter text
513
538
for ( const filterName of filterNames ) {
514
- // Select the passed filter names
515
539
await page . getByText ( filterRegex ( filterName ) ) . dispatchEvent ( "click" ) ;
516
540
await getFirstFilterButtonLocator ( page ) . getByRole ( "checkbox" ) . click ( ) ;
517
541
await expect (
@@ -531,6 +555,7 @@ export async function testClearAll(
531
555
page . locator ( "#sidebar-positioner" ) . getByText ( filterName )
532
556
) . toHaveCount ( 0 ) ;
533
557
}
558
+ // Ensure that the filters still show as unchecked
534
559
for ( let i = 0 ; i < filterNames . length ; i ++ ) {
535
560
await page . getByText ( filterRegex ( filterNames [ i ] ) ) . dispatchEvent ( "click" ) ;
536
561
await expect (
0 commit comments