@@ -109,7 +109,7 @@ function sendCancellableNotificationWithoutNotificationResponse(
109109
110110describe ( "Temporary Notification Controller" , ( ) => {
111111 describe ( "position" , ( ) => {
112- it ( "should render with default positions" , async function ( ) {
112+ it ( "should render with default positions" , async function ( ) {
113113 const Component = ( ) => {
114114 return < GoabTemporaryNotificationCtrl testId = "notification-ctrl" /> ;
115115 } ;
@@ -128,7 +128,7 @@ describe("Temporary Notification Controller", () => {
128128 } ) ;
129129 } ) ;
130130
131- it ( "should render with custom positions" , async function ( ) {
131+ it ( "should render with custom positions" , async function ( ) {
132132 const Component = ( ) => {
133133 return (
134134 < GoabTemporaryNotificationCtrl
@@ -154,37 +154,42 @@ describe("Temporary Notification Controller", () => {
154154 } ) ;
155155 } ) ;
156156
157- it ( "should show notification" , async function ( ) {
157+ it ( "should show notification" , async function ( ) {
158158 const Component = ( ) => {
159159 return < GoabTemporaryNotificationCtrl /> ;
160160 } ;
161161
162162 const result = render ( < Component /> ) ;
163163
164- await vi . waitFor ( ( ) => {
164+ setTimeout ( ( ) => {
165165 sendTemporaryNotification ( "This is the notification" , {
166166 testId : "some-notification" ,
167167 } ) ;
168+ } , 0 )
168169
170+ await vi . waitFor ( ( ) => {
169171 const notification = result . getByTestId ( "some-notification" ) ;
170172 expect ( notification . elements ( ) . length ) . toBe ( 1 ) ;
171173 } ) ;
172174 } ) ;
173175
174- it ( "should hide notification after specified duration" , async function ( ) {
176+ it ( "should hide notification after specified duration" , async function ( ) {
175177 const Component = ( ) => {
176178 return < GoabTemporaryNotificationCtrl /> ;
177179 } ;
178180
179181 const result = render ( < Component /> ) ;
180182 const notifications = result . getByTestId ( "short-notification" ) ;
181183
182- // ensure notification is visible
183- await vi . waitFor ( async ( ) => {
184+ setTimeout ( ( ) => {
184185 sendTemporaryNotification ( "This is a short notification" , {
185186 testId : "short-notification" ,
186187 duration : 100 ,
187188 } ) ;
189+ } , 0 ) ;
190+
191+ // ensure notification is visible
192+ await vi . waitFor ( ( ) => {
188193 expect ( notifications . elements ( ) . length ) . toBe ( 1 ) ;
189194 } ) ;
190195
@@ -194,7 +199,7 @@ describe("Temporary Notification Controller", () => {
194199 } ) ;
195200 } ) ;
196201
197- it ( "should handle action button click" , async function ( ) {
202+ it ( "should handle action button click" , async function ( ) {
198203 const Component = ( ) => {
199204 return < GoabTemporaryNotificationCtrl verticalPosition = { "top" } /> ;
200205 } ;
@@ -203,20 +208,22 @@ describe("Temporary Notification Controller", () => {
203208 const actionButton = result . getByRole ( "button" ) ;
204209 const actionMock = vi . fn ( ) ;
205210
206- await vi . waitFor ( async ( ) => {
211+ setTimeout ( ( ) => {
207212 sendTemporaryNotification ( "Notification with action" , {
208213 testId : "action-notification" ,
209214 actionText : "Undo" ,
210215 action : actionMock ,
211216 } ) ;
217+ } , 0 ) ;
212218
219+ await vi . waitFor ( async ( ) => {
213220 expect ( actionButton . elements ( ) . length ) . toBe ( 1 ) ;
214221 await actionButton . click ( ) ;
215222 expect ( actionMock ) . toHaveBeenCalledOnce ( ) ;
216223 } ) ;
217224 } ) ;
218225
219- it ( "should handle action button click and cancel notification" , async function ( ) {
226+ it ( "should handle action button click and cancel notification" , async function ( ) {
220227 const Component = ( ) => {
221228 return < GoabTemporaryNotificationCtrl verticalPosition = { "top" } /> ;
222229 } ;
@@ -225,27 +232,29 @@ describe("Temporary Notification Controller", () => {
225232 const notification = result . getByTestId ( "cancel-notification" ) ;
226233 const actionButton = result . getByRole ( "button" ) ;
227234
228- await vi . waitFor ( async ( ) => {
235+ setTimeout ( ( ) => {
229236 sendCancellableNotification (
230237 "Notification with cancel action" ,
231238 "cancel-notification" ,
232239 ) ;
240+ } , 0 ) ;
233241
242+ await vi . waitFor ( ( ) => {
234243 // Verify the notification is displayed
235244 expect ( notification . elements ( ) . length ) . toBe ( 1 ) ;
245+ } ) ;
236246
237- // Click the cancel button
238- expect ( actionButton . elements ( ) . length ) . toBe ( 1 ) ;
239- await actionButton . click ( ) ;
247+ // Click the cancel button
248+ expect ( actionButton . elements ( ) . length ) . toBe ( 1 ) ;
249+ await actionButton . click ( ) ;
240250
241- // Verify the notification is removed
242- await vi . waitFor ( ( ) => {
243- expect ( notification . elements ( ) . length ) . toBe ( 0 ) ;
244- } ) ;
251+ // Verify the notification is removed
252+ await vi . waitFor ( ( ) => {
253+ expect ( notification . elements ( ) . length ) . toBe ( 0 ) ;
245254 } ) ;
246255 } ) ;
247256
248- it ( "should allow for dismissing of the notification without a second notification from appearing" , async function ( ) {
257+ it ( "should allow for dismissing of the notification without a second notification from appearing" , async function ( ) {
249258 const Component = ( ) => {
250259 return < GoabTemporaryNotificationCtrl verticalPosition = { "top" } /> ;
251260 } ;
@@ -254,27 +263,29 @@ describe("Temporary Notification Controller", () => {
254263 const notification = result . getByTestId ( "cancel-notification" ) ;
255264 const actionButton = result . getByRole ( "button" ) ;
256265
257- await vi . waitFor ( async ( ) => {
266+ setTimeout ( ( ) => {
258267 sendCancellableNotificationWithoutNotificationResponse (
259268 "Notification with cancel action" ,
260269 "cancel-notification" ,
261270 ) ;
271+ } , 0 ) ;
262272
273+ await vi . waitFor ( ( ) => {
263274 // Verify the notification is displayed
264275 expect ( notification . elements ( ) . length ) . toBe ( 1 ) ;
276+ } ) ;
265277
266- // Click the cancel button
267- expect ( actionButton . elements ( ) . length ) . toBe ( 1 ) ;
268- await actionButton . click ( ) ;
278+ // Click the cancel button
279+ expect ( actionButton . elements ( ) . length ) . toBe ( 1 ) ;
280+ await actionButton . click ( ) ;
269281
270- // Verify the notification is removed
271- await vi . waitFor ( ( ) => {
272- expect ( notification . elements ( ) . length ) . toBe ( 0 ) ;
273- } ) ;
282+ // Verify the notification is removed
283+ await vi . waitFor ( ( ) => {
284+ expect ( notification . elements ( ) . length ) . toBe ( 0 ) ;
274285 } ) ;
275286 } ) ;
276287
277- it ( "should handle progress updates" , async function ( ) {
288+ it ( "should handle progress updates" , async function ( ) {
278289 const Component = ( ) => {
279290 return (
280291 < GoabTemporaryNotificationCtrl
@@ -285,15 +296,17 @@ describe("Temporary Notification Controller", () => {
285296 } ;
286297
287298 const result = render ( < Component /> ) ;
288-
289299 const progressIndicator = result . getByTestId ( "progress" ) ;
290300
291- await vi . waitFor ( ( ) => {
301+ setTimeout ( ( ) => {
292302 const uuid = sendTemporaryNotification ( "some message" , {
293303 testId : "some-notification" ,
294304 type : "progress" ,
295305 } ) ;
296306 sendProgress ( uuid , 10 ) ;
307+ } , 0 )
308+
309+ await vi . waitFor ( ( ) => {
297310 expect ( progressIndicator . element ( ) . getAttribute ( "value" ) ) . toBe ( "10" ) ;
298311 } ) ;
299312 } ) ;
0 commit comments