-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4833e57
commit 31a8469
Showing
4 changed files
with
1,429 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Oops, something went wrong.