11// @vitest -environment jsdom
22
33import React , { act } from 'react' ;
4- import { afterEach , beforeEach , describe , expect , it } from 'vitest' ;
4+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
55import { createRoot , type Root } from 'react-dom/client' ;
66import ConfigCollectionItem from './ConfigCollectionItem' ;
77
@@ -18,9 +18,11 @@ describe('ConfigCollectionItem', () => {
1818 afterEach ( ( ) => {
1919 act ( ( ) => root . unmount ( ) ) ;
2020 container . remove ( ) ;
21+ vi . useRealTimers ( ) ;
2122 } ) ;
2223
2324 it ( 'uses an independent native button for expandable details' , ( ) => {
25+ vi . useFakeTimers ( ) ;
2426 act ( ( ) => {
2527 root . render (
2628 < ConfigCollectionItem
@@ -43,18 +45,29 @@ describe('ConfigCollectionItem', () => {
4345 act ( ( ) => {
4446 control ?. click ( ) ;
4547 } ) ;
46- const details = container . querySelector < HTMLElement > ( '.bitfun-collection-item__details-collapse' ) ;
47- expect ( details ?. dataset . open ) . toBe ( 'false' ) ;
48- expect ( details ?. getAttribute ( 'aria-hidden' ) ) . toBe ( 'true' ) ;
48+ expect ( container . querySelector ( '.bitfun-collection-item__details-collapse' ) ) . toBeNull ( ) ;
4949
5050 act ( ( ) => {
5151 toggle ?. click ( ) ;
5252 } ) ;
5353
54+ const details = container . querySelector < HTMLElement > ( '.bitfun-collection-item__details-collapse' ) ;
5455 expect ( toggle ?. getAttribute ( 'aria-expanded' ) ) . toBe ( 'true' ) ;
5556 expect ( container . textContent ) . toContain ( 'Configuration location' ) ;
5657 expect ( details ?. dataset . open ) . toBe ( 'true' ) ;
5758 expect ( details ?. getAttribute ( 'aria-hidden' ) ) . toBe ( 'false' ) ;
59+
60+ act ( ( ) => {
61+ toggle ?. click ( ) ;
62+ } ) ;
63+ expect ( details ?. dataset . open ) . toBe ( 'false' ) ;
64+ expect ( details ?. getAttribute ( 'aria-hidden' ) ) . toBe ( 'true' ) ;
65+ expect ( details ?. hasAttribute ( 'inert' ) ) . toBe ( true ) ;
66+
67+ act ( ( ) => {
68+ vi . advanceTimersByTime ( 180 ) ;
69+ } ) ;
70+ expect ( container . querySelector ( '.bitfun-collection-item__details-collapse' ) ) . toBeNull ( ) ;
5871 } ) ;
5972
6073 it ( 'does not expose disabled details as an interactive control' , ( ) => {
@@ -78,6 +91,6 @@ describe('ConfigCollectionItem', () => {
7891 } ) ;
7992
8093 expect ( toggle ?. getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
81- expect ( container . querySelector ( '.bitfun-collection-item__details-collapse' ) ?. getAttribute ( 'aria-hidden' ) ) . toBe ( 'true' ) ;
94+ expect ( container . querySelector ( '.bitfun-collection-item__details-collapse' ) ) . toBeNull ( ) ;
8295 } ) ;
8396} ) ;
0 commit comments