Skip to content

Commit

Permalink
Merge pull request #23 from allroundexperts/fix-18480
Browse files Browse the repository at this point in the history
fix: add strict checking to getRegisteredCommandIndex function
  • Loading branch information
mountiny authored May 17, 2023
2 parents 8f008c1 + 31a8469 commit ce2f31e
Show file tree
Hide file tree
Showing 4 changed files with 1,448 additions and 13 deletions.
48 changes: 48 additions & 0 deletions __tests__/KeyCommand/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import _ from 'underscore';
// eslint-disable-next-line
import * as Keycommand from '../../src/KeyCommand/index.js';

const {
default: {
getConstants,
registerKeyCommands,
unregisterKeyCommands,
getRegisteredCommandIndex,
},
} = Keycommand;

const constants = getConstants();

const commands = [
{input: constants.keyInputEscape},
{input: constants.keyInputEnter},
{input: constants.keyInputEscape, modifierFlags: constants.keyModifierCommand},
{input: constants.keyInputEnter, modifierFlags: constants.keyModifierCommand},
{input: constants.keyInputDownArrow, modifierFlags: constants.keyModifierCommand},
];

describe('KeyCommand getRegisteredCommandIndex', () => {
beforeAll(() => {
registerKeyCommands(commands);
});

afterAll(() => {
unregisterKeyCommands(commands);
});

it('should return correct command given that an exact match exists', () => {
_.map(commands, (command, index) => {
expect(getRegisteredCommandIndex(command)).toBe(index);
});

_.map([...commands].reverse(), (command, index) => {
expect(getRegisteredCommandIndex(command)).toBe(commands.length - 1 - index);
});
});

it('should return -1 if command does not exist', () => {
expect(getRegisteredCommandIndex({
input: constants.keyInputDownArrow,
})).toBe(-1);
});
});
Loading

0 comments on commit ce2f31e

Please sign in to comment.