@@ -72,12 +72,13 @@ describe('ConnectionMonitor', () => {
72
72
expect ( screen . getByText ( 'Cannot connect' ) ) . toBeInTheDocument ( ) ;
73
73
} , { timeout : 6000 } ) ;
74
74
75
- // Should show countdown
75
+ // Should show countdown - wait for it to appear since it's async
76
76
await waitFor ( ( ) => {
77
77
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 } ) ;
79
79
80
80
// Modal should disappear when automatic retry succeeds
81
+ // This should happen after the RETRY_INTERVAL (10 seconds)
81
82
await waitFor ( ( ) => {
82
83
expect ( screen . queryByText ( 'Cannot connect' ) ) . not . toBeInTheDocument ( ) ;
83
84
} , { timeout : 12000 } ) ;
@@ -92,10 +93,25 @@ describe('ConnectionMonitor', () => {
92
93
93
94
render ( < ConnectionMonitor /> ) ;
94
95
96
+ // Wait for modal to appear
95
97
await waitFor ( ( ) => {
96
98
expect ( screen . getByText ( 'Cannot connect' ) ) . toBeInTheDocument ( ) ;
97
99
} , { timeout : 4000 } ) ;
98
100
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 ) ;
101
117
} ) ;
0 commit comments