-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathcomms.test.ts
More file actions
172 lines (138 loc) · 5.03 KB
/
comms.test.ts
File metadata and controls
172 lines (138 loc) · 5.03 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// @vitest-environment happy-dom
import { mockSettings } from '../../__mocks__/state-mocks';
import { type Link, OpenPreference } from '../../types';
import * as storage from '../core/storage';
import {
applyKeyboardShortcut,
copyToClipboard,
decryptValue,
encryptValue,
getAppVersion,
hideWindow,
openExternalLink,
quitApp,
setAutoLaunch,
setUseAlternateIdleIcon,
showWindow,
updateTrayColor,
updateTrayTitle,
} from './comms';
describe('renderer/utils/comms.ts', () => {
describe('openExternalLink', () => {
it('should open an external link', () => {
vi.spyOn(storage, 'loadState').mockReturnValue({
settings: { ...mockSettings, openLinks: OpenPreference.BACKGROUND },
});
openExternalLink('https://gitify.io/' as Link);
expect(window.gitify.openExternalLink).toHaveBeenCalledTimes(1);
expect(window.gitify.openExternalLink).toHaveBeenCalledWith(
'https://gitify.io/',
false,
);
});
it('should open in foreground when preference set to FOREGROUND', () => {
vi.spyOn(storage, 'loadState').mockReturnValue({
settings: { ...mockSettings, openLinks: OpenPreference.FOREGROUND },
});
openExternalLink('https://gitify.io/' as Link);
expect(window.gitify.openExternalLink).toHaveBeenCalledWith(
'https://gitify.io/',
true,
);
});
it('should use default open preference if user settings not found', () => {
vi.spyOn(storage, 'loadState').mockReturnValue({
settings: null,
});
openExternalLink('https://gitify.io/' as Link);
expect(window.gitify.openExternalLink).toHaveBeenCalledTimes(1);
expect(window.gitify.openExternalLink).toHaveBeenCalledWith(
'https://gitify.io/',
true,
);
});
it('should ignore opening external local links file:///', () => {
openExternalLink('file:///Applications/SomeApp.app' as Link);
expect(window.gitify.openExternalLink).not.toHaveBeenCalled();
});
it('should ignore non-https links (http)', () => {
openExternalLink('http://example.com' as Link);
expect(window.gitify.openExternalLink).not.toHaveBeenCalled();
});
});
describe('app/version & crypto helpers', () => {
it('gets app version', async () => {
const version = await getAppVersion();
expect(window.gitify.app.version).toHaveBeenCalledTimes(1);
expect(version).toBe('v0.0.1');
});
it('encrypts value', async () => {
const value = await encryptValue('plain');
expect(window.gitify.encryptValue).toHaveBeenCalledTimes(1);
expect(window.gitify.encryptValue).toHaveBeenCalledWith('plain');
expect(value).toBe('encrypted');
});
it('decrypts value', async () => {
const value = await decryptValue('encrypted');
expect(window.gitify.decryptValue).toHaveBeenCalledTimes(1);
expect(window.gitify.decryptValue).toHaveBeenCalledWith('encrypted');
expect(value).toBe('decrypted');
});
});
describe('window / app actions', () => {
it('quits app', () => {
quitApp();
expect(window.gitify.app.quit).toHaveBeenCalledTimes(1);
});
it('shows window', () => {
showWindow();
expect(window.gitify.app.show).toHaveBeenCalledTimes(1);
});
it('hides window', () => {
hideWindow();
expect(window.gitify.app.hide).toHaveBeenCalledTimes(1);
});
});
describe('settings toggles', () => {
it('sets auto launch', () => {
setAutoLaunch(true);
expect(window.gitify.setAutoLaunch).toHaveBeenCalledTimes(1);
expect(window.gitify.setAutoLaunch).toHaveBeenCalledWith(true);
});
it('sets alternate idle icon', () => {
setUseAlternateIdleIcon(false);
expect(window.gitify.tray.useAlternateIdleIcon).toHaveBeenCalledTimes(1);
expect(window.gitify.tray.useAlternateIdleIcon).toHaveBeenCalledWith(
false,
);
});
it('applies keyboard shortcut', async () => {
await applyKeyboardShortcut({
enabled: true,
accelerator: 'CommandOrControl+Shift+G',
});
expect(window.gitify.applyKeyboardShortcut).toHaveBeenCalledTimes(1);
expect(window.gitify.applyKeyboardShortcut).toHaveBeenCalledWith({
enabled: true,
keyboardShortcut: 'CommandOrControl+Shift+G',
});
});
});
describe('tray helpers', () => {
it('updates tray icon color with count', () => {
updateTrayColor(5);
expect(window.gitify.tray.updateColor).toHaveBeenCalledTimes(1);
expect(window.gitify.tray.updateColor).toHaveBeenCalledWith(5);
});
it('updates tray title with provided value', () => {
updateTrayTitle('gitify');
expect(window.gitify.tray.updateTitle).toHaveBeenCalledTimes(1);
expect(window.gitify.tray.updateTitle).toHaveBeenCalledWith('gitify');
});
});
it('copy to clipboard', async () => {
copyToClipboard('some-value');
expect(navigator.clipboard.writeText).toHaveBeenCalledTimes(1);
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('some-value');
});
});