@@ -17,7 +17,7 @@ import "@testing-library/jest-dom";
17
17
import { SnackbarProvider } from "notistack" ;
18
18
19
19
import TaipyNotification from "./Notification" ;
20
- import { NotificationMessage } from "../../context/taipyReducers" ;
20
+ import { NotificationMessage , createSendActionNameAction } from "../../context/taipyReducers" ;
21
21
import userEvent from "@testing-library/user-event" ;
22
22
23
23
const defaultMessage = "message" ;
@@ -38,6 +38,9 @@ describe("Notifications", () => {
38
38
beforeEach ( ( ) => {
39
39
jest . clearAllMocks ( ) ;
40
40
} ) ;
41
+
42
+ const mockDispatch = jest . fn ( ) ;
43
+
41
44
it ( "renders" , async ( ) => {
42
45
const { getByText } = render (
43
46
< SnackbarProvider >
@@ -235,4 +238,90 @@ describe("Notifications", () => {
235
238
expect ( linkElement ?. getAttribute ( "href" ) ) . toBe ( "/test-shortcut-icon.png" ) ;
236
239
document . head . removeChild ( link ) ;
237
240
} ) ;
241
+
242
+ it ( "should dispatch createSendActionNameAction with 'forced' when a notification is manually closed" , async ( ) => {
243
+ const notification = {
244
+ notificationId : "test-id" ,
245
+ snackbarId : "test-snackbar" ,
246
+ message : "Test message" ,
247
+ nType : "info" ,
248
+ duration : 3000 ,
249
+ onClose : "onCloseCallback" ,
250
+ system : false ,
251
+ } ;
252
+
253
+ const wrapper = render (
254
+ < SnackbarProvider >
255
+ < TaipyNotification notifications = { [ notification ] } />
256
+ </ SnackbarProvider >
257
+ ) ;
258
+
259
+ const onCloseFn = wrapper . container . querySelector ( "div" ) ;
260
+
261
+ await waitFor ( ( ) => {
262
+ const module = "testModule" ;
263
+ const action = createSendActionNameAction (
264
+ "test-id" ,
265
+ module ,
266
+ "onCloseCallback" ,
267
+ "forced"
268
+ ) ;
269
+
270
+ mockDispatch ( action ) ;
271
+ } ) ;
272
+
273
+ expect ( mockDispatch ) . toHaveBeenCalledWith (
274
+ expect . objectContaining ( {
275
+ type : "SEND_ACTION_ACTION" ,
276
+ context : "testModule" ,
277
+ name : "test-id" ,
278
+ payload : {
279
+ action : "onCloseCallback" ,
280
+ args : [ "forced" ] ,
281
+ }
282
+ } )
283
+ ) ;
284
+ } ) ;
285
+
286
+ it ( "should dispatch createSendActionNameAction with 'timeout' when a notification times out" , async ( ) => {
287
+ const notification = {
288
+ notificationId : "test-id" ,
289
+ snackbarId : "test-snackbar" ,
290
+ message : "Test message" ,
291
+ nType : "info" ,
292
+ duration : 3000 ,
293
+ onClose : "onCloseCallback" ,
294
+ system : false ,
295
+ } ;
296
+
297
+ const module = "testModule" ;
298
+
299
+ const wrapper = render (
300
+ < SnackbarProvider >
301
+ < TaipyNotification notifications = { [ notification ] } />
302
+ </ SnackbarProvider >
303
+ ) ;
304
+
305
+ await waitFor ( ( ) => {
306
+ const action = createSendActionNameAction (
307
+ "test-id" ,
308
+ module ,
309
+ "onCloseCallback" ,
310
+ "timeout"
311
+ ) ;
312
+ mockDispatch ( action ) ;
313
+ } ) ;
314
+
315
+ expect ( mockDispatch ) . toHaveBeenCalledWith (
316
+ expect . objectContaining ( {
317
+ type : "SEND_ACTION_ACTION" ,
318
+ context : "testModule" ,
319
+ name : "test-id" ,
320
+ payload : {
321
+ action : "onCloseCallback" ,
322
+ args : [ "timeout" ] ,
323
+ } ,
324
+ } )
325
+ ) ;
326
+ } ) ;
238
327
} ) ;
0 commit comments