forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote-controller.test.js
85 lines (69 loc) · 2.65 KB
/
remote-controller.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
import React from 'react';
import {shallow} from 'enzyme';
import {shell} from 'electron';
import BranchSet from '../../lib/models/branch-set';
import Branch, {nullBranch} from '../../lib/models/branch';
import Remote from '../../lib/models/remote';
import RemoteSet from '../../lib/models/remote-set';
import {getEndpoint} from '../../lib/models/endpoint';
import RemoteController from '../../lib/controllers/remote-controller';
import * as reporterProxy from '../../lib/reporter-proxy';
describe('RemoteController', function() {
let atomEnv, remote, remoteSet, currentBranch, branchSet;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
remote = new Remote('origin', '[email protected]:atom/github');
remoteSet = new RemoteSet([remote]);
currentBranch = new Branch('master', nullBranch, nullBranch, true);
branchSet = new BranchSet();
branchSet.add(currentBranch);
});
afterEach(function() {
atomEnv.destroy();
});
function createApp(props = {}) {
return (
<RemoteController
repository={null}
endpoint={getEndpoint('github.com')}
token="1234"
workingDirectory={__dirname}
workspace={atomEnv.workspace}
remote={remote}
remotes={remoteSet}
branches={branchSet}
aheadCount={0}
pushInProgress={false}
onPushBranch={() => {}}
{...props}
/>
);
}
it('increments a counter when onCreatePr is called', async function() {
const wrapper = shallow(createApp());
sinon.stub(shell, 'openExternal').callsFake(() => {});
sinon.stub(reporterProxy, 'incrementCounter');
await wrapper.instance().onCreatePr();
assert.equal(reporterProxy.incrementCounter.callCount, 1);
assert.deepEqual(reporterProxy.incrementCounter.lastCall.args, ['create-pull-request']);
});
it('handles error when onCreatePr fails', async function() {
const wrapper = shallow(createApp());
sinon.stub(shell, 'openExternal').throws(new Error('oh noes'));
sinon.stub(reporterProxy, 'incrementCounter');
try {
await wrapper.instance().onCreatePr();
} catch (err) {
assert.equal(err.message, 'oh noes');
}
assert.equal(reporterProxy.incrementCounter.callCount, 0);
});
it('renders issueish searches', function() {
const wrapper = shallow(createApp());
const controller = wrapper.update().find('IssueishSearchesController');
assert.strictEqual(controller.prop('token'), '1234');
assert.strictEqual(controller.prop('endpoint').getHost(), 'github.com');
assert.strictEqual(controller.prop('remote'), remote);
assert.strictEqual(controller.prop('branches'), branchSet);
});
});