import { useNotification } from '@kyvg/vue3-notification'; import { FileManagementActions, InteractivityActions, NotificationPayload, NotificationsActions, SlidersActions } from '@3cr/types-ts'; import { useNotificationHandler } from '@/composables/useNotificationHandler'; describe('useNotificationHandler tests', () => { const { notify } = useNotification(); const { handler, announce } = useNotificationHandler(); it(`should handleNotification InteractivityActions.in01`, () => { const notification: NotificationPayload = { Action: InteractivityActions.in01, Code: 'S00001' } as NotificationPayload; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalled(); }); it(`should handleNotification InteractivityActions.in02`, () => { const notification: NotificationPayload = { Action: InteractivityActions.in02, Code: 'S00001' } as NotificationPayload; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalled(); }); it(`should handleNotification InteractivityActions.in03`, () => { const notification: NotificationPayload = { Action: InteractivityActions.in03, Code: 'S00001' } as NotificationPayload; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalled(); }); it(`should handleNotification InteractivityActions.in04`, () => { const notification: NotificationPayload = { Action: InteractivityActions.in04, Code: 'S00001' } as NotificationPayload; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalled(); }); it(`should handleNotification SlidersActions.sl01`, () => { const notification: NotificationPayload = { Action: SlidersActions.sl01, Code: 'S00001' } as NotificationPayload; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalled(); }); it(`should handleNotification success [MUTED] FileManagementActions.fm01`, () => { const notification: NotificationPayload = { Action: FileManagementActions.fm01, Code: 'S00001' } as NotificationPayload; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalledWith({ title: notification.Code, text: notification.Action, type: 'success' }); }); it(`should handleNotification info [MUTED] FileManagementActions.fm01`, () => { const notification: NotificationPayload = { Action: FileManagementActions.fm01, Code: 'I00001' } as NotificationPayload; handler(NotificationsActions.no04, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalledWith({ title: notification.Code, text: notification.Action, type: 'info' }); }); it(`should handleNotification failure FileManagementActions.fm01`, () => { const notification: NotificationPayload = { Action: FileManagementActions.fm01, Code: 'F00001' } as NotificationPayload; handler(NotificationsActions.no03, JSON.stringify(notification)); expect(notify).toHaveBeenCalledWith({ title: 'enums.notificationType.warning', text: notification.Code, type: 'warn' }); }); it(`should handleNotification warning FileManagementActions.fm01`, () => { const notification: NotificationPayload = { Action: FileManagementActions.fm01, Code: 'A00001' } as NotificationPayload; handler(NotificationsActions.no02, JSON.stringify(notification)); expect(notify).toHaveBeenCalledWith({ title: 'enums.notificationType.error', text: notification.Code, type: 'error' }); }); it(`should handleNotification slider mute FileManagementActions.fm01`, () => { vi.mocked(notify).mockClear(); const notification: NotificationPayload = { Action: SlidersActions.sl01, Code: 'A00001' } as NotificationPayload; handler(NotificationsActions.no02, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalledWith({ title: 'enums.notificationType.error', text: notification.Code, type: 'error' }); }); it(`should handleNotification success FileManagementActions.fm01`, () => { vi.mocked(notify).mockClear(); const notification: NotificationPayload = { Action: FileManagementActions.fm01, Code: 'S00001' } as NotificationPayload; announce(NotificationsActions.no01, notification); expect(notify).toHaveBeenCalledWith({ title: 'enums.notificationType.success', text: notification.Code, type: 'success' }); }); it(`should handleNotification info FileManagementActions.fm01`, () => { vi.mocked(notify).mockClear(); const notification: NotificationPayload = { Action: FileManagementActions.fm01, Code: 'I00001' } as NotificationPayload; announce(NotificationsActions.no04, notification); expect(notify).toHaveBeenCalledWith({ title: 'enums.notificationType.info', text: notification.Code, type: 'info' }); }); it(`should handleNotification default FileManagementActions.fm01`, () => { vi.mocked(notify).mockClear(); const notification: NotificationPayload = { Action: FileManagementActions.fm01, Code: 'I00001' } as NotificationPayload; announce(0 as unknown as NotificationsActions, notification); expect(notify).toHaveBeenCalledWith({ title: 'enums.notificationType.info', text: notification.Code, type: 'info' }); }); });