@@ -8,9 +8,11 @@ import {
8
8
quitApp ,
9
9
setAlternateIdleIcon ,
10
10
setAutoLaunch ,
11
+ setKeyboardShortcut ,
11
12
showWindow ,
12
13
updateTrayIcon ,
13
14
} from './comms' ;
15
+ import { Constants } from './constants' ;
14
16
import * as storage from './storage' ;
15
17
16
18
describe ( 'utils/comms.ts' , ( ) => {
@@ -23,6 +25,41 @@ describe('utils/comms.ts', () => {
23
25
jest . clearAllMocks ( ) ;
24
26
} ) ;
25
27
28
+ describe ( 'openExternalLink' , ( ) => {
29
+ it ( 'should open an external link' , ( ) => {
30
+ jest
31
+ . spyOn ( storage , 'loadState' )
32
+ . mockReturnValue ( { settings : mockSettings } ) ;
33
+
34
+ openExternalLink ( 'https://www.gitify.io/' as Link ) ;
35
+ expect ( shell . openExternal ) . toHaveBeenCalledTimes ( 1 ) ;
36
+ expect ( shell . openExternal ) . toHaveBeenCalledWith (
37
+ 'https://www.gitify.io/' ,
38
+ {
39
+ activate : true ,
40
+ } ,
41
+ ) ;
42
+ } ) ;
43
+
44
+ it ( 'should use default open preference if user settings not found' , ( ) => {
45
+ jest . spyOn ( storage , 'loadState' ) . mockReturnValue ( { settings : null } ) ;
46
+
47
+ openExternalLink ( 'https://www.gitify.io/' as Link ) ;
48
+ expect ( shell . openExternal ) . toHaveBeenCalledTimes ( 1 ) ;
49
+ expect ( shell . openExternal ) . toHaveBeenCalledWith (
50
+ 'https://www.gitify.io/' ,
51
+ {
52
+ activate : true ,
53
+ } ,
54
+ ) ;
55
+ } ) ;
56
+
57
+ it ( 'should ignore opening external local links file:///' , ( ) => {
58
+ openExternalLink ( 'file:///Applications/SomeApp.app' as Link ) ;
59
+ expect ( shell . openExternal ) . toHaveBeenCalledTimes ( 0 ) ;
60
+ } ) ;
61
+ } ) ;
62
+
26
63
it ( 'should get app version' , async ( ) => {
27
64
await getAppVersion ( ) ;
28
65
expect ( ipcRenderer . invoke ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -47,47 +84,6 @@ describe('utils/comms.ts', () => {
47
84
expect ( ipcRenderer . send ) . toHaveBeenCalledWith ( 'gitify:window-hide' ) ;
48
85
} ) ;
49
86
50
- it ( 'should send mark the icons as active' , ( ) => {
51
- const notificationsLength = 3 ;
52
- updateTrayIcon ( notificationsLength ) ;
53
- expect ( ipcRenderer . send ) . toHaveBeenCalledTimes ( 1 ) ;
54
- expect ( ipcRenderer . send ) . toHaveBeenCalledWith ( 'gitify:icon-active' ) ;
55
- } ) ;
56
-
57
- it ( 'should send mark the icons as idle' , ( ) => {
58
- const notificationsLength = 0 ;
59
- updateTrayIcon ( notificationsLength ) ;
60
- expect ( ipcRenderer . send ) . toHaveBeenCalledTimes ( 1 ) ;
61
- expect ( ipcRenderer . send ) . toHaveBeenCalledWith ( 'gitify:icon-idle' ) ;
62
- } ) ;
63
-
64
- it ( 'should open an external link' , ( ) => {
65
- jest
66
- . spyOn ( storage , 'loadState' )
67
- . mockReturnValue ( { settings : mockSettings } ) ;
68
-
69
- openExternalLink ( 'https://www.gitify.io/' as Link ) ;
70
- expect ( shell . openExternal ) . toHaveBeenCalledTimes ( 1 ) ;
71
- expect ( shell . openExternal ) . toHaveBeenCalledWith ( 'https://www.gitify.io/' , {
72
- activate : true ,
73
- } ) ;
74
- } ) ;
75
-
76
- it ( 'should use default open preference if user settings not found' , ( ) => {
77
- jest . spyOn ( storage , 'loadState' ) . mockReturnValue ( { settings : null } ) ;
78
-
79
- openExternalLink ( 'https://www.gitify.io/' as Link ) ;
80
- expect ( shell . openExternal ) . toHaveBeenCalledTimes ( 1 ) ;
81
- expect ( shell . openExternal ) . toHaveBeenCalledWith ( 'https://www.gitify.io/' , {
82
- activate : true ,
83
- } ) ;
84
- } ) ;
85
-
86
- it ( 'should ignore opening external local links file:///' , ( ) => {
87
- openExternalLink ( 'file:///Applications/SomeApp.app' as Link ) ;
88
- expect ( shell . openExternal ) . toHaveBeenCalledTimes ( 0 ) ;
89
- } ) ;
90
-
91
87
it ( 'should setAutoLaunch (true)' , ( ) => {
92
88
setAutoLaunch ( true ) ;
93
89
@@ -114,4 +110,42 @@ describe('utils/comms.ts', () => {
114
110
true ,
115
111
) ;
116
112
} ) ;
113
+
114
+ it ( 'should enable keyboard shortcut' , ( ) => {
115
+ setKeyboardShortcut ( true ) ;
116
+ expect ( ipcRenderer . send ) . toHaveBeenCalledTimes ( 1 ) ;
117
+ expect ( ipcRenderer . send ) . toHaveBeenCalledWith (
118
+ 'gitify:update-keyboard-shortcut' ,
119
+ {
120
+ enabled : true ,
121
+ keyboardShortcut : Constants . DEFAULT_KEYBOARD_SHORTCUT ,
122
+ } ,
123
+ ) ;
124
+ } ) ;
125
+
126
+ it ( 'should disable keyboard shortcut' , ( ) => {
127
+ setKeyboardShortcut ( false ) ;
128
+ expect ( ipcRenderer . send ) . toHaveBeenCalledTimes ( 1 ) ;
129
+ expect ( ipcRenderer . send ) . toHaveBeenCalledWith (
130
+ 'gitify:update-keyboard-shortcut' ,
131
+ {
132
+ enabled : false ,
133
+ keyboardShortcut : Constants . DEFAULT_KEYBOARD_SHORTCUT ,
134
+ } ,
135
+ ) ;
136
+ } ) ;
137
+
138
+ it ( 'should send mark the icons as active' , ( ) => {
139
+ const notificationsLength = 3 ;
140
+ updateTrayIcon ( notificationsLength ) ;
141
+ expect ( ipcRenderer . send ) . toHaveBeenCalledTimes ( 1 ) ;
142
+ expect ( ipcRenderer . send ) . toHaveBeenCalledWith ( 'gitify:icon-active' ) ;
143
+ } ) ;
144
+
145
+ it ( 'should send mark the icons as idle' , ( ) => {
146
+ const notificationsLength = 0 ;
147
+ updateTrayIcon ( notificationsLength ) ;
148
+ expect ( ipcRenderer . send ) . toHaveBeenCalledTimes ( 1 ) ;
149
+ expect ( ipcRenderer . send ) . toHaveBeenCalledWith ( 'gitify:icon-idle' ) ;
150
+ } ) ;
117
151
} ) ;
0 commit comments