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