1
1
import { expect , test } from "@playwright/test" ;
2
- import { testFilterPresence } from "../testFunctions" ;
2
+ import {
3
+ filter_regex ,
4
+ getFirstElementTextLocator ,
5
+ testFilterPresence ,
6
+ } from "../testFunctions" ;
3
7
import { anvilFilters , anvilTabs , anvilTabTestOrder } from "./anvil-tabs" ;
4
8
5
9
test . describe . configure ( { mode : "parallel" } ) ;
6
10
7
- const filter_regex = ( filter : string ) : RegExp =>
8
- new RegExp ( filter + "\\s+\\([0-9]+\\)\\s*" ) ;
9
-
10
11
test ( "Check that all filters exist on the Datasets tab and are clickable" , async ( {
11
12
page,
12
13
} ) => {
@@ -49,7 +50,11 @@ test("Check that the first filter on the Datasets tab creates at least one check
49
50
// Select a filter
50
51
await page
51
52
. getByRole ( "button" )
52
- . getByText ( filter_regex ( anvilFilters [ 4 ] ) )
53
+ . getByText (
54
+ filter_regex (
55
+ anvilFilters [ Math . floor ( Math . random ( ) * anvilFilters . length ) ]
56
+ )
57
+ )
53
58
. click ( ) ;
54
59
// Expect all checkboxes to be unchecked initially and to work properly
55
60
await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeVisible ( ) ;
@@ -62,42 +67,42 @@ test("Check that the first filter on the Datasets tab creates at least one check
62
67
await expect ( checkbox ) . toBeChecked ( ) ;
63
68
}
64
69
await page . locator ( "body" ) . click ( ) ;
65
- const firstElementTextLocator = page
66
- . getByRole ( "rowgroup" )
67
- . nth ( 1 )
68
- . getByRole ( "row" )
69
- . nth ( 0 )
70
- . getByRole ( "cell" )
71
- . first ( ) ;
72
- await expect ( firstElementTextLocator ) . toBeVisible ( ) ;
70
+ await expect ( getFirstElementTextLocator ( page , 0 ) ) . toBeVisible ( ) ;
73
71
} ) ;
74
72
75
73
test ( "Check that filter checkboxes are persistent across pages" , async ( {
76
74
page,
77
75
} ) => {
78
- await page . goto ( anvilTabs . datasets . url ) ;
76
+ // Randomly select a filter
77
+ const test_filter =
78
+ anvilFilters [ Math . floor ( Math . random ( ) * anvilFilters . length ) ] ;
79
+ // Start on the first tab in the test order (should be files)
80
+ await page . goto ( anvilTabs [ anvilTabTestOrder [ 0 ] ] . url ) ;
79
81
await expect (
80
82
page . getByRole ( "tab" ) . getByText ( anvilTabs . datasets . tabName )
81
83
) . toBeVisible ( ) ;
82
- await page . getByText ( filter_regex ( anvilFilters [ 3 ] ) ) . click ( ) ; // maybe should select a random one instead;
84
+ // Select the first checkbox on the test filter
85
+ await page . getByText ( filter_regex ( test_filter ) ) . click ( ) ;
83
86
await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . not . toBeChecked ( ) ;
84
87
await page . getByRole ( "checkbox" ) . first ( ) . click ( ) ;
85
88
await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeChecked ( ) ;
86
89
await page . locator ( "body" ) . click ( ) ;
87
- for ( const blah of anvilTabTestOrder ) {
88
- console . log ( blah ) ;
89
- await page . getByRole ( "tab" ) . getByText ( anvilTabs [ blah ] . tabName ) . click ( ) ;
90
- const firstElementTextLocator = page
91
- . getByRole ( "rowgroup" )
92
- . nth ( 1 )
93
- . getByRole ( "row" )
94
- . nth ( 0 )
95
- . getByRole ( "cell" )
96
- . first ( ) ;
97
- await expect ( firstElementTextLocator ) . toBeVisible ( ) ;
98
- await expect ( page . getByText ( filter_regex ( anvilFilters [ 3 ] ) ) ) . toBeVisible ( ) ;
99
- await page . getByText ( filter_regex ( anvilFilters [ 3 ] ) ) . click ( ) ;
90
+ // Expect at least some text to still be visible
91
+ await expect ( getFirstElementTextLocator ( page , 0 ) ) . toBeVisible ( ) ;
92
+ // For each tab, check that the selected filter is still checked
93
+ for ( const tab of anvilTabTestOrder . slice ( 1 ) ) {
94
+ await page . getByRole ( "tab" ) . getByText ( anvilTabs [ tab ] . tabName ) . click ( ) ;
95
+ await expect ( page . getByText ( filter_regex ( test_filter ) ) ) . toBeVisible ( ) ;
96
+ await page . getByText ( filter_regex ( test_filter ) ) . click ( ) ;
100
97
await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeChecked ( ) ;
101
98
await page . locator ( "body" ) . click ( ) ;
102
99
}
100
+ // Return to the start tab and confirm that the filter stays checked and that some content is visible
101
+ await page
102
+ . getByRole ( "tab" )
103
+ . getByText ( anvilTabs [ anvilTabTestOrder [ 0 ] ] . tabName )
104
+ . click ( ) ;
105
+ await expect ( getFirstElementTextLocator ( page , 0 ) ) . toBeVisible ( ) ;
106
+ await page . getByText ( filter_regex ( test_filter ) ) . click ( ) ;
107
+ await expect ( page . getByRole ( "checkbox" ) . first ( ) ) . toBeChecked ( ) ;
103
108
} ) ;
0 commit comments