-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚔ Fix #173: Ignore when a component enables itself twice without swit…
…ching focus tree
- Loading branch information
Showing
3 changed files
with
76 additions
and
4 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
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
50 changes: 50 additions & 0 deletions
50
test/lib/FocusOnlyKeyEventStrategy/IgnoringEnablingDuplicateComponentIds.spec.js
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,50 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
import KeyEventManager from '../../../src/lib/KeyEventManager'; | ||
|
||
describe('Ignoring enabling duplicate component ids:', function () { | ||
context('when the FocusOnlyKeyEventStrategy registers a component ID', () => { | ||
beforeEach(function () { | ||
this.keyEventManager = new KeyEventManager(); | ||
this.eventStrategy = this.keyEventManager._focusOnlyEventStrategy; | ||
|
||
this.handler = sinon.spy(); | ||
|
||
this.componentId = this.eventStrategy.registerKeyMap({}); | ||
}); | ||
|
||
context('and it has already registered that component ID', () => { | ||
beforeEach(function () { | ||
this.keyMap = {ACTION1: { sequence: 'a', action: 'keydown' } }; | ||
|
||
this.eventStrategy.enableHotKeys( | ||
this.componentId, | ||
this.keyMap, | ||
{ACTION1: this.handler}, | ||
{}, | ||
{} | ||
); | ||
|
||
expect(this.eventStrategy.componentList[0].componentId).to.eql(this.componentId); | ||
expect(this.eventStrategy.componentList.length).to.eql(1); | ||
}); | ||
|
||
it('then returns undefined and does not add the component again \ | ||
(https://github.com/greena13/react-hotkeys/issues/173)', function () { | ||
const result = this.eventStrategy.enableHotKeys( | ||
this.componentId, | ||
this.keyMap, | ||
{ACTION1: this.handler}, | ||
{}, | ||
{} | ||
); | ||
|
||
expect(this.eventStrategy.componentList[0].componentId).to.eql(this.componentId); | ||
expect(this.eventStrategy.componentList.length).to.eql(1); | ||
|
||
expect(result).to.be.undefined; | ||
}); | ||
}); | ||
}); | ||
}); |