@@ -4,6 +4,7 @@ import { MemoryRouter } from 'react-router-dom';
44import { renderWithAppContext } from '../__helpers__/test-utils' ;
55
66import * as comms from '../utils/comms' ;
7+ import * as links from '../utils/links' ;
78import { GlobalShortcuts } from './GlobalShortcuts' ;
89
910const navigateMock = jest . fn ( ) ;
@@ -22,6 +23,20 @@ describe('components/GlobalShortcuts.tsx', () => {
2223 } ) ;
2324
2425 describe ( 'key bindings' , ( ) => {
26+ describe ( 'ignores keys that are not valid' , ( ) => {
27+ it ( 'ignores B key' , async ( ) => {
28+ renderWithAppContext (
29+ < MemoryRouter >
30+ < GlobalShortcuts />
31+ </ MemoryRouter > ,
32+ ) ;
33+
34+ await userEvent . keyboard ( 'b' ) ;
35+
36+ expect ( navigateMock ) . not . toHaveBeenCalled ( ) ;
37+ } ) ;
38+ } ) ;
39+
2540 describe ( 'home' , ( ) => {
2641 it ( 'navigates home when pressing H key' , async ( ) => {
2742 renderWithAppContext (
@@ -36,6 +51,42 @@ describe('components/GlobalShortcuts.tsx', () => {
3651 } ) ;
3752 } ) ;
3853
54+ describe ( 'openGitHubNotifications' , ( ) => {
55+ const openGitHubNotificationsSpy = jest
56+ . spyOn ( links , 'openGitHubNotifications' )
57+ . mockImplementation ( ) ;
58+
59+ it ( 'opens primary account GitHub notifications webpage when pressing N while logged in' , async ( ) => {
60+ renderWithAppContext (
61+ < MemoryRouter >
62+ < GlobalShortcuts />
63+ </ MemoryRouter > ,
64+ {
65+ isLoggedIn : true ,
66+ } ,
67+ ) ;
68+
69+ await userEvent . keyboard ( 'n' ) ;
70+
71+ expect ( openGitHubNotificationsSpy ) . toHaveBeenCalledTimes ( 1 ) ;
72+ } ) ;
73+
74+ it ( 'does not open primary account GitHub notifications webpage when logged out' , async ( ) => {
75+ renderWithAppContext (
76+ < MemoryRouter >
77+ < GlobalShortcuts />
78+ </ MemoryRouter > ,
79+ {
80+ isLoggedIn : false ,
81+ } ,
82+ ) ;
83+
84+ await userEvent . keyboard ( 'n' ) ;
85+
86+ expect ( openGitHubNotificationsSpy ) . not . toHaveBeenCalled ( ) ;
87+ } ) ;
88+ } ) ;
89+
3990 describe ( 'focus mode' , ( ) => {
4091 it ( 'toggles focus when pressing W while logged in' , async ( ) => {
4192 renderWithAppContext (
@@ -119,6 +170,78 @@ describe('components/GlobalShortcuts.tsx', () => {
119170 } ) ;
120171 } ) ;
121172
173+ describe ( 'openGitHubIssues' , ( ) => {
174+ const openGitHubIssuesSpy = jest
175+ . spyOn ( links , 'openGitHubIssues' )
176+ . mockImplementation ( ) ;
177+
178+ it ( 'opens primary account GitHub issues webpage when pressing I while logged in' , async ( ) => {
179+ renderWithAppContext (
180+ < MemoryRouter >
181+ < GlobalShortcuts />
182+ </ MemoryRouter > ,
183+ {
184+ isLoggedIn : true ,
185+ } ,
186+ ) ;
187+
188+ await userEvent . keyboard ( 'i' ) ;
189+
190+ expect ( openGitHubIssuesSpy ) . toHaveBeenCalledTimes ( 1 ) ;
191+ } ) ;
192+
193+ it ( 'does not open primary account GitHub issues webpage when logged out' , async ( ) => {
194+ renderWithAppContext (
195+ < MemoryRouter >
196+ < GlobalShortcuts />
197+ </ MemoryRouter > ,
198+ {
199+ isLoggedIn : false ,
200+ } ,
201+ ) ;
202+
203+ await userEvent . keyboard ( 'n' ) ;
204+
205+ expect ( openGitHubIssuesSpy ) . not . toHaveBeenCalled ( ) ;
206+ } ) ;
207+ } ) ;
208+
209+ describe ( 'openGitHubPulls' , ( ) => {
210+ const openGitHubPullsSpy = jest
211+ . spyOn ( links , 'openGitHubPulls' )
212+ . mockImplementation ( ) ;
213+
214+ it ( 'opens primary account GitHub pull requests webpage when pressing N while logged in' , async ( ) => {
215+ renderWithAppContext (
216+ < MemoryRouter >
217+ < GlobalShortcuts />
218+ </ MemoryRouter > ,
219+ {
220+ isLoggedIn : true ,
221+ } ,
222+ ) ;
223+
224+ await userEvent . keyboard ( 'p' ) ;
225+
226+ expect ( openGitHubPullsSpy ) . toHaveBeenCalledTimes ( 1 ) ;
227+ } ) ;
228+
229+ it ( 'does not open primary account GitHub pull requests webpage when logged out' , async ( ) => {
230+ renderWithAppContext (
231+ < MemoryRouter >
232+ < GlobalShortcuts />
233+ </ MemoryRouter > ,
234+ {
235+ isLoggedIn : false ,
236+ } ,
237+ ) ;
238+
239+ await userEvent . keyboard ( 'n' ) ;
240+
241+ expect ( openGitHubPullsSpy ) . not . toHaveBeenCalled ( ) ;
242+ } ) ;
243+ } ) ;
244+
122245 describe ( 'refresh' , ( ) => {
123246 it ( 'refreshes notifications when pressing R key' , async ( ) => {
124247 renderWithAppContext (
0 commit comments