forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog-view.test.js
141 lines (115 loc) · 4.58 KB
/
dialog-view.test.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import React from 'react';
import {shallow} from 'enzyme';
import DialogView from '../../lib/views/dialog-view';
import TabGroup from '../../lib/tab-group';
describe('DialogView', function() {
let atomEnv;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(overrides = {}) {
return (
<DialogView
workspace={atomEnv.workspace}
commands={atomEnv.commands}
tabGroup={new TabGroup()}
inProgress={false}
acceptEnabled={true}
accept={() => {}}
cancel={() => {}}
children={<div />}
{...overrides}
/>
);
}
it('includes common dialog elements', function() {
const wrapper = shallow(buildApp());
assert.isTrue(wrapper.exists('Panel[location="modal"]'));
assert.isTrue(wrapper.exists('.github-Dialog'));
assert.isTrue(wrapper.exists('Commands'));
assert.isTrue(wrapper.exists('main.github-DialogForm'));
assert.isTrue(wrapper.exists('footer.github-DialogFooter'));
assert.isTrue(wrapper.exists('.github-DialogInfo'));
assert.isTrue(wrapper.exists('.github-DialogButtons'));
assert.isTrue(wrapper.exists('.btn.github-Dialog-cancelButton'));
assert.isTrue(wrapper.exists('.btn.btn-primary'));
assert.isFalse(wrapper.exists('header.github-DialogPrompt'));
assert.isFalse(wrapper.exists('.loading-spinner-small'));
assert.isFalse(wrapper.exists('.error-messages'));
});
describe('customization', function() {
it('includes a prompt banner if the prompt prop is provided', function() {
const wrapper = shallow(buildApp({prompt: 'some text'}));
assert.strictEqual(wrapper.find('header.github-DialogPrompt').text(), 'some text');
});
it('inserts custom form contents', function() {
const wrapper = shallow(buildApp({
children: <div className="custom" />,
}));
assert.isTrue(wrapper.exists('main .custom'));
});
it('displays a spinner and custom message when in progress', function() {
const wrapper = shallow(buildApp({
progressMessage: 'crunching numbers',
inProgress: true,
}));
assert.isTrue(wrapper.exists('.loading-spinner-small'));
assert.strictEqual(wrapper.find('.github-DialogProgress-message').text(), 'crunching numbers');
});
it('omits the spinner when no progress message is provided', function() {
const wrapper = shallow(buildApp({
inProgress: true,
}));
assert.isFalse(wrapper.exists('.loading-spinner-small'));
assert.isFalse(wrapper.exists('.github-DialogProgress-message'));
});
it('uses a custom classes and label for the accept button', function() {
const wrapper = shallow(buildApp({
acceptClassName: 'icon icon-repo-clone',
acceptText: 'Engage',
}));
const button = wrapper.find('.btn-primary');
assert.isTrue(button.hasClass('icon'));
assert.isTrue(button.hasClass('icon-repo-clone'));
assert.strictEqual(button.prop('children'), 'Engage');
});
});
it('displays an error with a friendly explanation', function() {
const e = new Error('unfriendly');
e.userMessage = 'friendly';
const wrapper = shallow(buildApp({error: e}));
assert.strictEqual(wrapper.find('.error-messages li').text(), 'friendly');
});
it('falls back to presenting the regular error message', function() {
const e = new Error('other');
const wrapper = shallow(buildApp({error: e}));
assert.strictEqual(wrapper.find('.error-messages li').text(), 'other');
});
it('calls the accept callback on core:confirm event', function() {
const accept = sinon.spy();
const wrapper = shallow(buildApp({accept}));
wrapper.find('Command[command="core:confirm"]').prop('callback')();
assert.isTrue(accept.called);
});
it('calls the accept callback on an accept button click', function() {
const accept = sinon.spy();
const wrapper = shallow(buildApp({accept}));
wrapper.find('.btn-primary').prop('onClick')();
assert.isTrue(accept.called);
});
it('calls the cancel callback on a core:cancel event', function() {
const cancel = sinon.spy();
const wrapper = shallow(buildApp({cancel}));
wrapper.find('Command[command="core:cancel"]').prop('callback')();
assert.isTrue(cancel.called);
});
it('calls the cancel callback on a cancel button click', function() {
const cancel = sinon.spy();
const wrapper = shallow(buildApp({cancel}));
wrapper.find('.github-Dialog-cancelButton').prop('onClick')();
assert.isTrue(cancel.called);
});
});