forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrent-pull-request-container.test.js
More file actions
208 lines (165 loc) · 6.24 KB
/
current-pull-request-container.test.js
File metadata and controls
208 lines (165 loc) · 6.24 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import React from 'react';
import {mount} from 'enzyme';
import {ManualStateObserver} from '../helpers';
import {createPullRequestResult} from '../fixtures/factories/pull-request-result';
import {createRepositoryResult} from '../fixtures/factories/repository-result';
import Remote from '../../lib/models/remote';
import RemoteSet from '../../lib/models/remote-set';
import Branch, {nullBranch} from '../../lib/models/branch';
import BranchSet from '../../lib/models/branch-set';
import {expectRelayQuery} from '../../lib/relay-network-layer-manager';
import CurrentPullRequestContainer from '../../lib/containers/current-pull-request-container';
describe('CurrentPullRequestContainer', function() {
let observer;
beforeEach(function() {
observer = new ManualStateObserver();
});
function useEmptyResult() {
return expectRelayQuery({
name: 'currentPullRequestContainerQuery',
variables: {
headOwner: 'atom',
headName: 'github',
headRef: 'refs/heads/master',
first: 5,
},
}, {
repository: {
ref: {
associatedPullRequests: {
totalCount: 0,
nodes: [],
},
id: 'ref0',
},
id: 'repository0',
},
});
}
function useResults(...attrs) {
return expectRelayQuery({
name: 'currentPullRequestContainerQuery',
variables: {
headOwner: 'atom',
headName: 'github',
headRef: 'refs/heads/master',
first: 5,
},
}, {
repository: {
ref: {
associatedPullRequests: {
totalCount: attrs.length,
nodes: attrs.map(createPullRequestResult),
},
id: 'ref0',
},
id: 'repository0',
},
});
}
function buildApp(overrideProps = {}) {
const origin = new Remote('origin', 'git@github.com:atom/github.git');
const upstreamBranch = Branch.createRemoteTracking('refs/remotes/origin/master', 'origin', 'refs/heads/master');
const branch = new Branch('master', upstreamBranch, upstreamBranch, true);
const branchSet = new BranchSet();
branchSet.add(branch);
const remotes = new RemoteSet([origin]);
return (
<CurrentPullRequestContainer
repository={createRepositoryResult()}
token="1234"
endpoint={origin.getEndpoint()}
remoteOperationObserver={observer}
remote={origin}
remotes={remotes}
branches={branchSet}
aheadCount={0}
pushInProgress={false}
onOpenIssueish={() => {}}
onCreatePr={() => {}}
{...overrideProps}
/>
);
}
it('performs no query without an upstream remote', function() {
const branch = new Branch('local', nullBranch, nullBranch, true);
const branchSet = new BranchSet();
branchSet.add(branch);
const wrapper = mount(buildApp({branches: branchSet}));
assert.isFalse(wrapper.find('ReactRelayQueryRenderer').exists());
const list = wrapper.find('BareIssueishListController');
assert.isTrue(list.exists());
assert.isFalse(list.prop('isLoading'));
assert.strictEqual(list.prop('total'), 0);
assert.lengthOf(list.prop('results'), 0);
});
it('passes an empty result list and an isLoading prop to the controller while loading', async function() {
const {resolve, promise} = useEmptyResult();
const wrapper = mount(buildApp());
assert.isTrue(wrapper.find('BareIssueishListController').prop('isLoading'));
resolve();
await promise;
assert.isFalse(wrapper.update().find('BareIssueishListController').prop('isLoading'));
});
it('passes an empty result list and an error prop to the controller when errored', async function() {
const {reject, promise} = useEmptyResult();
const e = new Error('oh no');
e.rawStack = e.stack;
reject(e);
await promise.catch(() => null);
const wrapper = mount(buildApp());
await assert.async.isFalse(wrapper.update().find('BareIssueishListController').prop('isLoading'));
assert.strictEqual(wrapper.find('BareIssueishListController').prop('error'), e);
});
it('passes a configured pull request creation tile to the controller', async function() {
const {resolve, promise} = useEmptyResult();
resolve();
await promise;
const wrapper = mount(buildApp());
await assert.async.isFalse(wrapper.update().find('BareIssueishListController').prop('isLoading'));
assert.isTrue(wrapper.find('CreatePullRequestTile').exists());
});
it('passes results to the controller', async function() {
const {resolve, promise} = useResults({number: 10});
const wrapper = mount(buildApp());
resolve();
await promise;
const controller = wrapper.update().find('BareIssueishListController');
assert.strictEqual(controller.prop('total'), 1);
assert.deepEqual(controller.prop('results').map(result => result.number), [10]);
});
it('filters out pull requests opened on different repositories', async function() {
const repository = createRepositoryResult({id: 'upstream-repo'});
const {resolve, promise} = useResults(
{id: 'pr0', number: 11, repositoryID: 'upstream-repo'},
{id: 'pr1', number: 22, repositoryID: 'someones-fork'},
);
const wrapper = mount(buildApp({repository}));
resolve();
await promise;
wrapper.update();
const numbers = wrapper.find('IssueishListView').prop('issueishes').map(i => i.getNumber());
assert.deepEqual(numbers, [11]);
});
it('performs the query again when a remote operation completes', async function() {
const {resolve: resolve0, promise: promise0, disable: disable0} = useResults({number: 0});
const wrapper = mount(buildApp());
resolve0();
await promise0;
wrapper.update();
const controller = wrapper.find('BareIssueishListController');
assert.deepEqual(controller.prop('results').map(result => result.number), [0]);
disable0();
const {resolve: resolve1, promise: promise1} = useResults({number: 1});
resolve1();
await promise1;
wrapper.update();
assert.deepEqual(controller.prop('results').map(result => result.number), [0]);
observer.trigger();
await assert.async.deepEqual(
wrapper.update().find('BareIssueishListController').prop('results').map(result => result.number),
[1],
);
});
});