1 | import React from 'react';
|
2 | import {shallow, mount} from 'enzyme';
|
3 |
|
4 | import simulateCombo from '../../test-helpers/simulate-combo';
|
5 | import getUID from '../global/get-uid';
|
6 |
|
7 | import Shortcuts from './shortcuts';
|
8 |
|
9 | describe('ShortcutsComponent', () => {
|
10 | const factory = props => (
|
11 | <Shortcuts
|
12 | map={{enter: sandbox.spy()}}
|
13 | scope={getUID('shortcuts-test-')}
|
14 | {...props}
|
15 | />
|
16 | );
|
17 |
|
18 | const shallowShortcuts = props => shallow(factory(props));
|
19 | const mountShortcuts = props => mount(factory(props));
|
20 |
|
21 |
|
22 | it('should initialize', () => {
|
23 | shallowShortcuts().should.exist;
|
24 | });
|
25 |
|
26 |
|
27 | it('should call shortcut handler', () => {
|
28 | const wrapper = mountShortcuts();
|
29 | simulateCombo('enter');
|
30 |
|
31 | wrapper.prop('map').enter.should.be.called;
|
32 | });
|
33 |
|
34 | it('should enable shortcuts if disabled becomes "false"', () => {
|
35 | const wrapper = mountShortcuts({disabled: true});
|
36 |
|
37 | simulateCombo('enter');
|
38 | wrapper.prop('map').enter.should.not.be.called;
|
39 |
|
40 | wrapper.setProps({disabled: false});
|
41 |
|
42 | simulateCombo('enter');
|
43 | wrapper.prop('map').enter.should.be.called;
|
44 | });
|
45 | });
|