forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissueish-searches-controller.test.js
More file actions
143 lines (119 loc) · 4.92 KB
/
issueish-searches-controller.test.js
File metadata and controls
143 lines (119 loc) · 4.92 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
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
import React from 'react';
import {shallow} from 'enzyme';
import IssueishSearchesController from '../../lib/controllers/issueish-searches-controller';
import {queryBuilder} from '../builder/graphql/query';
import Remote from '../../lib/models/remote';
import RemoteSet from '../../lib/models/remote-set';
import Branch from '../../lib/models/branch';
import BranchSet from '../../lib/models/branch-set';
import Issueish from '../../lib/models/issueish';
import {getEndpoint} from '../../lib/models/endpoint';
import {nullOperationStateObserver} from '../../lib/models/operation-state-observer';
import * as reporterProxy from '../../lib/reporter-proxy';
import remoteContainerQuery from '../../lib/containers/__generated__/remoteContainerQuery.graphql';
describe('IssueishSearchesController', function() {
let atomEnv;
const origin = new Remote('origin', 'git@github.com:atom/github.git');
const upstreamMaster = Branch.createRemoteTracking('origin/master', 'origin', 'refs/heads/master');
const master = new Branch('master', upstreamMaster);
beforeEach(function() {
atomEnv = global.buildAtomEnvironment();
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(overloadProps = {}) {
const branches = new BranchSet();
branches.add(master);
return (
<IssueishSearchesController
token="1234"
endpoint={getEndpoint('github.com')}
repository={queryBuilder(remoteContainerQuery).build().repository}
remoteOperationObserver={nullOperationStateObserver}
workingDirectory={__dirname}
workspace={atomEnv.workspace}
remote={origin}
remotes={new RemoteSet([origin])}
branches={branches}
aheadCount={0}
pushInProgress={false}
onCreatePr={() => {}}
{...overloadProps}
/>
);
}
it('renders a CurrentPullRequestContainer', function() {
const branches = new BranchSet();
branches.add(master);
const p = {
token: '4321',
endpoint: getEndpoint('mygithub.com'),
repository: queryBuilder(remoteContainerQuery).build().repository,
remote: origin,
remotes: new RemoteSet([origin]),
branches,
aheadCount: 4,
pushInProgress: true,
};
const wrapper = shallow(buildApp(p));
const container = wrapper.find('CurrentPullRequestContainer');
assert.isTrue(container.exists());
for (const key in p) {
assert.strictEqual(container.prop(key), p[key], `expected prop ${key} to be passed`);
}
});
it('renders an IssueishSearchContainer for each Search', function() {
const wrapper = shallow(buildApp());
assert.isTrue(wrapper.state('searches').length > 0);
for (const search of wrapper.state('searches')) {
const list = wrapper.find('IssueishSearchContainer').filterWhere(w => w.prop('search') === search);
assert.isTrue(list.exists());
assert.strictEqual(list.prop('token'), '1234');
assert.strictEqual(list.prop('endpoint').getHost(), 'github.com');
}
});
it('passes a handler to open an issueish pane and reports an event', async function() {
sinon.spy(atomEnv.workspace, 'open');
const wrapper = shallow(buildApp());
const container = wrapper.find('IssueishSearchContainer').at(0);
const issueish = new Issueish({
number: 123,
url: 'https://github.com/atom/github/issue/123',
author: {login: 'smashwilson', avatarUrl: 'https://avatars0.githubusercontent.com/u/17565?s=40&v=4'},
createdAt: '2019-04-01T10:00:00',
repository: {id: '0'},
commits: {nodes: []},
});
sinon.stub(reporterProxy, 'addEvent');
await container.prop('onOpenIssueish')(issueish);
assert.isTrue(
atomEnv.workspace.open.calledWith(
`atom-github://issueish/github.com/atom/github/123?workdir=${encodeURIComponent(__dirname)}`,
{pending: true, searchAllPanes: true},
),
);
assert.isTrue(reporterProxy.addEvent.calledWith('open-issueish-in-pane', {package: 'github', from: 'issueish-list'}));
});
it('passes a handler to open reviews and reports an event', async function() {
sinon.spy(atomEnv.workspace, 'open');
const wrapper = shallow(buildApp());
const container = wrapper.find('IssueishSearchContainer').at(0);
const issueish = new Issueish({
number: 2084,
url: 'https://github.com/atom/github/pull/2084',
author: {login: 'kuychaco', avatarUrl: 'https://avatars3.githubusercontent.com/u/7910250?v=4'},
createdAt: '2019-04-01T10:00:00',
repository: {id: '0'},
commits: {nodes: []},
});
sinon.stub(reporterProxy, 'addEvent');
await container.prop('onOpenReviews')(issueish);
assert.isTrue(
atomEnv.workspace.open.calledWith(
`atom-github://reviews/github.com/atom/github/2084?workdir=${encodeURIComponent(__dirname)}`,
),
);
assert.isTrue(reporterProxy.addEvent.calledWith('open-reviews-tab', {package: 'github', from: 'IssueishSearchesController'}));
});
});