Skip to content

Commit fef606a

Browse files
authored
feat: set url for native notification (#2338)
* feat: set url for native notification Signed-off-by: Adam Setch <[email protected]> * feat: set url for native notification Signed-off-by: Adam Setch <[email protected]> --------- Signed-off-by: Adam Setch <[email protected]>
1 parent 05f92dd commit fef606a

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/renderer/utils/notifications/native.test.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { waitFor } from '@testing-library/react';
2+
13
import {
24
mockAccountNotifications,
35
mockSingleAccountNotifications,
@@ -15,7 +17,7 @@ describe('renderer/utils/notifications/native.ts', () => {
1517
});
1618

1719
describe('triggerNativeNotifications', () => {
18-
it('should raise a native notification and play sound for a single new notification', () => {
20+
it('should raise a native notification and play sound for a single new notification', async () => {
1921
const settings: SettingsState = {
2022
...defaultSettings,
2123
playSound: true,
@@ -26,8 +28,11 @@ describe('renderer/utils/notifications/native.ts', () => {
2628
auth: mockAuth,
2729
settings,
2830
});
31+
// wait for async native handling (generateGitHubWebUrl) to complete
32+
await waitFor(() =>
33+
expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1),
34+
);
2935

30-
expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1);
3136
expect(window.gitify.raiseNativeNotification).toHaveBeenCalledWith(
3237
expect.stringContaining(
3338
mockSingleAccountNotifications[0].notifications[0].repository
@@ -36,14 +41,19 @@ describe('renderer/utils/notifications/native.ts', () => {
3641
expect.stringContaining(
3742
mockSingleAccountNotifications[0].notifications[0].subject.title,
3843
),
39-
null,
44+
expect.stringContaining(
45+
mockSingleAccountNotifications[0].notifications[0].repository
46+
.html_url,
47+
),
4048
);
4149

42-
expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1);
50+
await waitFor(() =>
51+
expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1),
52+
);
4353
expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.2);
4454
});
4555

46-
it('should raise a native notification and play sound for multiple new notifications', () => {
56+
it('should raise a native notification and play sound for multiple new notifications', async () => {
4757
const settings: SettingsState = {
4858
...defaultSettings,
4959
playSound: true,
@@ -54,15 +64,19 @@ describe('renderer/utils/notifications/native.ts', () => {
5464
auth: mockAuth,
5565
settings,
5666
});
67+
await waitFor(() =>
68+
expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1),
69+
);
5770

58-
expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1);
5971
expect(window.gitify.raiseNativeNotification).toHaveBeenCalledWith(
6072
'Gitify',
6173
'You have 4 notifications',
6274
null,
6375
);
6476

65-
expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1);
77+
await waitFor(() =>
78+
expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1),
79+
);
6680
expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.2);
6781
});
6882

src/renderer/utils/notifications/native.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { APPLICATION } from '../../../shared/constants';
33
import type { AccountNotifications, GitifyState } from '../../types';
44
import type { Notification } from '../../typesGitHub';
55
import { getAccountUUID } from '../auth/utils';
6+
import { generateGitHubWebUrl } from '../helpers';
67
import { setTrayIconColor } from './notifications';
78

89
export const triggerNativeNotifications = (
@@ -50,18 +51,20 @@ export const triggerNativeNotifications = (
5051
}
5152
};
5253

53-
export const raiseNativeNotification = (notifications: Notification[]) => {
54+
export const raiseNativeNotification = async (
55+
notifications: Notification[],
56+
) => {
5457
let title: string;
5558
let body: string;
56-
const url: string = null;
59+
let url: string = null;
5760

5861
if (notifications.length === 1) {
5962
const notification = notifications[0];
6063
title = window.gitify.platform.isWindows()
6164
? ''
6265
: notification.repository.full_name;
6366
body = notification.subject.title;
64-
// url intentionally left null (no direct subject URL available)
67+
url = await generateGitHubWebUrl(notification);
6568
} else {
6669
title = APPLICATION.NAME;
6770
body = `You have ${notifications.length} notifications`;

0 commit comments

Comments
 (0)