Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @license |
Ben Rohlfs | 94fcbbc | 2022-05-27 10:45:03 +0200 | [diff] [blame] | 3 | * Copyright 2021 Google LLC |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 5 | */ |
| 6 | import '../../test/common-test-setup-karma'; |
Ben Rohlfs | be0c0ba | 2021-10-17 19:36:43 +0200 | [diff] [blame] | 7 | import { |
Ben Rohlfs | be0c0ba | 2021-10-17 19:36:43 +0200 | [diff] [blame] | 8 | COMBO_TIMEOUT_MS, |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 9 | describeBinding, |
| 10 | ShortcutsService, |
Ben Rohlfs | be0c0ba | 2021-10-17 19:36:43 +0200 | [diff] [blame] | 11 | } from '../../services/shortcuts/shortcuts-service'; |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 12 | import {Shortcut, ShortcutSection} from './shortcuts-config'; |
Ben Rohlfs | 1aeb1d3 | 2022-06-30 23:02:59 +0200 | [diff] [blame^] | 13 | import {SinonFakeTimers, SinonSpy} from 'sinon'; |
| 14 | import {Binding, Key, Modifier} from '../../utils/dom-util'; |
Chris Poucet | efcdb20 | 2021-11-22 23:54:26 +0100 | [diff] [blame] | 15 | import {getAppContext} from '../app-context'; |
Ben Rohlfs | 1aeb1d3 | 2022-06-30 23:02:59 +0200 | [diff] [blame^] | 16 | import {pressKey} from '../../test/test-utils'; |
| 17 | |
| 18 | const KEY_A: Binding = {key: 'a'}; |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 19 | |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 20 | suite('shortcuts-service tests', () => { |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 21 | let service: ShortcutsService; |
| 22 | |
| 23 | setup(() => { |
Chris Poucet | efcdb20 | 2021-11-22 23:54:26 +0100 | [diff] [blame] | 24 | service = new ShortcutsService( |
| 25 | getAppContext().userModel, |
Chris Poucet | b243fa4 | 2022-05-24 14:23:19 +0200 | [diff] [blame] | 26 | getAppContext().flagsService, |
Chris Poucet | efcdb20 | 2021-11-22 23:54:26 +0100 | [diff] [blame] | 27 | getAppContext().reportingService |
| 28 | ); |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 29 | }); |
| 30 | |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 31 | test('getShortcut', () => { |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 32 | assert.equal(service.getShortcut(Shortcut.NEXT_FILE), ']'); |
| 33 | assert.equal(service.getShortcut(Shortcut.TOGGLE_LEFT_PANE), 'A'); |
| 34 | assert.equal( |
| 35 | service.getShortcut(Shortcut.SEND_REPLY), |
| 36 | 'Ctrl+Enter,Meta/Cmd+Enter' |
| 37 | ); |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 38 | }); |
| 39 | |
Ben Rohlfs | 1aeb1d3 | 2022-06-30 23:02:59 +0200 | [diff] [blame^] | 40 | suite('addShortcut()', () => { |
| 41 | let el: HTMLElement; |
| 42 | let listener: SinonSpy<[KeyboardEvent], void>; |
| 43 | |
| 44 | setup(() => { |
| 45 | el = document.createElement('div'); |
| 46 | listener = sinon.spy() as SinonSpy<[KeyboardEvent], void>; |
| 47 | }); |
| 48 | |
| 49 | test('standard call', () => { |
| 50 | service.addShortcut(el, KEY_A, listener); |
| 51 | pressKey(el, KEY_A.key); |
| 52 | assert.isTrue(listener.calledOnce); |
| 53 | }); |
| 54 | |
| 55 | test('doNotPrevent option default false', () => { |
| 56 | service.addShortcut(el, KEY_A, listener); |
| 57 | pressKey(el, KEY_A.key); |
| 58 | assert.isTrue(listener.calledOnce); |
| 59 | assert.isTrue(listener.lastCall.firstArg?.defaultPrevented); |
| 60 | }); |
| 61 | |
| 62 | test('doNotPrevent option force false', () => { |
| 63 | service.addShortcut(el, KEY_A, listener, {doNotPrevent: false}); |
| 64 | pressKey(el, KEY_A.key); |
| 65 | assert.isTrue(listener.calledOnce); |
| 66 | assert.isTrue(listener.lastCall.firstArg?.defaultPrevented); |
| 67 | }); |
| 68 | |
| 69 | test('doNotPrevent option force true', () => { |
| 70 | service.addShortcut(el, KEY_A, listener, {doNotPrevent: true}); |
| 71 | pressKey(el, KEY_A.key); |
| 72 | assert.isTrue(listener.calledOnce); |
| 73 | assert.isFalse(listener.lastCall.firstArg?.defaultPrevented); |
| 74 | }); |
| 75 | |
| 76 | test('shouldSuppress option default true', () => { |
| 77 | service.shortcutsDisabled = true; |
| 78 | service.addShortcut(el, KEY_A, listener); |
| 79 | pressKey(el, KEY_A.key); |
| 80 | assert.isTrue(listener.notCalled); |
| 81 | }); |
| 82 | |
| 83 | test('shouldSuppress option force true', () => { |
| 84 | service.shortcutsDisabled = true; |
| 85 | service.addShortcut(el, KEY_A, listener, {shouldSuppress: true}); |
| 86 | pressKey(el, KEY_A.key); |
| 87 | assert.isTrue(listener.notCalled); |
| 88 | }); |
| 89 | |
| 90 | test('shouldSuppress option force false', () => { |
| 91 | service.shortcutsDisabled = true; |
| 92 | service.addShortcut(el, KEY_A, listener, {shouldSuppress: false}); |
| 93 | pressKey(el, KEY_A.key); |
| 94 | assert.isTrue(listener.calledOnce); |
| 95 | }); |
| 96 | }); |
| 97 | |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 98 | suite('binding descriptions', () => { |
| 99 | function mapToObject<K, V>(m: Map<K, V>) { |
| 100 | const o: any = {}; |
| 101 | m.forEach((v: V, k: K) => (o[k] = v)); |
| 102 | return o; |
| 103 | } |
| 104 | |
| 105 | test('single combo description', () => { |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 106 | assert.deepEqual(describeBinding({key: 'a'}), ['a']); |
| 107 | assert.deepEqual( |
| 108 | describeBinding({key: 'a', modifiers: [Modifier.CTRL_KEY]}), |
| 109 | ['Ctrl', 'a'] |
| 110 | ); |
| 111 | assert.deepEqual( |
| 112 | describeBinding({ |
| 113 | key: Key.UP, |
| 114 | modifiers: [Modifier.CTRL_KEY, Modifier.SHIFT_KEY], |
| 115 | }), |
| 116 | ['Shift', 'Ctrl', '↑'] |
| 117 | ); |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 118 | }); |
| 119 | |
| 120 | test('combo set description', () => { |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 121 | assert.deepEqual( |
| 122 | service.describeBindings(Shortcut.GO_TO_OPENED_CHANGES), |
| 123 | [['g', 'o']] |
| 124 | ); |
| 125 | assert.deepEqual(service.describeBindings(Shortcut.SAVE_COMMENT), [ |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 126 | ['Ctrl', 'Enter'], |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 127 | ['Meta/Cmd', 'Enter'], |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 128 | ['Ctrl', 's'], |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 129 | ['Meta/Cmd', 's'], |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 130 | ]); |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 131 | assert.deepEqual(service.describeBindings(Shortcut.PREV_FILE), [['[']]); |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 132 | }); |
| 133 | |
| 134 | test('combo set description width', () => { |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 135 | assert.strictEqual(service.comboSetDisplayWidth([['u']]), 1); |
| 136 | assert.strictEqual(service.comboSetDisplayWidth([['g', 'o']]), 2); |
| 137 | assert.strictEqual(service.comboSetDisplayWidth([['Shift', 'r']]), 6); |
| 138 | assert.strictEqual(service.comboSetDisplayWidth([['x'], ['y']]), 4); |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 139 | assert.strictEqual( |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 140 | service.comboSetDisplayWidth([['x'], ['y'], ['Shift', 'z']]), |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 141 | 12 |
| 142 | ); |
| 143 | }); |
| 144 | |
| 145 | test('distribute shortcut help', () => { |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 146 | assert.deepEqual(service.distributeBindingDesc([['o']]), [[['o']]]); |
| 147 | assert.deepEqual(service.distributeBindingDesc([['g', 'o']]), [ |
| 148 | [['g', 'o']], |
| 149 | ]); |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 150 | assert.deepEqual( |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 151 | service.distributeBindingDesc([['ctrl', 'shift', 'meta', 'enter']]), |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 152 | [[['ctrl', 'shift', 'meta', 'enter']]] |
| 153 | ); |
| 154 | assert.deepEqual( |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 155 | service.distributeBindingDesc([ |
| 156 | ['ctrl', 'shift', 'meta', 'enter'], |
| 157 | ['o'], |
| 158 | ]), |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 159 | [[['ctrl', 'shift', 'meta', 'enter']], [['o']]] |
| 160 | ); |
| 161 | assert.deepEqual( |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 162 | service.distributeBindingDesc([ |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 163 | ['ctrl', 'enter'], |
| 164 | ['meta', 'enter'], |
| 165 | ['ctrl', 's'], |
| 166 | ['meta', 's'], |
| 167 | ]), |
| 168 | [ |
| 169 | [ |
| 170 | ['ctrl', 'enter'], |
| 171 | ['meta', 'enter'], |
| 172 | ], |
| 173 | [ |
| 174 | ['ctrl', 's'], |
| 175 | ['meta', 's'], |
| 176 | ], |
| 177 | ] |
| 178 | ); |
| 179 | }); |
| 180 | |
| 181 | test('active shortcuts by section', () => { |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 182 | assert.deepEqual(mapToObject(service.activeShortcutsBySection()), {}); |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 183 | |
Chris Poucet | 35764c3 | 2022-06-21 09:48:10 +0200 | [diff] [blame] | 184 | service.addShortcutListener(Shortcut.NEXT_FILE, _ => {}); |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 185 | assert.deepEqual(mapToObject(service.activeShortcutsBySection()), { |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 186 | [ShortcutSection.NAVIGATION]: [ |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 187 | { |
| 188 | shortcut: Shortcut.NEXT_FILE, |
| 189 | text: 'Go to next file', |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 190 | bindings: [{key: ']'}], |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 191 | }, |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 192 | ], |
| 193 | }); |
Chris Poucet | 35764c3 | 2022-06-21 09:48:10 +0200 | [diff] [blame] | 194 | service.addShortcutListener(Shortcut.NEXT_LINE, _ => {}); |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 195 | assert.deepEqual(mapToObject(service.activeShortcutsBySection()), { |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 196 | [ShortcutSection.DIFFS]: [ |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 197 | { |
| 198 | shortcut: Shortcut.NEXT_LINE, |
| 199 | text: 'Go to next line', |
Ben Rohlfs | 5f5cb5e | 2021-11-08 12:10:25 +0100 | [diff] [blame] | 200 | bindings: [ |
| 201 | {allowRepeat: true, key: 'j'}, |
| 202 | {allowRepeat: true, key: 'ArrowDown'}, |
| 203 | ], |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 204 | }, |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 205 | ], |
| 206 | [ShortcutSection.NAVIGATION]: [ |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 207 | { |
| 208 | shortcut: Shortcut.NEXT_FILE, |
| 209 | text: 'Go to next file', |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 210 | bindings: [{key: ']'}], |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 211 | }, |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 212 | ], |
| 213 | }); |
| 214 | |
Chris Poucet | 35764c3 | 2022-06-21 09:48:10 +0200 | [diff] [blame] | 215 | service.addShortcutListener(Shortcut.SEARCH, _ => {}); |
| 216 | service.addShortcutListener(Shortcut.GO_TO_OPENED_CHANGES, _ => {}); |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 217 | assert.deepEqual(mapToObject(service.activeShortcutsBySection()), { |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 218 | [ShortcutSection.DIFFS]: [ |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 219 | { |
| 220 | shortcut: Shortcut.NEXT_LINE, |
| 221 | text: 'Go to next line', |
Ben Rohlfs | 5f5cb5e | 2021-11-08 12:10:25 +0100 | [diff] [blame] | 222 | bindings: [ |
| 223 | {allowRepeat: true, key: 'j'}, |
| 224 | {allowRepeat: true, key: 'ArrowDown'}, |
| 225 | ], |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 226 | }, |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 227 | ], |
| 228 | [ShortcutSection.EVERYWHERE]: [ |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 229 | { |
| 230 | shortcut: Shortcut.SEARCH, |
| 231 | text: 'Search', |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 232 | bindings: [{key: '/'}], |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 233 | }, |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 234 | { |
| 235 | shortcut: Shortcut.GO_TO_OPENED_CHANGES, |
| 236 | text: 'Go to Opened Changes', |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 237 | bindings: [{key: 'o', combo: 'g'}], |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 238 | }, |
| 239 | ], |
| 240 | [ShortcutSection.NAVIGATION]: [ |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 241 | { |
| 242 | shortcut: Shortcut.NEXT_FILE, |
| 243 | text: 'Go to next file', |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 244 | bindings: [{key: ']'}], |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 245 | }, |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 246 | ], |
| 247 | }); |
| 248 | }); |
| 249 | |
| 250 | test('directory view', () => { |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 251 | assert.deepEqual(mapToObject(service.directoryView()), {}); |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 252 | |
Chris Poucet | 35764c3 | 2022-06-21 09:48:10 +0200 | [diff] [blame] | 253 | service.addShortcutListener(Shortcut.GO_TO_OPENED_CHANGES, _ => {}); |
| 254 | service.addShortcutListener(Shortcut.NEXT_FILE, _ => {}); |
| 255 | service.addShortcutListener(Shortcut.NEXT_LINE, _ => {}); |
| 256 | service.addShortcutListener(Shortcut.SAVE_COMMENT, _ => {}); |
| 257 | service.addShortcutListener(Shortcut.SEARCH, _ => {}); |
Ben Rohlfs | 42333cb | 2021-10-07 07:54:10 +0200 | [diff] [blame] | 258 | assert.deepEqual(mapToObject(service.directoryView()), { |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 259 | [ShortcutSection.DIFFS]: [ |
Ben Rohlfs | fea8240 | 2021-10-06 17:50:47 +0200 | [diff] [blame] | 260 | {binding: [['j'], ['↓']], text: 'Go to next line'}, |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 261 | { |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 262 | binding: [['Ctrl', 'Enter']], |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 263 | text: 'Save comment', |
| 264 | }, |
| 265 | { |
| 266 | binding: [ |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 267 | ['Meta/Cmd', 'Enter'], |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 268 | ['Ctrl', 's'], |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 269 | ], |
| 270 | text: 'Save comment', |
| 271 | }, |
Ben Rohlfs | 410f522 | 2021-10-19 23:44:02 +0200 | [diff] [blame] | 272 | { |
| 273 | binding: [['Meta/Cmd', 's']], |
| 274 | text: 'Save comment', |
| 275 | }, |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 276 | ], |
| 277 | [ShortcutSection.EVERYWHERE]: [ |
| 278 | {binding: [['/']], text: 'Search'}, |
| 279 | {binding: [['g', 'o']], text: 'Go to Opened Changes'}, |
| 280 | ], |
| 281 | [ShortcutSection.NAVIGATION]: [ |
| 282 | {binding: [[']']], text: 'Go to next file'}, |
| 283 | ], |
| 284 | }); |
| 285 | }); |
| 286 | }); |
Ben Rohlfs | be0c0ba | 2021-10-17 19:36:43 +0200 | [diff] [blame] | 287 | |
| 288 | suite('combo keys', () => { |
| 289 | let clock: SinonFakeTimers; |
| 290 | setup(() => { |
| 291 | clock = sinon.useFakeTimers(); |
| 292 | clock.tick(1000); |
| 293 | }); |
| 294 | |
| 295 | teardown(() => { |
| 296 | clock.restore(); |
| 297 | }); |
| 298 | |
| 299 | test('not in combo key mode initially', () => { |
| 300 | assert.isFalse(service.isInComboKeyMode()); |
| 301 | }); |
| 302 | |
| 303 | test('pressing f does not switch into combo key mode', () => { |
| 304 | const event = new KeyboardEvent('keydown', {key: 'f'}); |
| 305 | document.dispatchEvent(event); |
| 306 | assert.isFalse(service.isInComboKeyMode()); |
| 307 | }); |
| 308 | |
| 309 | test('pressing g switches into combo key mode', () => { |
| 310 | const event = new KeyboardEvent('keydown', {key: 'g'}); |
| 311 | document.dispatchEvent(event); |
| 312 | assert.isTrue(service.isInComboKeyMode()); |
| 313 | }); |
| 314 | |
| 315 | test('pressing v switches into combo key mode', () => { |
| 316 | const event = new KeyboardEvent('keydown', {key: 'v'}); |
| 317 | document.dispatchEvent(event); |
| 318 | assert.isTrue(service.isInComboKeyMode()); |
| 319 | }); |
| 320 | |
| 321 | test('combo key mode timeout', () => { |
| 322 | const event = new KeyboardEvent('keydown', {key: 'g'}); |
| 323 | document.dispatchEvent(event); |
| 324 | assert.isTrue(service.isInComboKeyMode()); |
| 325 | clock.tick(COMBO_TIMEOUT_MS / 2); |
| 326 | assert.isTrue(service.isInComboKeyMode()); |
| 327 | clock.tick(COMBO_TIMEOUT_MS); |
| 328 | assert.isFalse(service.isInComboKeyMode()); |
| 329 | }); |
| 330 | }); |
Ben Rohlfs | 966586e | 2021-10-06 16:15:24 +0200 | [diff] [blame] | 331 | }); |