-
Notifications
You must be signed in to change notification settings - Fork 187
/
shortcuts.test.tsx
48 lines (34 loc) · 1.28 KB
/
shortcuts.test.tsx
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
48
import React from 'react';
import {shallow, mount} from 'enzyme';
import simulateCombo from '../../test-helpers/simulate-combo';
import getUID from '../global/get-uid';
import Shortcuts, {ShortcutsProps} from './shortcuts';
type ShortcutsAttrs = JSX.LibraryManagedAttributes<typeof Shortcuts, ShortcutsProps>
type FactoryProps = Omit<ShortcutsAttrs, 'map' | 'scope'>
describe('ShortcutsComponent', () => {
const factory = (props?: FactoryProps) => (
<Shortcuts
map={{enter: sandbox.spy()}}
scope={getUID('shortcuts-test-')}
{...props}
/>
);
const shallowShortcuts = (props?: FactoryProps) => shallow(factory(props));
const mountShortcuts = (props?: FactoryProps) => mount(factory(props));
it('should initialize', () => {
shallowShortcuts().should.exist;
});
it('should call shortcut handler', () => {
const wrapper = mountShortcuts();
simulateCombo('enter');
wrapper.prop('map').enter.should.be.called;
});
it('should enable shortcuts if disabled becomes "false"', () => {
const wrapper = mountShortcuts({disabled: true});
simulateCombo('enter');
wrapper.prop('map').enter.should.not.be.called;
wrapper.setProps({disabled: false});
simulateCombo('enter');
wrapper.prop('map').enter.should.be.called;
});
});