forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote-controller.test.js
More file actions
88 lines (70 loc) · 2.72 KB
/
remote-controller.test.js
File metadata and controls
88 lines (70 loc) · 2.72 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 {shell} from 'electron';
import BranchSet from '../../lib/models/branch-set';
import Branch, {nullBranch} from '../../lib/models/branch';
import Remote from '../../lib/models/remote';
import {getEndpoint} from '../../lib/models/endpoint';
import {nullOperationStateObserver} from '../../lib/models/operation-state-observer';
import RemoteController from '../../lib/controllers/remote-controller';
import * as reporterProxy from '../../lib/reporter-proxy';
describe('RemoteController', function() {
let atomEnv, remote, branchSet, currentBranch;
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
remote = new Remote('origin', 'git@github.com:atom/github');
currentBranch = new Branch('master', nullBranch, nullBranch, true);
branchSet = new BranchSet();
branchSet.add(currentBranch);
});
afterEach(function() {
atomEnv.destroy();
});
function createApp(props = {}) {
const noop = () => {};
return (
<RemoteController
endpoint={getEndpoint('github.com')}
token="1234"
repository={null}
remoteOperationObserver={nullOperationStateObserver}
workingDirectory={__dirname}
workspace={atomEnv.workspace}
remote={remote}
remotesByName={new Map()}
branches={branchSet}
aheadCount={0}
pushInProgress={false}
onPushBranch={noop}
{...props}
/>
);
}
it('increments a counter when onCreatePr is called', async function() {
const wrapper = shallow(createApp());
sinon.stub(shell, 'openExternal').callsArg(2);
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').callsArgWith(2, 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);
});
});