-
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 #166: Fix over-zealous modifier flag discrepency correction
- Loading branch information
Showing
4 changed files
with
67 additions
and
5 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
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
51 changes: 51 additions & 0 deletions
51
test/HotKeys/BindingToKeysWithSimulatedKeypressEvents.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,51 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import {mount} from 'enzyme'; | ||
import sinon from 'sinon'; | ||
|
||
import Key from '../support/Key'; | ||
import KeyEventManager from '../../src/lib/KeyEventManager'; | ||
import { HotKeys } from '../../src'; | ||
import FocusableElement from '../support/FocusableElement'; | ||
|
||
describe('Binding to keys with simulated keypress events:', function () { | ||
context('when HotKeys has actions for a the keydown and keyup event', () => { | ||
beforeEach(function () { | ||
this.keyMap = { | ||
'ACTION1': {sequence: 'command', action: 'keydown'}, | ||
'ACTION2': {sequence: 'command', action: 'keyup'}, | ||
}; | ||
|
||
this.action1Handler = sinon.spy(); | ||
this.action2Handler = sinon.spy(); | ||
|
||
this.handlers = { | ||
'ACTION1': this.action1Handler, | ||
'ACTION2': this.action2Handler, | ||
}; | ||
|
||
this.wrapper = mount( | ||
<HotKeys keyMap={this.keyMap} handlers={this.handlers}> | ||
<div className="childElement" /> | ||
</HotKeys> | ||
); | ||
|
||
this.keyEventManager = KeyEventManager.getInstance(); | ||
|
||
this.targetElement = new FocusableElement(this.wrapper, '.childElement'); | ||
this.targetElement.focus(); | ||
}); | ||
|
||
it('then simulates the cmd keypress event and the non-modifier key\'s keypress event (https://github.com/greena13/react-hotkeys/issues/166)', function () { | ||
this.targetElement.keyDown(Key.COMMAND, { metaKey: true }); | ||
|
||
expect(this.action1Handler).to.have.been.calledOnce; | ||
expect(this.action2Handler).to.not.have.been.called; | ||
|
||
this.targetElement.keyUp(Key.COMMAND, { metaKey: false }); | ||
|
||
expect(this.action1Handler).to.have.been.calledOnce; | ||
expect(this.action2Handler).to.have.been.calledOnce; | ||
}); | ||
}); | ||
}); |