@@ -5,7 +5,10 @@ import { setViewport, sendKeys } from '@web/test-runner-commands';
55import { allUpdates } from '@patternfly/pfe-tools/test/utils.js' ;
66
77import { PfV5BackToTop } from '../pf-v5-back-to-top.js' ;
8- import { a11ySnapshot } from '@patternfly/pfe-tools/test/a11y-snapshot.js' ;
8+ import { type A11yTreeSnapshot , a11ySnapshot } from '@patternfly/pfe-tools/test/a11y-snapshot.js' ;
9+
10+ const takeProps = ( props : string [ ] ) => ( obj : object ) =>
11+ Object . fromEntries ( Object . entries ( obj ) . filter ( ( [ k ] ) => props . includes ( k ) ) ) ;
912
1013describe ( '<pf-v5-back-to-top>' , function ( ) {
1114 it ( 'imperatively instantiates' , function ( ) {
@@ -30,6 +33,7 @@ describe('<pf-v5-back-to-top>', function() {
3033
3134 describe ( 'when rendered in a viewport with a height smaller then content length' , function ( ) {
3235 let element : PfV5BackToTop ;
36+ let snapshot : A11yTreeSnapshot ;
3337
3438 beforeEach ( async function ( ) {
3539 await setViewport ( { width : 320 , height : 640 } ) ;
@@ -42,29 +46,30 @@ describe('<pf-v5-back-to-top>', function() {
4246 </ div >
4347 ` ) ;
4448 element = container . querySelector ( 'pf-v5-back-to-top' ) ! ;
49+ snapshot = await a11ySnapshot ( ) ;
50+
4551 await allUpdates ( element ) ;
4652 } ) ;
4753
48- it ( 'should be hidden on init' , async function ( ) {
49- const snapshot = await a11ySnapshot ( ) ;
50- expect ( snapshot ) . to . not . axContainRole ( 'link' ) ;
54+ it ( 'should be hidden on init' , function ( ) {
55+ const { children } = snapshot ;
56+ expect ( children ) . to . be . undefined ;
5157 } ) ;
5258
53- it ( 'should not be accessible' , async function ( ) {
54- const snapshot = await a11ySnapshot ( ) ;
55- expect ( snapshot ) . to . not . axContainName ( 'Back to top' ) ;
59+ it ( 'should not be accessible' , function ( ) {
60+ expect ( snapshot . children ) . to . be . undefined ;
5661 } ) ;
5762
5863 describe ( 'when scrolled 401px' , function ( ) {
5964 beforeEach ( async function ( ) {
6065 window . scrollTo ( { top : 401 , behavior : 'instant' } ) ;
6166 await nextFrame ( ) ;
6267 await allUpdates ( element ) ;
68+ snapshot = await a11ySnapshot ( ) ;
6369 } ) ;
6470
65- it ( 'should be visible' , async function ( ) {
66- expect ( await a11ySnapshot ( ) )
67- . to . axContainQuery ( { role : 'link' , name : 'Back to top' } ) ;
71+ it ( 'should be visible' , function ( ) {
72+ expect ( snapshot . children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'link' , name : 'Back to top' } ] ) ;
6873 } ) ;
6974
7075 it ( 'should be accessible' , async function ( ) {
@@ -90,11 +95,11 @@ describe('<pf-v5-back-to-top>', function() {
9095 await nextFrame ( ) ;
9196 element . alwaysVisible = true ;
9297 await allUpdates ( element ) ;
98+ snapshot = await a11ySnapshot ( ) ;
9399 } ) ;
94100
95- it ( 'should be visible' , async function ( ) {
96- expect ( await a11ySnapshot ( ) )
97- . to . axContainQuery ( { role : 'link' , name : 'Back to top' } ) ;
101+ it ( 'should be visible' , function ( ) {
102+ expect ( snapshot . children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'link' , name : 'Back to top' } ] ) ;
98103 } ) ;
99104
100105 it ( 'should be accessible' , async function ( ) {
@@ -117,29 +122,32 @@ describe('<pf-v5-back-to-top>', function() {
117122 beforeEach ( async function ( ) {
118123 element . scrollDistance = 1000 ;
119124 await allUpdates ( element ) ;
125+ snapshot = await a11ySnapshot ( ) ;
120126 } ) ;
121127
122- it ( 'should be hidden' , async function ( ) {
123- expect ( await a11ySnapshot ( ) ) . to . not . axContainRole ( 'link' ) ;
128+ it ( 'should be hidden' , function ( ) {
129+ const { children } = snapshot ;
130+ expect ( children ) . to . be . undefined ;
124131 } ) ;
125132
126133 describe ( 'when scrolled 1001px' , function ( ) {
127134 beforeEach ( async function ( ) {
128135 window . scrollTo ( { top : 1001 , behavior : 'instant' } ) ;
129136 await nextFrame ( ) ;
130137 await allUpdates ( element ) ;
138+ snapshot = await a11ySnapshot ( ) ;
131139 } ) ;
132140
133- it ( 'should be visible' , async function ( ) {
134- expect ( await a11ySnapshot ( ) )
135- . to . axContainQuery ( { role : 'link' , name : 'Back to top' } ) ;
141+ it ( 'should be visible' , function ( ) {
142+ expect ( snapshot . children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'link' , name : 'Back to top' } ] ) ;
136143 } ) ;
137144 } ) ;
138145 } ) ;
139146 } ) ;
140147
141148 describe ( 'when rendered in an element with an overflowed height' , function ( ) {
142149 let element : PfV5BackToTop ;
150+ let snapshot : A11yTreeSnapshot ;
143151
144152 beforeEach ( async function ( ) {
145153 window . scrollTo ( { top : 0 , behavior : 'instant' } ) ;
@@ -152,11 +160,13 @@ describe('<pf-v5-back-to-top>', function() {
152160 ` ) ;
153161 element = container . querySelector ( 'pf-v5-back-to-top' ) ! ;
154162 await allUpdates ( element ) ;
163+
164+ snapshot = await a11ySnapshot ( { selector : 'pf-v5-back-to-top' } ) ;
155165 } ) ;
156166
157- it ( 'should be hidden on init' , async function ( ) {
158- const snapshot = await a11ySnapshot ( { selector : 'pf-v5-back-to-top' } ) ;
159- expect ( snapshot ?. children ) . to . not . be . ok ;
167+ it ( 'should be hidden on init' , function ( ) {
168+ const { children } = snapshot ;
169+ expect ( children ) . to . be . undefined ;
160170 } ) ;
161171
162172 describe ( 'when scrolled 401px' , function ( ) {
@@ -166,17 +176,18 @@ describe('<pf-v5-back-to-top>', function() {
166176 scrollableElement . dispatchEvent ( new Event ( 'scroll' ) ) ;
167177 await nextFrame ( ) ;
168178 await allUpdates ( element ) ;
179+ snapshot = await a11ySnapshot ( ) ;
169180 } ) ;
170181
171- it ( 'should be visible' , async function ( ) {
172- expect ( await a11ySnapshot ( ) )
173- . to . axContainQuery ( { role : 'link' , name : 'Back to top' } ) ;
182+ it ( 'should be visible' , function ( ) {
183+ expect ( snapshot . children ?. at ( 0 ) ?. children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'link' , name : 'Back to top' } ] ) ;
174184 } ) ;
175185 } ) ;
176186 } ) ;
177187
178188 describe ( 'when no text is provided' , function ( ) {
179189 let element : PfV5BackToTop ;
190+ let snapshot : A11yTreeSnapshot ;
180191
181192 describe ( 'as a link' , function ( ) {
182193 beforeEach ( async function ( ) {
@@ -198,11 +209,11 @@ describe('<pf-v5-back-to-top>', function() {
198209 window . scrollTo ( { top : 401 , behavior : 'instant' } ) ;
199210 await nextFrame ( ) ;
200211 await allUpdates ( element ) ;
212+ snapshot = await a11ySnapshot ( ) ;
201213 } ) ;
202214
203- it ( 'should have a label of "Back to top"' , async function ( ) {
204- expect ( await a11ySnapshot ( ) )
205- . to . axContainQuery ( { role : 'link' , name : 'Back to top' } ) ;
215+ it ( 'should have a label of "Back to top"' , function ( ) {
216+ expect ( snapshot . children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'link' , name : 'Back to top' } ] ) ;
206217 } ) ;
207218 } ) ;
208219 } ) ;
@@ -227,18 +238,19 @@ describe('<pf-v5-back-to-top>', function() {
227238 window . scrollTo ( { top : 401 , behavior : 'instant' } ) ;
228239 await nextFrame ( ) ;
229240 await allUpdates ( element ) ;
241+ snapshot = await a11ySnapshot ( ) ;
230242 } ) ;
231243
232- it ( 'should have a label of "Back to top"' , async function ( ) {
233- expect ( await a11ySnapshot ( ) )
234- . to . axContainQuery ( { role : 'button' , name : 'Back to top' } ) ;
244+ it ( 'should have a label of "Back to top"' , function ( ) {
245+ expect ( snapshot . children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'button' , name : 'Back to top' } ] ) ;
235246 } ) ;
236247 } ) ;
237248 } ) ;
238249 } ) ;
239250
240251 describe ( 'when a label is provided' , function ( ) {
241252 let element : PfV5BackToTop ;
253+ let snapshot : A11yTreeSnapshot ;
242254
243255 describe ( 'as a link' , function ( ) {
244256 beforeEach ( async function ( ) {
@@ -260,11 +272,11 @@ describe('<pf-v5-back-to-top>', function() {
260272 window . scrollTo ( { top : 401 , behavior : 'instant' } ) ;
261273 await nextFrame ( ) ;
262274 await allUpdates ( element ) ;
275+ snapshot = await a11ySnapshot ( ) ;
263276 } ) ;
264277
265- it ( 'should have a label of "Return to top"' , async function ( ) {
266- expect ( await a11ySnapshot ( ) )
267- . to . axContainQuery ( { role : 'link' , name : 'Return to top' } ) ;
278+ it ( 'should have a label of "Return to top"' , function ( ) {
279+ expect ( snapshot . children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'link' , name : 'Return to top' } ] ) ;
268280 } ) ;
269281 } ) ;
270282 } ) ;
@@ -289,11 +301,11 @@ describe('<pf-v5-back-to-top>', function() {
289301 window . scrollTo ( { top : 401 , behavior : 'instant' } ) ;
290302 await nextFrame ( ) ;
291303 await allUpdates ( element ) ;
304+ snapshot = await a11ySnapshot ( ) ;
292305 } ) ;
293306
294- it ( 'should have a label of "Return to top"' , async function ( ) {
295- expect ( await a11ySnapshot ( ) )
296- . to . axContainQuery ( { role : 'button' , name : 'Return to top' } ) ;
307+ it ( 'should have a label of "Return to top"' , function ( ) {
308+ expect ( snapshot . children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'button' , name : 'Return to top' } ] ) ;
297309 } ) ;
298310 } ) ;
299311 } ) ;
0 commit comments