forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone-dialog.test.js
146 lines (120 loc) · 5.26 KB
/
clone-dialog.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
142
143
144
145
146
import React from 'react';
import {shallow} from 'enzyme';
import path from 'path';
import CloneDialog from '../../lib/views/clone-dialog';
import {dialogRequests} from '../../lib/controllers/dialogs-controller';
describe('CloneDialog', function() {
let atomEnv;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(overrides = {}) {
return (
<CloneDialog
config={atomEnv.config}
workspace={atomEnv.workspace}
commands={atomEnv.commands}
request={dialogRequests.clone()}
inProgress={false}
{...overrides}
/>
);
}
describe('entering a remote URL', function() {
it("updates the project path automatically if it hasn't been modified", function() {
sinon.stub(atomEnv.config, 'get').returns(path.join('/home/me/src'));
const wrapper = shallow(buildApp());
wrapper.find('.github-Clone-sourceURL').prop('buffer').setText('[email protected]:atom/github.git');
wrapper.update();
assert.strictEqual(
wrapper.find('.github-Clone-destinationPath').prop('buffer').getText(),
path.join('/home/me/src/github'),
);
wrapper.find('.github-Clone-sourceURL').prop('buffer')
.setText('https://github.com/smashwilson/slack-emojinator.git');
wrapper.update();
assert.strictEqual(
wrapper.find('.github-Clone-destinationPath').prop('buffer').getText(),
path.join('/home/me/src/slack-emojinator'),
);
});
it("doesn't update the project path if the source URL has no pathname", function() {
sinon.stub(atomEnv.config, 'get').returns(path.join('/home/me/src'));
const wrapper = shallow(buildApp());
wrapper.find('.github-Clone-sourceURL').prop('buffer').setText('https://github.com');
wrapper.update();
assert.strictEqual(
wrapper.find('.github-Clone-destinationPath').prop('buffer').getText(),
path.join('/home/me/src'),
);
});
it("doesn't update the project path if it has been modified", function() {
const wrapper = shallow(buildApp());
wrapper.find('.github-Clone-destinationPath').prop('buffer').setText(path.join('/somewhere/else'));
wrapper.find('.github-Clone-sourceURL').prop('buffer').setText('[email protected]:atom/github.git');
assert.strictEqual(
wrapper.find('.github-Clone-destinationPath').prop('buffer').getText(),
path.join('/somewhere/else'),
);
});
});
describe('clone button enablement', function() {
it('disables the clone button with no remote URL', function() {
const wrapper = shallow(buildApp());
wrapper.find('.github-Clone-destinationPath').prop('buffer').setText(path.join('/some/where'));
wrapper.find('.github-Clone-sourceURL').prop('buffer').setText('');
wrapper.update();
assert.isFalse(wrapper.find('DialogView').prop('acceptEnabled'));
});
it('disables the clone button with no project path', function() {
const wrapper = shallow(buildApp());
wrapper.find('.github-Clone-destinationPath').prop('buffer').setText('');
wrapper.find('.github-Clone-sourceURL').prop('buffer').setText('[email protected]:atom/github.git');
wrapper.update();
assert.isFalse(wrapper.find('DialogView').prop('acceptEnabled'));
});
it('enables the clone button when both text boxes are populated', function() {
const wrapper = shallow(buildApp());
wrapper.find('.github-Clone-destinationPath').prop('buffer').setText(path.join('/some/where'));
wrapper.find('.github-Clone-sourceURL').prop('buffer').setText('[email protected]:atom/github.git');
wrapper.update();
assert.isTrue(wrapper.find('DialogView').prop('acceptEnabled'));
});
});
it('calls the acceptance callback', function() {
const accept = sinon.spy();
const request = dialogRequests.clone();
request.onAccept(accept);
const wrapper = shallow(buildApp({request}));
wrapper.find('.github-Clone-destinationPath').prop('buffer').setText(path.join('/some/where'));
wrapper.find('.github-Clone-sourceURL').prop('buffer').setText('[email protected]:atom/github.git');
wrapper.find('DialogView').prop('accept')();
assert.isTrue(accept.calledWith('[email protected]:atom/github.git', path.join('/some/where')));
});
it('does nothing from the acceptance callback if either text field is empty', function() {
const accept = sinon.spy();
const request = dialogRequests.clone();
request.onAccept(accept);
const wrapper = shallow(buildApp({request}));
wrapper.find('DialogView').prop('accept')();
assert.isFalse(accept.called);
});
it('calls the cancellation callback', function() {
const cancel = sinon.spy();
const request = dialogRequests.clone();
request.onCancel(cancel);
const wrapper = shallow(buildApp({request}));
wrapper.find('DialogView').prop('cancel')();
assert.isTrue(cancel.called);
});
describe('in progress', function() {
it('disables the text editors and buttons', function() {
const wrapper = shallow(buildApp({inProgress: true}));
assert.isTrue(wrapper.find('.github-Clone-sourceURL').prop('readOnly'));
assert.isTrue(wrapper.find('.github-Clone-destinationPath').prop('readOnly'));
});
});
});