import { useNotificationHandler } from '@/composables/useNotificationHandler'; import { FileManagementActions, InteractivityActions, NotificationPayload, NotificationsActions, SlidersActions, } from '@3cr/types-ts'; import { useNotification } from '@kyvg/vue3-notification'; describe('useNotificationHandler tests', () => { const { notify } = useNotification(); const { handler, announce } = useNotificationHandler(); afterEach(() => { vi.clearAllMocks(); }); it('should handleNotification InteractivityActions.in01', () => { const notification = { Action: InteractivityActions.in01, Code: 'S00001' }; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalled(); }); it('should handleNotification InteractivityActions.in02', () => { const notification = { Action: InteractivityActions.in02, Code: 'S00001' }; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalled(); }); it('should handleNotification InteractivityActions.in03', () => { const notification = { Action: InteractivityActions.in03, Code: 'S00001' }; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalled(); }); it('should handleNotification InteractivityActions.in04', () => { const notification = { Action: InteractivityActions.in04, Code: 'S00001' }; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalled(); }); it('should handleNotification SlidersActions.sl01', () => { const notification = { Action: SlidersActions.sl01, Code: 'S00001' }; handler(NotificationsActions.no01, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalled(); }); it('should handleNotification success [MUTED] FileManagementActions.fm01', () => { const notification = { Action: FileManagementActions.fm01, Code: 'S00001' }; 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 = { Action: FileManagementActions.fm01, Code: 'I00001' }; 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 = { Action: FileManagementActions.fm01, Code: 'F00001' }; handler(NotificationsActions.no03, JSON.stringify(notification)); expect(notify).toHaveBeenCalledWith({ title: 'enums.notificationType.warning', text: 'Function is not defined', type: 'warn', }); }); it('should handleNotification warning FileManagementActions.fm01', () => { const notification = { Action: FileManagementActions.fm01, Code: 'A00001' }; handler(NotificationsActions.no02, JSON.stringify(notification)); expect(notify).toHaveBeenCalledWith({ title: 'enums.notificationType.error', text: 'Input value exceeded limits defined', type: 'error', }); }); it('should handleNotification slider mute FileManagementActions.fm01', () => { const notification = { Action: SlidersActions.sl01, Code: 'A00001' }; handler(NotificationsActions.no02, JSON.stringify(notification)); expect(notify).not.toHaveBeenCalledWith({ title: 'enums.notificationType.error', text: 'Input value exceeded limits defined', type: 'error', }); }); it('should handleNotification success FileManagementActions.fm01', () => { const notification = { Action: FileManagementActions.fm01, Code: 'S00001', } as NotificationPayload; announce(NotificationsActions.no01, notification); expect(notify).toHaveBeenCalledWith({ title: 'enums.notificationType.success', text: 'Action from Front End has completed.', type: 'success', }); }); it('should handleNotification info FileManagementActions.fm01', () => { const notification = { Action: FileManagementActions.fm01, Code: 'I00001', } as NotificationPayload; announce(NotificationsActions.no04, notification); expect(notify).toHaveBeenCalledWith({ title: 'enums.notificationType.info', text: 'Reading file from cache', type: 'info', }); }); it('should handleNotification default FileManagementActions.fm01', () => { const notification = { Action: FileManagementActions.fm01, Code: 'I00001', } as NotificationPayload; announce(0 as unknown as NotificationsActions, notification); expect(notify).toHaveBeenCalledWith({ title: 'enums.notificationType.info', text: 'Reading file from cache', type: 'info', }); }); });