From 822999a96718c199e227a7b11929c9458085c50e Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 29 Oct 2025 21:36:09 -0400 Subject: [PATCH 1/2] feat: set url for native notification Signed-off-by: Adam Setch --- src/renderer/utils/notifications/native.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/renderer/utils/notifications/native.ts b/src/renderer/utils/notifications/native.ts index f011f4c7e..6d0705868 100644 --- a/src/renderer/utils/notifications/native.ts +++ b/src/renderer/utils/notifications/native.ts @@ -3,6 +3,7 @@ import { APPLICATION } from '../../../shared/constants'; import type { AccountNotifications, GitifyState } from '../../types'; import type { Notification } from '../../typesGitHub'; import { getAccountUUID } from '../auth/utils'; +import { generateGitHubWebUrl } from '../helpers'; import { setTrayIconColor } from './notifications'; export const triggerNativeNotifications = ( @@ -50,10 +51,12 @@ export const triggerNativeNotifications = ( } }; -export const raiseNativeNotification = (notifications: Notification[]) => { +export const raiseNativeNotification = async ( + notifications: Notification[], +) => { let title: string; let body: string; - const url: string = null; + let url: string = null; if (notifications.length === 1) { const notification = notifications[0]; @@ -61,7 +64,7 @@ export const raiseNativeNotification = (notifications: Notification[]) => { ? '' : notification.repository.full_name; body = notification.subject.title; - // url intentionally left null (no direct subject URL available) + url = await generateGitHubWebUrl(notification); } else { title = APPLICATION.NAME; body = `You have ${notifications.length} notifications`; From 1e59a580ec2346635711b7f6a3f8fd5a074a7052 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Wed, 29 Oct 2025 21:45:47 -0400 Subject: [PATCH 2/2] feat: set url for native notification Signed-off-by: Adam Setch --- .../utils/notifications/native.test.ts | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/renderer/utils/notifications/native.test.ts b/src/renderer/utils/notifications/native.test.ts index 37933406f..856037f89 100644 --- a/src/renderer/utils/notifications/native.test.ts +++ b/src/renderer/utils/notifications/native.test.ts @@ -1,3 +1,5 @@ +import { waitFor } from '@testing-library/react'; + import { mockAccountNotifications, mockSingleAccountNotifications, @@ -15,7 +17,7 @@ describe('renderer/utils/notifications/native.ts', () => { }); describe('triggerNativeNotifications', () => { - it('should raise a native notification and play sound for a single new notification', () => { + it('should raise a native notification and play sound for a single new notification', async () => { const settings: SettingsState = { ...defaultSettings, playSound: true, @@ -26,8 +28,11 @@ describe('renderer/utils/notifications/native.ts', () => { auth: mockAuth, settings, }); + // wait for async native handling (generateGitHubWebUrl) to complete + await waitFor(() => + expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1), + ); - expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1); expect(window.gitify.raiseNativeNotification).toHaveBeenCalledWith( expect.stringContaining( mockSingleAccountNotifications[0].notifications[0].repository @@ -36,14 +41,19 @@ describe('renderer/utils/notifications/native.ts', () => { expect.stringContaining( mockSingleAccountNotifications[0].notifications[0].subject.title, ), - null, + expect.stringContaining( + mockSingleAccountNotifications[0].notifications[0].repository + .html_url, + ), ); - expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1); + await waitFor(() => + expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1), + ); expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.2); }); - it('should raise a native notification and play sound for multiple new notifications', () => { + it('should raise a native notification and play sound for multiple new notifications', async () => { const settings: SettingsState = { ...defaultSettings, playSound: true, @@ -54,15 +64,19 @@ describe('renderer/utils/notifications/native.ts', () => { auth: mockAuth, settings, }); + await waitFor(() => + expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1), + ); - expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1); expect(window.gitify.raiseNativeNotification).toHaveBeenCalledWith( 'Gitify', 'You have 4 notifications', null, ); - expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1); + await waitFor(() => + expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1), + ); expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.2); });