|
| 1 | +import _ from 'underscore'; |
| 2 | +// eslint-disable-next-line |
| 3 | +import * as Keycommand from '../../src/KeyCommand/index.js'; |
| 4 | + |
| 5 | +const { |
| 6 | + default: { |
| 7 | + getConstants, |
| 8 | + registerKeyCommands, |
| 9 | + unregisterKeyCommands, |
| 10 | + getRegisteredCommandIndex, |
| 11 | + }, |
| 12 | +} = Keycommand; |
| 13 | + |
| 14 | +const constants = getConstants(); |
| 15 | + |
| 16 | +const commands = [ |
| 17 | + {input: constants.keyInputEscape}, |
| 18 | + {input: constants.keyInputEnter}, |
| 19 | + {input: constants.keyInputEscape, modifierFlags: constants.keyModifierCommand}, |
| 20 | + {input: constants.keyInputEnter, modifierFlags: constants.keyModifierCommand}, |
| 21 | + {input: constants.keyInputDownArrow, modifierFlags: constants.keyModifierCommand}, |
| 22 | +]; |
| 23 | + |
| 24 | +describe('KeyCommand getRegisteredCommandIndex', () => { |
| 25 | + beforeAll(() => { |
| 26 | + registerKeyCommands(commands); |
| 27 | + }); |
| 28 | + |
| 29 | + afterAll(() => { |
| 30 | + unregisterKeyCommands(commands); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should return correct command given that an exact match exists', () => { |
| 34 | + _.map(commands, (command, index) => { |
| 35 | + expect(getRegisteredCommandIndex(command)).toBe(index); |
| 36 | + }); |
| 37 | + |
| 38 | + _.map([...commands].reverse(), (command, index) => { |
| 39 | + expect(getRegisteredCommandIndex(command)).toBe(commands.length - 1 - index); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should return -1 if command does not exist', () => { |
| 44 | + expect(getRegisteredCommandIndex({ |
| 45 | + input: constants.keyInputDownArrow, |
| 46 | + })).toBe(-1); |
| 47 | + }); |
| 48 | +}); |
0 commit comments