@@ -264,24 +264,36 @@ describe('TooltipDialog', () => {
264264 expect ( getByTestId ( 'backdrop' ) ) . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
265265
266266 // Open
267- await user . click ( trigger ) ;
267+ await act ( async ( ) => {
268+ await user . click ( trigger ) ;
269+ } ) ;
268270
269271 const openDialog = getByRole ( 'dialog' ) ;
270-
271- expect ( openDialog ) . not . toBeNull ( ) ;
272-
272+ expect ( openDialog ) . toBeInTheDocument ( ) ;
273+ expect ( getByTestId ( 'backdrop' ) ) . not . toHaveAttribute ( 'aria-hidden' ) ;
274+ expect ( openDialog ) . toHaveFocus ( ) ;
273275 // Backdrop should NOT have hideVisually styles when visible
274276 const visibleBackdropStyles = window . getComputedStyle ( getByTestId ( 'backdrop' ) ) ;
275-
276277 expect ( visibleBackdropStyles . position ) . toBe ( 'fixed' ) ;
277278
278279 // Close (toggle button again)
279- await user . click ( trigger ) ;
280-
281- const hiddenAgainDialog = queryByRole ( 'dialog' , { hidden : true } ) ;
280+ await act ( async ( ) => {
281+ await user . click ( trigger ) ;
282+ } ) ;
282283
283284 // Dialog remains mounted but visually hidden again
285+ const hiddenAgainDialog = queryByRole ( 'dialog' , { hidden : true } ) ;
284286 expect ( hiddenAgainDialog ) . not . toBeNull ( ) ;
287+ await waitFor ( ( ) => {
288+ expect ( getByTestId ( 'backdrop' ) ) . toHaveAttribute ( 'aria-hidden' , 'true' ) ;
289+ // Backdrop should have hideVisually styles applied again
290+ const hiddenBackdropStyles = window . getComputedStyle ( getByTestId ( 'backdrop' ) ) ;
291+ expect ( hiddenBackdropStyles . position ) . toBe ( 'absolute' ) ;
292+ expect ( hiddenBackdropStyles . width ) . toBe ( '1px' ) ;
293+ expect ( hiddenBackdropStyles . height ) . toBe ( '1px' ) ;
294+ } ) ;
295+ // Focus should return to trigger
296+ expect ( trigger ) . toHaveFocus ( ) ;
285297 } ) ;
286298 } ) ;
287299} ) ;
0 commit comments