-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathnative.test.ts
More file actions
140 lines (115 loc) · 4.32 KB
/
native.test.ts
File metadata and controls
140 lines (115 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import {
mockAccountNotifications,
mockSingleAccountNotifications,
} from '../../__mocks__/notifications-mocks';
import { mockAuth } from '../../__mocks__/state-mocks';
import { defaultSettings } from '../../context/defaults';
import type { SettingsState } from '../../types';
import { mockGitHubNotifications } from '../api/__mocks__/response-mocks';
import * as comms from '../comms';
import * as links from '../links';
import * as native from './native';
const raiseNativeNotificationMock = jest.spyOn(
native,
'raiseNativeNotification',
);
const raiseSoundNotificationMock = jest.spyOn(native, 'raiseSoundNotification');
describe('renderer/utils/notifications/native.ts', () => {
afterEach(() => {
jest.clearAllMocks();
});
describe('triggerNativeNotifications', () => {
it('should raise a native notification and play sound for a single new notification', () => {
const settings: SettingsState = {
...defaultSettings,
playSound: true,
showNotifications: true,
};
native.triggerNativeNotifications([], mockSingleAccountNotifications, {
auth: mockAuth,
settings,
});
expect(raiseNativeNotificationMock).toHaveBeenCalledTimes(1);
expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1);
expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.2);
});
it('should raise a native notification and play sound for multiple new notifications', () => {
const settings: SettingsState = {
...defaultSettings,
playSound: true,
showNotifications: true,
};
native.triggerNativeNotifications([], mockAccountNotifications, {
auth: mockAuth,
settings,
});
expect(raiseNativeNotificationMock).toHaveBeenCalledTimes(1);
expect(raiseSoundNotificationMock).toHaveBeenCalledTimes(1);
expect(raiseSoundNotificationMock).toHaveBeenCalledWith(0.2);
});
it('should not raise a native notification or play a sound when there are no new notifications', () => {
const settings: SettingsState = {
...defaultSettings,
playSound: true,
showNotifications: true,
};
native.triggerNativeNotifications(
mockSingleAccountNotifications,
mockSingleAccountNotifications,
{
auth: mockAuth,
settings,
},
);
expect(raiseNativeNotificationMock).not.toHaveBeenCalled();
expect(raiseSoundNotificationMock).not.toHaveBeenCalled();
});
it('should not raise a native notification or play a sound when there are zero notifications', () => {
const settings: SettingsState = {
...defaultSettings,
playSound: true,
showNotifications: true,
};
native.triggerNativeNotifications([], [], {
auth: mockAuth,
settings,
});
expect(raiseNativeNotificationMock).not.toHaveBeenCalled();
expect(raiseSoundNotificationMock).not.toHaveBeenCalled();
});
it('should not raise a native notification when setting disabled', () => {
const settings: SettingsState = {
...defaultSettings,
showNotifications: false,
};
native.triggerNativeNotifications([], mockAccountNotifications, {
auth: mockAuth,
settings,
});
expect(raiseNativeNotificationMock).not.toHaveBeenCalled();
});
});
describe('raiseNativeNotification', () => {
it('should click on a native notification (with 1 notification)', () => {
const hideWindowMock = jest.spyOn(comms, 'hideWindow');
jest.spyOn(links, 'openNotification');
const nativeNotification: Notification = native.raiseNativeNotification([
mockGitHubNotifications[0],
]);
nativeNotification.onclick(null);
expect(links.openNotification).toHaveBeenCalledTimes(1);
expect(links.openNotification).toHaveBeenLastCalledWith(
mockGitHubNotifications[0],
);
expect(hideWindowMock).toHaveBeenCalledTimes(1);
});
it('should click on a native notification (with more than 1 notification)', () => {
const showWindowMock = jest.spyOn(comms, 'showWindow');
const nativeNotification = native.raiseNativeNotification(
mockGitHubNotifications,
);
nativeNotification.onclick(null);
expect(showWindowMock).toHaveBeenCalledTimes(1);
});
});
});