10
10
* governing permissions and limitations under the License.
11
11
*/
12
12
13
+ import { act , render , waitFor } from '@react-spectrum/test-utils-internal' ;
13
14
import { ariaHideOutside } from '../src' ;
14
- import React from 'react' ;
15
- import { render , waitFor } from '@react-spectrum/test-utils-internal' ;
15
+ import React , { useState } from 'react' ;
16
16
17
17
describe ( 'ariaHideOutside' , function ( ) {
18
18
it ( 'should hide everything except the provided element [button]' , function ( ) {
@@ -354,10 +354,13 @@ describe('ariaHideOutside', function () {
354
354
} ) ;
355
355
356
356
it ( 'should hide everything except the provided element [row]' , function ( ) {
357
- let { getAllByRole} = render (
357
+ let { getAllByRole, getByTestId } = render (
358
358
< div role = "grid" >
359
359
< div role = "row" >
360
- < div role = "gridcell" > Cell 1</ div >
360
+ < div role = "gridcell" >
361
+ < span data-testid = "test-span" >
362
+ Cell 1
363
+ </ span > </ div >
361
364
</ div >
362
365
< div role = "row" >
363
366
< div role = "gridcell" > Cell 2</ div >
@@ -367,13 +370,15 @@ describe('ariaHideOutside', function () {
367
370
368
371
let cells = getAllByRole ( 'gridcell' ) ;
369
372
let rows = getAllByRole ( 'row' ) ;
373
+ let span = getByTestId ( 'test-span' ) ;
370
374
371
375
let revert = ariaHideOutside ( [ rows [ 1 ] ] ) ;
372
376
373
377
// Applies aria-hidden to the row and cell despite recursive nature of aria-hidden
374
378
// for https://bugs.webkit.org/show_bug.cgi?id=222623
375
379
expect ( rows [ 0 ] ) . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
376
380
expect ( cells [ 0 ] ) . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
381
+ expect ( span ) . not . toHaveAttribute ( 'aria-hidden' ) ;
377
382
expect ( rows [ 1 ] ) . not . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
378
383
expect ( cells [ 1 ] ) . not . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
379
384
@@ -383,5 +388,47 @@ describe('ariaHideOutside', function () {
383
388
expect ( cells [ 0 ] ) . not . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
384
389
expect ( rows [ 1 ] ) . not . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
385
390
expect ( cells [ 1 ] ) . not . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
391
+ expect ( span ) . not . toHaveAttribute ( 'aria-hidden' ) ;
392
+ } ) ;
393
+
394
+ it ( 'should unhide after item reorder' , async function ( ) {
395
+ function Item ( props ) {
396
+ return (
397
+ < div role = "presentation" >
398
+ < div data-testid = { props . testid } role = "row" >
399
+ < div role = "gridcell" />
400
+ </ div >
401
+ </ div >
402
+ ) ;
403
+ }
404
+
405
+ function Test ( ) {
406
+ let [ count , setCount ] = useState ( 0 ) ;
407
+ let items = [ 'row1' , 'row2' , 'row3' , 'row4' , 'row5' ] ;
408
+ if ( count === 1 ) {
409
+ items = [ 'row2' , 'row3' , 'row4' , 'row5' , 'row1' ] ;
410
+ }
411
+
412
+ return (
413
+ < >
414
+ < button onClick = { ( ) => setCount ( ( old ) => old + 1 ) } > press</ button >
415
+ { items . map ( ( item ) => < Item testid = { item } key = { item } /> ) }
416
+ </ >
417
+
418
+ ) ;
419
+ }
420
+
421
+ let { getByRole, getByTestId} = render (
422
+ < Test />
423
+ ) ;
424
+
425
+ let button = getByRole ( 'button' ) ;
426
+ let row = getByTestId ( 'row1' ) ;
427
+ let revert = ariaHideOutside ( [ button ] ) ;
428
+
429
+ act ( ( ) => button . click ( ) ) ;
430
+ await Promise . resolve ( ) ;
431
+ revert ( ) ;
432
+ expect ( row ) . not . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
386
433
} ) ;
387
434
} ) ;
0 commit comments