@@ -8,9 +8,11 @@ import {
88 quitApp ,
99 setAlternateIdleIcon ,
1010 setAutoLaunch ,
11+ setKeyboardShortcut ,
1112 showWindow ,
1213 updateTrayIcon ,
1314} from './comms' ;
15+ import { Constants } from './constants' ;
1416import * as storage from './storage' ;
1517
1618describe ( 'utils/comms.ts' , ( ) => {
@@ -23,6 +25,41 @@ describe('utils/comms.ts', () => {
2325 jest . clearAllMocks ( ) ;
2426 } ) ;
2527
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+
2663 it ( 'should get app version' , async ( ) => {
2764 await getAppVersion ( ) ;
2865 expect ( ipcRenderer . invoke ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -47,47 +84,6 @@ describe('utils/comms.ts', () => {
4784 expect ( ipcRenderer . send ) . toHaveBeenCalledWith ( 'gitify:window-hide' ) ;
4885 } ) ;
4986
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-
9187 it ( 'should setAutoLaunch (true)' , ( ) => {
9288 setAutoLaunch ( true ) ;
9389
@@ -114,4 +110,42 @@ describe('utils/comms.ts', () => {
114110 true ,
115111 ) ;
116112 } ) ;
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+ } ) ;
117151} ) ;
0 commit comments