|
1 | | -import { waitFor } from '@testing-library/react'; |
2 | | - |
3 | | -import { |
4 | | - mockAccountNotifications, |
5 | | - mockSingleAccountNotifications, |
6 | | -} from '../../__mocks__/notifications-mocks'; |
7 | | -import { mockAuth } from '../../__mocks__/state-mocks'; |
8 | | -import { defaultSettings } from '../../context/defaults'; |
9 | | -import type { SettingsState } from '../../types'; |
10 | | -import * as native from './native'; |
11 | | - |
12 | | -const raiseSoundNotificationMock = jest.spyOn(native, 'raiseSoundNotification'); |
13 | | - |
14 | | -describe('renderer/utils/notifications/native.ts', () => { |
15 | | - afterEach(() => { |
16 | | - jest.clearAllMocks(); |
17 | | - }); |
18 | | - |
19 | | - describe('triggerNativeNotifications', () => { |
20 | | - it('should raise a native notification and play sound for a single new notification', async () => { |
21 | | - const settings: SettingsState = { |
22 | | - ...defaultSettings, |
23 | | - playSound: true, |
24 | | - showNotifications: true, |
25 | | - }; |
26 | | - |
27 | | - native.triggerNativeNotifications([], mockSingleAccountNotifications, { |
28 | | - auth: mockAuth, |
29 | | - settings, |
30 | | - }); |
31 | | - |
32 | | - // wait for async native handling (generateGitHubWebUrl) to complete |
33 | | - await waitFor(() => |
34 | | - expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1), |
35 | | - ); |
36 | | - |
37 | | - expect(window.gitify.raiseNativeNotification).toHaveBeenCalledWith( |
38 | | - expect.stringContaining( |
39 | | - mockSingleAccountNotifications[0].notifications[0].repository |
40 | | - .full_name, |
41 | | - ), |
42 | | - expect.stringContaining( |
43 | | - mockSingleAccountNotifications[0].notifications[0].subject.title, |
44 | | - ), |
45 | | - expect.stringContaining( |
46 | | - mockSingleAccountNotifications[0].notifications[0].repository |
47 | | - .html_url, |
48 | | - ), |
49 | | - ); |
50 | | - |
51 | | - await waitFor(() => |
52 | | - expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1), |
53 | | - ); |
54 | | - expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.2); |
55 | | - }); |
56 | | - |
57 | | - it('should raise a native notification and play sound for multiple new notifications', async () => { |
58 | | - const settings: SettingsState = { |
59 | | - ...defaultSettings, |
60 | | - playSound: true, |
61 | | - showNotifications: true, |
62 | | - }; |
63 | | - |
64 | | - native.triggerNativeNotifications([], mockAccountNotifications, { |
65 | | - auth: mockAuth, |
66 | | - settings, |
67 | | - }); |
68 | | - |
69 | | - await waitFor(() => |
70 | | - expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1), |
71 | | - ); |
72 | | - |
73 | | - expect(window.gitify.raiseNativeNotification).toHaveBeenCalledWith( |
74 | | - 'Gitify', |
75 | | - 'You have 4 notifications', |
76 | | - null, |
77 | | - ); |
78 | | - |
79 | | - await waitFor(() => |
80 | | - expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1), |
81 | | - ); |
82 | | - expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.2); |
83 | | - }); |
84 | | - |
85 | | - it('should not raise a native notification or play a sound when there are no new notifications', () => { |
86 | | - const settings: SettingsState = { |
87 | | - ...defaultSettings, |
88 | | - playSound: true, |
89 | | - showNotifications: true, |
90 | | - }; |
91 | | - |
92 | | - native.triggerNativeNotifications( |
93 | | - mockSingleAccountNotifications, |
94 | | - mockSingleAccountNotifications, |
95 | | - { |
96 | | - auth: mockAuth, |
97 | | - settings, |
98 | | - }, |
99 | | - ); |
100 | | - |
101 | | - expect(window.gitify.raiseNativeNotification).not.toHaveBeenCalled(); |
102 | | - expect(raiseSoundNotificationMock).not.toHaveBeenCalled(); |
103 | | - }); |
104 | | - |
105 | | - it('should not raise a native notification or play a sound when there are zero notifications', () => { |
106 | | - const settings: SettingsState = { |
107 | | - ...defaultSettings, |
108 | | - playSound: true, |
109 | | - showNotifications: true, |
110 | | - }; |
111 | | - |
112 | | - native.triggerNativeNotifications([], [], { |
113 | | - auth: mockAuth, |
114 | | - settings, |
115 | | - }); |
116 | | - |
117 | | - expect(window.gitify.raiseNativeNotification).not.toHaveBeenCalled(); |
118 | | - expect(raiseSoundNotificationMock).not.toHaveBeenCalled(); |
119 | | - }); |
120 | | - |
121 | | - it('should not raise a native notification when setting disabled', () => { |
122 | | - const settings: SettingsState = { |
123 | | - ...defaultSettings, |
124 | | - showNotifications: false, |
125 | | - }; |
126 | | - |
127 | | - native.triggerNativeNotifications([], mockAccountNotifications, { |
128 | | - auth: mockAuth, |
129 | | - settings, |
130 | | - }); |
131 | | - |
132 | | - expect(window.gitify.raiseNativeNotification).not.toHaveBeenCalled(); |
133 | | - }); |
134 | | - }); |
135 | | -}); |
| 1 | +// import { waitFor } from '@testing-library/react'; |
| 2 | + |
| 3 | +// import { |
| 4 | +// mockAccountNotifications, |
| 5 | +// mockSingleAccountNotifications, |
| 6 | +// } from '../../__mocks__/notifications-mocks'; |
| 7 | +// import { mockAuth } from '../../__mocks__/state-mocks'; |
| 8 | +// import { defaultSettings } from '../../context/defaults'; |
| 9 | +// import type { SettingsState } from '../../types'; |
| 10 | +// import * as native from './native'; |
| 11 | + |
| 12 | +// const raiseSoundNotificationMock = jest.spyOn(native, 'raiseSoundNotification'); |
| 13 | + |
| 14 | +// describe('renderer/utils/notifications/native.ts', () => { |
| 15 | +// afterEach(() => { |
| 16 | +// jest.clearAllMocks(); |
| 17 | +// }); |
| 18 | + |
| 19 | +// describe('triggerNativeNotifications', () => { |
| 20 | +// it('should raise a native notification and play sound for a single new notification', async () => { |
| 21 | +// const settings: SettingsState = { |
| 22 | +// ...defaultSettings, |
| 23 | +// playSound: true, |
| 24 | +// showNotifications: true, |
| 25 | +// }; |
| 26 | + |
| 27 | +// native.triggerNativeNotifications([], mockSingleAccountNotifications, { |
| 28 | +// auth: mockAuth, |
| 29 | +// settings, |
| 30 | +// }); |
| 31 | + |
| 32 | +// // wait for async native handling (generateGitHubWebUrl) to complete |
| 33 | +// await waitFor(() => |
| 34 | +// expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1), |
| 35 | +// ); |
| 36 | + |
| 37 | +// expect(window.gitify.raiseNativeNotification).toHaveBeenCalledWith( |
| 38 | +// expect.stringContaining( |
| 39 | +// mockSingleAccountNotifications[0].notifications[0].repository |
| 40 | +// .full_name, |
| 41 | +// ), |
| 42 | +// expect.stringContaining( |
| 43 | +// mockSingleAccountNotifications[0].notifications[0].subject.title, |
| 44 | +// ), |
| 45 | +// expect.stringContaining( |
| 46 | +// mockSingleAccountNotifications[0].notifications[0].repository |
| 47 | +// .html_url, |
| 48 | +// ), |
| 49 | +// ); |
| 50 | + |
| 51 | +// await waitFor(() => |
| 52 | +// expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1), |
| 53 | +// ); |
| 54 | +// expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.2); |
| 55 | +// }); |
| 56 | + |
| 57 | +// it('should raise a native notification and play sound for multiple new notifications', async () => { |
| 58 | +// const settings: SettingsState = { |
| 59 | +// ...defaultSettings, |
| 60 | +// playSound: true, |
| 61 | +// showNotifications: true, |
| 62 | +// }; |
| 63 | + |
| 64 | +// native.triggerNativeNotifications([], mockAccountNotifications, { |
| 65 | +// auth: mockAuth, |
| 66 | +// settings, |
| 67 | +// }); |
| 68 | + |
| 69 | +// await waitFor(() => |
| 70 | +// expect(window.gitify.raiseNativeNotification).toHaveBeenCalledTimes(1), |
| 71 | +// ); |
| 72 | + |
| 73 | +// expect(window.gitify.raiseNativeNotification).toHaveBeenCalledWith( |
| 74 | +// 'Gitify', |
| 75 | +// 'You have 4 notifications', |
| 76 | +// null, |
| 77 | +// ); |
| 78 | + |
| 79 | +// await waitFor(() => |
| 80 | +// expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1), |
| 81 | +// ); |
| 82 | +// expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.2); |
| 83 | +// }); |
| 84 | + |
| 85 | +// it('should not raise a native notification or play a sound when there are no new notifications', () => { |
| 86 | +// const settings: SettingsState = { |
| 87 | +// ...defaultSettings, |
| 88 | +// playSound: true, |
| 89 | +// showNotifications: true, |
| 90 | +// }; |
| 91 | + |
| 92 | +// native.triggerNativeNotifications( |
| 93 | +// mockSingleAccountNotifications, |
| 94 | +// mockSingleAccountNotifications, |
| 95 | +// { |
| 96 | +// auth: mockAuth, |
| 97 | +// settings, |
| 98 | +// }, |
| 99 | +// ); |
| 100 | + |
| 101 | +// expect(window.gitify.raiseNativeNotification).not.toHaveBeenCalled(); |
| 102 | +// expect(raiseSoundNotificationMock).not.toHaveBeenCalled(); |
| 103 | +// }); |
| 104 | + |
| 105 | +// it('should not raise a native notification or play a sound when there are zero notifications', () => { |
| 106 | +// const settings: SettingsState = { |
| 107 | +// ...defaultSettings, |
| 108 | +// playSound: true, |
| 109 | +// showNotifications: true, |
| 110 | +// }; |
| 111 | + |
| 112 | +// native.triggerNativeNotifications([], [], { |
| 113 | +// auth: mockAuth, |
| 114 | +// settings, |
| 115 | +// }); |
| 116 | + |
| 117 | +// expect(window.gitify.raiseNativeNotification).not.toHaveBeenCalled(); |
| 118 | +// expect(raiseSoundNotificationMock).not.toHaveBeenCalled(); |
| 119 | +// }); |
| 120 | + |
| 121 | +// it('should not raise a native notification when setting disabled', () => { |
| 122 | +// const settings: SettingsState = { |
| 123 | +// ...defaultSettings, |
| 124 | +// showNotifications: false, |
| 125 | +// }; |
| 126 | + |
| 127 | +// native.triggerNativeNotifications([], mockAccountNotifications, { |
| 128 | +// auth: mockAuth, |
| 129 | +// settings, |
| 130 | +// }); |
| 131 | + |
| 132 | +// expect(window.gitify.raiseNativeNotification).not.toHaveBeenCalled(); |
| 133 | +// }); |
| 134 | +// }); |
| 135 | +// }); |
0 commit comments