@@ -72,12 +72,13 @@ describe('ConnectionMonitor', () => {
7272 expect ( screen . getByText ( 'Cannot connect' ) ) . toBeInTheDocument ( ) ;
7373 } , { timeout : 6000 } ) ;
7474
75- // Should show countdown
75+ // Should show countdown - wait for it to appear since it's async
7676 await waitFor ( ( ) => {
7777 expect ( screen . getByText ( / R e t r y i n g i n \d + s e c o n d / ) ) . toBeInTheDocument ( ) ;
78- } , { timeout : 1000 } ) ;
78+ } , { timeout : 2000 } ) ;
7979
8080 // Modal should disappear when automatic retry succeeds
81+ // This should happen after the RETRY_INTERVAL (10 seconds)
8182 await waitFor ( ( ) => {
8283 expect ( screen . queryByText ( 'Cannot connect' ) ) . not . toBeInTheDocument ( ) ;
8384 } , { timeout : 12000 } ) ;
@@ -92,10 +93,25 @@ describe('ConnectionMonitor', () => {
9293
9394 render ( < ConnectionMonitor /> ) ;
9495
96+ // Wait for modal to appear
9597 await waitFor ( ( ) => {
9698 expect ( screen . getByText ( 'Cannot connect' ) ) . toBeInTheDocument ( ) ;
9799 } , { timeout : 4000 } ) ;
98100
99- expect ( screen . getByText ( / R e t r y i n g i n \d + s e c o n d / ) ) . toBeInTheDocument ( ) ;
100- } , 6000 ) ;
101+ await waitFor ( ( ) => {
102+ expect ( screen . getByText ( / R e t r y i n g i n \d + s e c o n d / ) ) . toBeInTheDocument ( ) ;
103+ } , { timeout : 2000 } ) ;
104+
105+ // Verify the countdown is actually working by checking it's a reasonable value
106+ const countdownElement = screen . getByText ( / R e t r y i n g i n \d + s e c o n d / ) ;
107+ const countdownText = countdownElement . textContent || '' ;
108+ const secondsMatch = countdownText . match ( / R e t r y i n g i n ( \d + ) s e c o n d / ) ;
109+
110+ if ( secondsMatch ) {
111+ const seconds = parseInt ( secondsMatch [ 1 ] , 10 ) ;
112+ // Should be between 1-10 seconds (since RETRY_INTERVAL is 10 seconds)
113+ expect ( seconds ) . toBeGreaterThan ( 0 ) ;
114+ expect ( seconds ) . toBeLessThanOrEqual ( 10 ) ;
115+ }
116+ } , 8000 ) ;
101117} ) ;
0 commit comments