@@ -5,10 +5,7 @@ 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 { 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 ) ) ) ;
8+ import { a11ySnapshot } from '@patternfly/pfe-tools/test/a11y-snapshot.js' ;
129
1310describe ( '<pf-v5-back-to-top>' , function ( ) {
1411 it ( 'imperatively instantiates' , function ( ) {
@@ -33,7 +30,6 @@ describe('<pf-v5-back-to-top>', function() {
3330
3431 describe ( 'when rendered in a viewport with a height smaller then content length' , function ( ) {
3532 let element : PfV5BackToTop ;
36- let snapshot : A11yTreeSnapshot ;
3733
3834 beforeEach ( async function ( ) {
3935 await setViewport ( { width : 320 , height : 640 } ) ;
@@ -46,30 +42,29 @@ describe('<pf-v5-back-to-top>', function() {
4642 </ div >
4743 ` ) ;
4844 element = container . querySelector ( 'pf-v5-back-to-top' ) ! ;
49- snapshot = await a11ySnapshot ( ) ;
50-
5145 await allUpdates ( element ) ;
5246 } ) ;
5347
54- it ( 'should be hidden on init' , function ( ) {
55- const { children } = snapshot ;
56- expect ( children ) . to . be . undefined ;
48+ it ( 'should be hidden on init' , async function ( ) {
49+ const snapshot = await a11ySnapshot ( ) ;
50+ expect ( snapshot ) . to . not . axContainRole ( 'link' ) ;
5751 } ) ;
5852
59- it ( 'should not be accessible' , function ( ) {
60- expect ( snapshot . children ) . to . be . undefined ;
53+ it ( 'should not be accessible' , async function ( ) {
54+ const snapshot = await a11ySnapshot ( ) ;
55+ expect ( snapshot ) . to . not . axContainName ( 'Back to top' ) ;
6156 } ) ;
6257
6358 describe ( 'when scrolled 401px' , function ( ) {
6459 beforeEach ( async function ( ) {
6560 window . scrollTo ( { top : 401 , behavior : 'instant' } ) ;
6661 await nextFrame ( ) ;
6762 await allUpdates ( element ) ;
68- snapshot = await a11ySnapshot ( ) ;
6963 } ) ;
7064
71- it ( 'should be visible' , function ( ) {
72- expect ( snapshot . children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'link' , name : 'Back to top' } ] ) ;
65+ it ( 'should be visible' , async function ( ) {
66+ expect ( await a11ySnapshot ( ) )
67+ . to . axContainQuery ( { role : 'link' , name : 'Back to top' } ) ;
7368 } ) ;
7469
7570 it ( 'should be accessible' , async function ( ) {
@@ -95,11 +90,11 @@ describe('<pf-v5-back-to-top>', function() {
9590 await nextFrame ( ) ;
9691 element . alwaysVisible = true ;
9792 await allUpdates ( element ) ;
98- snapshot = await a11ySnapshot ( ) ;
9993 } ) ;
10094
101- it ( 'should be visible' , function ( ) {
102- expect ( snapshot . children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'link' , name : 'Back to top' } ] ) ;
95+ it ( 'should be visible' , async function ( ) {
96+ expect ( await a11ySnapshot ( ) )
97+ . to . axContainQuery ( { role : 'link' , name : 'Back to top' } ) ;
10398 } ) ;
10499
105100 it ( 'should be accessible' , async function ( ) {
@@ -122,32 +117,29 @@ describe('<pf-v5-back-to-top>', function() {
122117 beforeEach ( async function ( ) {
123118 element . scrollDistance = 1000 ;
124119 await allUpdates ( element ) ;
125- snapshot = await a11ySnapshot ( ) ;
126120 } ) ;
127121
128- it ( 'should be hidden' , function ( ) {
129- const { children } = snapshot ;
130- expect ( children ) . to . be . undefined ;
122+ it ( 'should be hidden' , async function ( ) {
123+ expect ( await a11ySnapshot ( ) ) . to . not . axContainRole ( 'link' ) ;
131124 } ) ;
132125
133126 describe ( 'when scrolled 1001px' , function ( ) {
134127 beforeEach ( async function ( ) {
135128 window . scrollTo ( { top : 1001 , behavior : 'instant' } ) ;
136129 await nextFrame ( ) ;
137130 await allUpdates ( element ) ;
138- snapshot = await a11ySnapshot ( ) ;
139131 } ) ;
140132
141- it ( 'should be visible' , function ( ) {
142- expect ( snapshot . children ?. map ( takeProps ( [ 'name' , 'role' ] ) ) ) . to . deep . equal ( [ { role : 'link' , name : 'Back to top' } ] ) ;
133+ it ( 'should be visible' , async function ( ) {
134+ expect ( await a11ySnapshot ( ) )
135+ . to . axContainQuery ( { role : 'link' , name : 'Back to top' } ) ;
143136 } ) ;
144137 } ) ;
145138 } ) ;
146139 } ) ;
147140
148141 describe ( 'when rendered in an element with an overflowed height' , function ( ) {
149142 let element : PfV5BackToTop ;
150- let snapshot : A11yTreeSnapshot ;
151143
152144 beforeEach ( async function ( ) {
153145 window . scrollTo ( { top : 0 , behavior : 'instant' } ) ;
@@ -160,13 +152,11 @@ describe('<pf-v5-back-to-top>', function() {
160152 ` ) ;
161153 element = container . querySelector ( 'pf-v5-back-to-top' ) ! ;
162154 await allUpdates ( element ) ;
163-
164- snapshot = await a11ySnapshot ( { selector : 'pf-v5-back-to-top' } ) ;
165155 } ) ;
166156
167- it ( 'should be hidden on init' , function ( ) {
168- const { children } = snapshot ;
169- expect ( children ) . to . be . undefined ;
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 ;
170160 } ) ;
171161
172162 describe ( 'when scrolled 401px' , function ( ) {
@@ -176,18 +166,17 @@ describe('<pf-v5-back-to-top>', function() {
176166 scrollableElement . dispatchEvent ( new Event ( 'scroll' ) ) ;
177167 await nextFrame ( ) ;
178168 await allUpdates ( element ) ;
179- snapshot = await a11ySnapshot ( ) ;
180169 } ) ;
181170
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' } ] ) ;
171+ it ( 'should be visible' , async function ( ) {
172+ expect ( await a11ySnapshot ( ) )
173+ . to . axContainQuery ( { role : 'link' , name : 'Back to top' } ) ;
184174 } ) ;
185175 } ) ;
186176 } ) ;
187177
188178 describe ( 'when no text is provided' , function ( ) {
189179 let element : PfV5BackToTop ;
190- let snapshot : A11yTreeSnapshot ;
191180
192181 describe ( 'as a link' , function ( ) {
193182 beforeEach ( async function ( ) {
@@ -209,11 +198,11 @@ describe('<pf-v5-back-to-top>', function() {
209198 window . scrollTo ( { top : 401 , behavior : 'instant' } ) ;
210199 await nextFrame ( ) ;
211200 await allUpdates ( element ) ;
212- snapshot = await a11ySnapshot ( ) ;
213201 } ) ;
214202
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' } ] ) ;
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' } ) ;
217206 } ) ;
218207 } ) ;
219208 } ) ;
@@ -238,19 +227,18 @@ describe('<pf-v5-back-to-top>', function() {
238227 window . scrollTo ( { top : 401 , behavior : 'instant' } ) ;
239228 await nextFrame ( ) ;
240229 await allUpdates ( element ) ;
241- snapshot = await a11ySnapshot ( ) ;
242230 } ) ;
243231
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' } ] ) ;
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' } ) ;
246235 } ) ;
247236 } ) ;
248237 } ) ;
249238 } ) ;
250239
251240 describe ( 'when a label is provided' , function ( ) {
252241 let element : PfV5BackToTop ;
253- let snapshot : A11yTreeSnapshot ;
254242
255243 describe ( 'as a link' , function ( ) {
256244 beforeEach ( async function ( ) {
@@ -272,11 +260,11 @@ describe('<pf-v5-back-to-top>', function() {
272260 window . scrollTo ( { top : 401 , behavior : 'instant' } ) ;
273261 await nextFrame ( ) ;
274262 await allUpdates ( element ) ;
275- snapshot = await a11ySnapshot ( ) ;
276263 } ) ;
277264
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' } ] ) ;
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' } ) ;
280268 } ) ;
281269 } ) ;
282270 } ) ;
@@ -301,11 +289,11 @@ describe('<pf-v5-back-to-top>', function() {
301289 window . scrollTo ( { top : 401 , behavior : 'instant' } ) ;
302290 await nextFrame ( ) ;
303291 await allUpdates ( element ) ;
304- snapshot = await a11ySnapshot ( ) ;
305292 } ) ;
306293
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' } ] ) ;
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' } ) ;
309297 } ) ;
310298 } ) ;
311299 } ) ;
0 commit comments