@@ -16,6 +16,38 @@ describe('Directive: Hotkeys', () => {
16
16
spectator . fixture . detectChanges ( ) ;
17
17
} ) ;
18
18
19
+ it ( 'should not trigger hotkey output if hotkeys are paused, should trigger again when resumed' , ( ) => {
20
+ spectator = createDirective ( `<div [hotkeys]="'a'"></div>` ) ;
21
+
22
+ const hotkeysService = spectator . inject ( HotkeysService ) ;
23
+ hotkeysService . pause ( ) ;
24
+ const spyFcn = createSpy ( 'subscribe' , ( e ) => { } ) ;
25
+ spectator . output ( 'hotkey' ) . subscribe ( spyFcn ) ;
26
+ spectator . fixture . detectChanges ( ) ;
27
+ spectator . dispatchKeyboardEvent ( spectator . element , 'keydown' , 'a' ) ;
28
+ expect ( spyFcn ) . not . toHaveBeenCalled ( ) ;
29
+
30
+ hotkeysService . resume ( ) ;
31
+ spectator . dispatchKeyboardEvent ( spectator . element , 'keydown' , 'a' ) ;
32
+ expect ( spyFcn ) . toHaveBeenCalled ( ) ;
33
+ } ) ;
34
+
35
+ it ( 'should not trigger global hotkey output if hotkeys are paused, should trigger again when resumed' , ( ) => {
36
+ spectator = createDirective ( `<div [hotkeys]="'a'" isGlobal></div>` ) ;
37
+
38
+ const hotkeysService = spectator . inject ( HotkeysService ) ;
39
+ hotkeysService . pause ( ) ;
40
+ const spyFcn = createSpy ( 'subscribe' , ( e ) => { } ) ;
41
+ spectator . output ( 'hotkey' ) . subscribe ( spyFcn ) ;
42
+ spectator . fixture . detectChanges ( ) ;
43
+ spectator . dispatchKeyboardEvent ( document . documentElement , 'keydown' , 'a' ) ;
44
+ expect ( spyFcn ) . not . toHaveBeenCalled ( ) ;
45
+
46
+ hotkeysService . resume ( ) ;
47
+ spectator . dispatchKeyboardEvent ( document . documentElement , 'keydown' , 'a' ) ;
48
+ expect ( spyFcn ) . toHaveBeenCalled ( ) ;
49
+ } ) ;
50
+
19
51
const shouldIgnoreOnInputTest = ( directiveExtras ?: string ) => {
20
52
const spyFcn = createSpy ( 'subscribe' , ( ...args ) => { } ) ;
21
53
spectator = createDirective ( `<div [hotkeys]="'a'" ${ directiveExtras ?? '' } ><input></div>` ) ;
@@ -169,6 +201,60 @@ describe('Directive: Sequence Hotkeys', () => {
169
201
return run ( ) ;
170
202
} ) ;
171
203
204
+ it ( 'should not trigger sequence hotkey if hotkeys are paused, should trigger again when resumed' , ( ) => {
205
+ const run = async ( ) => {
206
+ // * Need to space out time to prevent other test keystrokes from interfering with sequence
207
+ await sleep ( 250 ) ;
208
+ const spyFcn = createSpy ( 'subscribe' , ( ...args ) => { } ) ;
209
+ spectator = createDirective ( `<div [hotkeys]="'g>m'" [isSequence]="true"></div>` ) ;
210
+ const hotkeysService = spectator . inject ( HotkeysService ) ;
211
+
212
+ hotkeysService . pause ( ) ;
213
+ spectator . output ( 'hotkey' ) . subscribe ( spyFcn ) ;
214
+ spectator . dispatchKeyboardEvent ( spectator . element , 'keydown' , 'g' ) ;
215
+ spectator . dispatchKeyboardEvent ( spectator . element , 'keydown' , 'm' ) ;
216
+ await sleep ( 250 ) ;
217
+ spectator . fixture . detectChanges ( ) ;
218
+ expect ( spyFcn ) . not . toHaveBeenCalled ( ) ;
219
+
220
+ hotkeysService . resume ( ) ;
221
+ spectator . dispatchKeyboardEvent ( spectator . element , 'keydown' , 'g' ) ;
222
+ spectator . dispatchKeyboardEvent ( spectator . element , 'keydown' , 'm' ) ;
223
+ await sleep ( 250 ) ;
224
+ spectator . fixture . detectChanges ( ) ;
225
+ expect ( spyFcn ) . toHaveBeenCalled ( ) ;
226
+ } ;
227
+
228
+ return run ( ) ;
229
+ } ) ;
230
+
231
+ it ( 'should not trigger global sequence hotkey if hotkeys are paused, should trigger again when resumed' , ( ) => {
232
+ const run = async ( ) => {
233
+ // * Need to space out time to prevent other test keystrokes from interfering with sequence
234
+ await sleep ( 250 ) ;
235
+ const spyFcn = createSpy ( 'subscribe' , ( ...args ) => { } ) ;
236
+ spectator = createDirective ( `<div [hotkeys]="'g>m'" [isSequence]="true" isGlobal></div>` ) ;
237
+ const hotkeysService = spectator . inject ( HotkeysService ) ;
238
+
239
+ hotkeysService . pause ( ) ;
240
+ spectator . output ( 'hotkey' ) . subscribe ( spyFcn ) ;
241
+ spectator . dispatchKeyboardEvent ( document . documentElement , 'keydown' , 'g' ) ;
242
+ spectator . dispatchKeyboardEvent ( document . documentElement , 'keydown' , 'm' ) ;
243
+ await sleep ( 250 ) ;
244
+ spectator . fixture . detectChanges ( ) ;
245
+ expect ( spyFcn ) . not . toHaveBeenCalled ( ) ;
246
+
247
+ hotkeysService . resume ( ) ;
248
+ spectator . dispatchKeyboardEvent ( document . documentElement , 'keydown' , 'g' ) ;
249
+ spectator . dispatchKeyboardEvent ( document . documentElement , 'keydown' , 'm' ) ;
250
+ await sleep ( 250 ) ;
251
+ spectator . fixture . detectChanges ( ) ;
252
+ expect ( spyFcn ) . toHaveBeenCalled ( ) ;
253
+ } ;
254
+
255
+ return run ( ) ;
256
+ } ) ;
257
+
172
258
const shouldIgnoreOnInputTest = async ( directiveExtras ?: string ) => {
173
259
// * Need to space out time to prevent other test keystrokes from interfering with sequence
174
260
await sleep ( 250 ) ;
0 commit comments