Repository navigation
Expand file tree
/
Copy pathkeystroke.test.js
More file actions
88 lines (67 loc) · 2.94 KB
/
Copy pathkeystroke.test.js
File metadata and controls
88 lines (67 loc) · 2.94 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react';
import {shallow} from 'enzyme';
import RefHolder from '../../lib/models/ref-holder';
import Keystroke from '../../lib/atom/keystroke';
describe('Keystroke', function() {
let atomEnv, keymaps, root, child;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
keymaps = atomEnv.keymaps;
root = document.createElement('div');
root.className = 'github-KeystrokeTest';
child = document.createElement('div');
child.className = 'github-KeystrokeTest-child';
root.appendChild(child);
atomEnv.commands.add(root, 'keystroke-test:root', () => {});
atomEnv.commands.add(child, 'keystroke-test:child', () => {});
keymaps.add(__filename, {
'.github-KeystrokeTest': {
'ctrl-x': 'keystroke-test:root',
},
'.github-KeystrokeTest-child': {
'alt-x': 'keystroke-test:root',
'ctrl-y': 'keystroke-test:child',
},
});
});
afterEach(function() {
atomEnv.destroy();
});
it('renders nothing for an unmapped command', function() {
const wrapper = shallow(
<Keystroke keymaps={keymaps} command="keystroke-test:unmapped" />,
);
assert.isFalse(wrapper.find('span.keystroke').exists());
});
it('renders nothing for a command that does not apply to the current target', function() {
const wrapper = shallow(
<Keystroke keymaps={keymaps} command="keystroke-test:child" refTarget={RefHolder.on(root)} />,
);
assert.isFalse(wrapper.find('span.keystroke').exists());
});
it('renders a registered keystroke', function() {
const wrapper = shallow(
<Keystroke keymaps={keymaps} command="keystroke-test:root" refTarget={RefHolder.on(root)} />,
);
assert.strictEqual(wrapper.find('span.keystroke').text(), process.platform === 'darwin' ? '\u2303X' : 'Ctrl+X');
// Exercise some other edge cases in the component lifecycle that are not particularly interesting
wrapper.setProps({});
wrapper.unmount();
});
it('uses the target to disambiguate keystroke bindings', function() {
const wrapper = shallow(
<Keystroke keymaps={keymaps} command="keystroke-test:root" refTarget={RefHolder.on(root)} />,
);
assert.strictEqual(wrapper.find('span.keystroke').text(), process.platform === 'darwin' ? '\u2303X' : 'Ctrl+X');
wrapper.setProps({refTarget: RefHolder.on(child)});
assert.strictEqual(wrapper.find('span.keystroke').text(), process.platform === 'darwin' ? '\u2325X' : 'Alt+X');
});
it('re-renders if the command prop changes', function() {
const wrapper = shallow(
<Keystroke keymaps={keymaps} command="keystroke-test:root" refTarget={RefHolder.on(child)} />,
);
assert.strictEqual(wrapper.find('span.keystroke').text(), process.platform === 'darwin' ? '\u2325X' : 'Alt+X');
wrapper.setProps({command: 'keystroke-test:child'});
assert.strictEqual(wrapper.find('span.keystroke').text(), process.platform === 'darwin' ? '\u2303Y' : 'Ctrl+Y');
});
});