Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit a5e9e12

Browse files
committed
CreateDialogController tests
1 parent ed8812c commit a5e9e12

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

test/controllers/create-dialog-controller.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ describe('CreateDialogController', function() {
4949

5050
buffer.setText('home');
5151
assert.strictEqual(atomEnv.config.get('github.sourceRemoteName'), 'home');
52+
53+
sinon.spy(atomEnv.config, 'set');
54+
buffer.setText('home');
55+
assert.isFalse(atomEnv.config.set.called);
56+
57+
wrapper.unmount();
5258
});
5359

5460
it('synchronizes the source protocol from Atom configuration', async function() {
@@ -60,6 +66,16 @@ describe('CreateDialogController', function() {
6066

6167
await wrapper.find(CreateDialogView).prop('didChangeProtocol')('https');
6268
assert.strictEqual(atomEnv.config.get('github.remoteFetchProtocol'), 'https');
69+
70+
sinon.spy(atomEnv.config, 'set');
71+
await wrapper.find(CreateDialogView).prop('didChangeProtocol')('https');
72+
assert.isFalse(atomEnv.config.set.called);
73+
});
74+
75+
it('begins with an empty owner ID while loading', function() {
76+
const wrapper = shallow(buildApp({user: null, isLoading: true}));
77+
78+
assert.strictEqual(wrapper.find(CreateDialogView).prop('selectedOwnerID'), '');
6379
});
6480

6581
it('begins with the owner ID as the viewer ID', function() {
@@ -172,6 +188,12 @@ describe('CreateDialogController', function() {
172188

173189
assert.isFalse(wrapper.find(CreateDialogView).prop('acceptEnabled'));
174190
});
191+
192+
it('disables the accept button if user data has not loaded yet', function() {
193+
const wrapper = shallow(buildApp({user: null}));
194+
195+
assert.isFalse(wrapper.find(CreateDialogView).prop('acceptEnabled'));
196+
});
175197
});
176198

177199
describe('acceptance', function() {
@@ -187,6 +209,39 @@ describe('CreateDialogController', function() {
187209
assert.isFalse(accept.called);
188210
});
189211

212+
it('uses the user ID if the selected owner ID was never changed', async function() {
213+
const accept = sinon.spy();
214+
const request = dialogRequests.create();
215+
request.onAccept(accept);
216+
const wrapper = shallow(buildApp({request, user: null, isLoading: true}));
217+
218+
assert.strictEqual(wrapper.find(CreateDialogView).prop('selectedOwnerID'), '');
219+
220+
wrapper.setProps({
221+
user: userBuilder(userQuery).id('my-id').build(),
222+
isLoading: false,
223+
});
224+
225+
wrapper.find(CreateDialogView).prop('repoName').setText('repo-name');
226+
wrapper.find(CreateDialogView).prop('didChangeVisibility')('PRIVATE');
227+
wrapper.find(CreateDialogView).prop('localPath').setText(path.join('/local/path'));
228+
wrapper.find(CreateDialogView).prop('didChangeProtocol')('ssh');
229+
wrapper.find(CreateDialogView).prop('sourceRemoteName').setText('upstream');
230+
231+
assert.strictEqual(wrapper.find(CreateDialogView).prop('selectedOwnerID'), '');
232+
233+
await wrapper.find(CreateDialogView).prop('accept')();
234+
235+
assert.isTrue(accept.calledWith({
236+
ownerID: 'my-id',
237+
name: 'repo-name',
238+
visibility: 'PRIVATE',
239+
localPath: path.join('/local/path'),
240+
protocol: 'ssh',
241+
sourceRemoteName: 'upstream',
242+
}));
243+
});
244+
190245
it('resolves onAccept with the populated data', async function() {
191246
const accept = sinon.spy();
192247
const request = dialogRequests.create();

0 commit comments

Comments
 (0)