forked from greena13/react-hotkeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwithHotKeys.spec.js
47 lines (36 loc) · 1.46 KB
/
withHotKeys.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, {PureComponent} from 'react';
import {mount} from 'enzyme';
import {expect} from 'chai';
import withHotKeys from '../lib/withHotKeys';
const ACTION_KEY_MAP = {
fakeAction1: 'esc',
fakeAction2: 'down',
};
class ChildComponent extends PureComponent {
hotKeyHandlers = {
'fakeAction1': () => {},
'fakeAction2': () => {},
}
render() {
return (<div />);
}
}
describe('withHotKeys-wrapped Component', () => {
const WrappedComponent = withHotKeys(ACTION_KEY_MAP)(ChildComponent);
it('includes HotKeysWrapper/HotKeys/FocusTrap', () => {
const mountedRootComponent = mount(<WrappedComponent />);
expect(mountedRootComponent.find('HotKeysWrapper')).to.have.length(1);
expect(mountedRootComponent.find('HotKeys')).to.have.length(1);
expect(mountedRootComponent.find('FocusTrap')).to.have.length(1);
});
it('renders HotKeys component with keyMap and handlers as props and keyMap and handlers have the same keys', () => {
const mountedRootComponent = mount(<WrappedComponent />);
const hotKeysWrapper = mountedRootComponent.find('HotKeys');
expect(hotKeysWrapper).to.have.length(1);
expect(hotKeysWrapper.find({keyMap: ACTION_KEY_MAP})).to.have.length(1);
expect(hotKeysWrapper.find({handlers: {}})).to.have.length(1);
const keyMapKeys = Object.keys(hotKeysWrapper.props().keyMap);
const handlersKeys = Object.keys(hotKeysWrapper.props().handlers);
expect(handlersKeys).to.eql(keyMapKeys);
});
});