diff --git a/platform/core/src/classes/HotkeysManager.test.js b/platform/core/src/classes/HotkeysManager.test.js index 1c038349e..0298128df 100644 --- a/platform/core/src/classes/HotkeysManager.test.js +++ b/platform/core/src/classes/HotkeysManager.test.js @@ -2,7 +2,7 @@ import CommandsManager from './CommandsManager.js'; import HotkeysManager from './HotkeysManager.js'; import hotkeys from './../utils/hotkeys'; import log from './../log.js'; -import objectHash from "object-hash"; +import objectHash from 'object-hash'; jest.mock('./CommandsManager.js'); jest.mock('./../utils/hotkeys'); @@ -10,6 +10,9 @@ jest.mock('./../log.js'); describe('HotkeysManager', () => { let hotkeysManager, commandsManager; + beforeAll(() => { + hotkeys.initialize(); + }); beforeEach(() => { commandsManager = new CommandsManager(); @@ -19,7 +22,6 @@ describe('HotkeysManager', () => { log.warn.mockClear(); jest.clearAllMocks(); }); - it('has expected properties', () => { const allProperties = Object.keys(hotkeysManager); const expectedProprties = [ @@ -122,11 +124,16 @@ describe('HotkeysManager', () => { const definition = { commandName: undefined, keys: '+' }; expect(() => { - hotkeysManager.registerHotkeys(definition) + hotkeysManager.registerHotkeys(definition); }).toThrow(); }); it('updates hotkeyDefinitions property with registered keys', () => { - const definition = { commandName: 'dance', commandOptions: {}, label: 'hello', keys: '+', }; + const definition = { + commandName: 'dance', + commandOptions: {}, + label: 'hello', + keys: '+', + }; hotkeysManager.registerHotkeys(definition); @@ -136,13 +143,15 @@ describe('HotkeysManager', () => { const commandHash = objectHash({ commandName: definition.commandName, - commandOptions: definition.commandOptions + commandOptions: definition.commandOptions, }); const hotkeyDefinitionForRegisteredCommand = hotkeysManager.hotkeyDefinitions[commandHash]; expect(numOfHotkeyDefinitions).toBe(1); - expect(Object.keys(hotkeysManager.hotkeyDefinitions)[0]).toEqual(commandHash); + expect(Object.keys(hotkeysManager.hotkeyDefinitions)[0]).toEqual( + commandHash + ); expect(hotkeyDefinitionForRegisteredCommand).toEqual(definition); }); it('calls hotkeys.bind for the group of keys', () => { diff --git a/platform/core/src/utils/hotkeys/index.js b/platform/core/src/utils/hotkeys/index.js index 9118e672f..e12068400 100644 --- a/platform/core/src/utils/hotkeys/index.js +++ b/platform/core/src/utils/hotkeys/index.js @@ -11,4 +11,21 @@ Mousetrap.initialize = () => { } }; +// These are only here so that Jest mocks them properly before .initialize() is called +Mousetrap.handleKey = () => + console.debug('Mousetrap recordPlugin not yet initialized'); +Mousetrap.startRecording = () => + console.debug('Mousetrap recordPlugin not yet initialized'); +Mousetrap.stopRecording = () => + console.debug('Mousetrap recordPlugin not yet initialized'); +Mousetrap.record = () => + console.debug('Mousetrap recordPlugin not yet initialized'); + +Mousetrap.stopCallback = () => + console.debug('Mousetrap pausePlugin not yet initialized'); +Mousetrap.pause = () => + console.debug('Mousetrap pausePlugin not yet initialized'); +Mousetrap.unpause = () => + console.debug('Mousetrap pausePlugin not yet initialized'); + export default Mousetrap;