@@ -96,6 +96,8 @@ test('Calls the callback set by updateTransitionEnd when transition ends and ani
9696 const closeButton = await screen . findByLabelText ( 'Close' ) ;
9797 await user . click ( closeButton ) ;
9898 expect ( mockCallback ) . not . toHaveBeenCalled ( ) ;
99+ // fireEvent is needed here because transitionEnd is a browser event that occurs automatically
100+ // when CSS transitions complete, not a user interaction that userEvent can simulate
99101 fireEvent . transitionEnd ( screen . getByText ( 'Test Alert' ) . closest ( '.pf-v6-c-alert-group__item' ) as HTMLElement ) ;
100102 expect ( mockCallback ) . toHaveBeenCalled ( ) ;
101103} ) ;
@@ -128,99 +130,50 @@ test('Does not call the callback set by updateTransitionEnd when transition ends
128130 await user . click ( closeButton ) ;
129131 expect ( mockCallback ) . toHaveBeenCalledTimes ( 1 ) ;
130132 // The transitionend event firing should not cause the callback to be called again
133+ // fireEvent is needed here because transitionEnd is a browser event that occurs automatically
134+ // when CSS transitions complete, not a user interaction that userEvent can simulate
131135 fireEvent . transitionEnd ( screen . getByText ( 'Test Alert' ) . closest ( '.pf-v6-c-alert-group__item' ) as HTMLElement ) ;
132136 expect ( mockCallback ) . toHaveBeenCalledTimes ( 1 ) ;
133137} ) ;
134138
135- // Animation context tests
136- test ( 'respects AnimationsProvider context when no local hasAnimations prop' , ( ) => {
137- const mockCallback = jest . fn ( ) ;
138-
139- render (
140- < AnimationsProvider config = { { hasAnimations : true } } >
141- < AlertGroup isToast appendTo = { document . body } >
142- < Alert
143- isLiveRegion
144- title = { 'Test Alert' }
145- actionClose = { < AlertActionCloseButton aria-label = "Close" onClose = { mockCallback } /> }
146- />
147- </ AlertGroup >
148- </ AnimationsProvider >
149- ) ;
150-
151- const closeButton = screen . getByLabelText ( 'Close' ) ;
152- fireEvent . click ( closeButton ) ;
153- expect ( mockCallback ) . not . toHaveBeenCalled ( ) ;
154-
155- // Should call callback on transition end when animations are enabled via context
156- fireEvent . transitionEnd ( screen . getByText ( 'Test Alert' ) . closest ( '.pf-v6-c-alert-group__item' ) as HTMLElement ) ;
157- expect ( mockCallback ) . toHaveBeenCalled ( ) ;
158- } ) ;
159-
160- test ( 'local hasAnimations prop takes precedence over context' , ( ) => {
161- window . matchMedia = ( query ) => ( {
162- matches : false ,
163- media : query ,
164- onchange : null ,
165- addListener : ( ) => { } , // deprecated
166- removeListener : ( ) => { } , // deprecated
167- addEventListener : ( ) => { } ,
168- removeEventListener : ( ) => { } ,
169- dispatchEvent : ( ) => true
139+ describe ( 'Animation context behavior' , ( ) => {
140+ test ( 'respects AnimationsProvider context when no local hasAnimations prop' , ( ) => {
141+ render (
142+ < AnimationsProvider config = { { hasAnimations : true } } >
143+ < AlertGroup >
144+ < Alert title = "Test Alert" />
145+ </ AlertGroup >
146+ </ AnimationsProvider >
147+ ) ;
148+
149+ // Should apply animation class when animations are enabled via context
150+ const alertGroupItem = screen . getByText ( 'Test Alert' ) . closest ( '.pf-v6-c-alert-group__item' ) ;
151+ expect ( alertGroupItem ) . toHaveClass ( 'pf-m-offstage-top' ) ;
170152 } ) ;
171153
172- const mockCallback = jest . fn ( ) ;
154+ test ( 'local hasAnimations prop takes precedence over context' , ( ) => {
155+ render (
156+ < AnimationsProvider config = { { hasAnimations : true } } >
157+ < AlertGroup hasAnimations = { false } >
158+ < Alert title = "Test Alert" />
159+ </ AlertGroup >
160+ </ AnimationsProvider >
161+ ) ;
162+
163+ // Should not apply animation class when local hasAnimations=false overrides context
164+ const alertGroupItem = screen . getByText ( 'Test Alert' ) . closest ( '.pf-v6-c-alert-group__item' ) ;
165+ expect ( alertGroupItem ) . not . toHaveClass ( 'pf-m-offstage-top' ) ;
166+ } ) ;
173167
174- render (
175- < AnimationsProvider config = { { hasAnimations : true } } >
176- < AlertGroup hasAnimations = { false } isToast appendTo = { document . body } >
177- < Alert
178- isLiveRegion
179- title = { 'Test Alert' }
180- actionClose = { < AlertActionCloseButton aria-label = "Close" onClose = { mockCallback } /> }
181- />
168+ test ( 'works without AnimationsProvider (backward compatibility)' , ( ) => {
169+ render (
170+ < AlertGroup >
171+ < Alert title = "Test Alert" />
182172 </ AlertGroup >
183- </ AnimationsProvider >
184- ) ;
173+ ) ;
185174
186- const closeButton = screen . getByLabelText ( 'Close' ) ;
187- fireEvent . click ( closeButton ) ;
188- expect ( mockCallback ) . toHaveBeenCalledTimes ( 1 ) ;
189-
190- // Should not call callback again on transition end when local hasAnimations=false overrides context
191- fireEvent . transitionEnd ( screen . getByText ( 'Test Alert' ) . closest ( '.pf-v6-c-alert-group__item' ) as HTMLElement ) ;
192- expect ( mockCallback ) . toHaveBeenCalledTimes ( 1 ) ;
193- } ) ;
194-
195- test ( 'works without AnimationsProvider (backward compatibility)' , ( ) => {
196- window . matchMedia = ( query ) => ( {
197- matches : false ,
198- media : query ,
199- onchange : null ,
200- addListener : ( ) => { } , // deprecated
201- removeListener : ( ) => { } , // deprecated
202- addEventListener : ( ) => { } ,
203- removeEventListener : ( ) => { } ,
204- dispatchEvent : ( ) => true
175+ // Should not apply animation class when no context and no local hasAnimations
176+ const alertGroupItem = screen . getByText ( 'Test Alert' ) . closest ( '.pf-v6-c-alert-group__item' ) ;
177+ expect ( alertGroupItem ) . not . toHaveClass ( 'pf-m-offstage-top' ) ;
205178 } ) ;
206-
207- const mockCallback = jest . fn ( ) ;
208-
209- render (
210- < AlertGroup isToast appendTo = { document . body } >
211- < Alert
212- isLiveRegion
213- title = { 'Test Alert' }
214- actionClose = { < AlertActionCloseButton aria-label = "Close" onClose = { mockCallback } /> }
215- />
216- </ AlertGroup >
217- ) ;
218-
219- const closeButton = screen . getByLabelText ( 'Close' ) ;
220- fireEvent . click ( closeButton ) ;
221- expect ( mockCallback ) . toHaveBeenCalledTimes ( 1 ) ;
222-
223- // Should not call callback again on transition end when no context and no local hasAnimations
224- fireEvent . transitionEnd ( screen . getByText ( 'Test Alert' ) . closest ( '.pf-v6-c-alert-group__item' ) as HTMLElement ) ;
225- expect ( mockCallback ) . toHaveBeenCalledTimes ( 1 ) ;
226179} ) ;
0 commit comments