forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissueish-search-container.test.js
More file actions
226 lines (197 loc) · 6.91 KB
/
Copy pathissueish-search-container.test.js
File metadata and controls
226 lines (197 loc) · 6.91 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import React from 'react';
import {shallow, mount} from 'enzyme';
import {CHECK_SUITE_PAGE_SIZE, CHECK_RUN_PAGE_SIZE} from '../../lib/helpers';
import {expectRelayQuery} from '../../lib/relay-network-layer-manager';
import Search, {nullSearch} from '../../lib/models/search';
import {getEndpoint} from '../../lib/models/endpoint';
import IssueishSearchContainer from '../../lib/containers/issueish-search-container';
import {ManualStateObserver} from '../helpers';
import {relayResponseBuilder} from '../builder/graphql/query';
describe('IssueishSearchContainer', function() {
let observer;
beforeEach(function() {
observer = new ManualStateObserver();
});
function buildApp(overrideProps = {}) {
return (
<IssueishSearchContainer
token="1234"
endpoint={getEndpoint('github.com')}
search={new Search('default', 'type:pr')}
remoteOperationObserver={observer}
onOpenIssueish={() => {}}
onOpenSearch={() => {}}
{...overrideProps}
/>
);
}
it('performs no query for a null Search', function() {
const wrapper = shallow(buildApp({search: nullSearch}));
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('renders a query for the Search', async function() {
const {resolve, promise} = expectRelayQuery({
name: 'issueishSearchContainerQuery',
variables: {
query: 'type:pr author:me',
},
}, {
search: {issueCount: 0, nodes: []},
});
const search = new Search('pull requests', 'type:pr author:me');
const wrapper = shallow(buildApp({search}));
assert.strictEqual(wrapper.find('ReactRelayQueryRenderer').prop('variables').query, 'type:pr author:me');
resolve();
await promise;
});
it('passes an empty result list and an isLoading prop to the controller while loading', async function() {
const {resolve, promise} = expectRelayQuery({
name: 'issueishSearchContainerQuery',
variables: {
query: 'type:pr author:me',
first: 20,
checkSuiteCount: CHECK_SUITE_PAGE_SIZE,
checkSuiteCursor: null,
checkRunCount: CHECK_RUN_PAGE_SIZE,
checkRunCursor: null,
},
}, op => {
return relayResponseBuilder(op)
.build();
});
const search = new Search('pull requests', 'type:pr author:me');
const wrapper = mount(buildApp({search}));
const controller = wrapper.find('BareIssueishListController');
assert.isTrue(controller.prop('isLoading'));
resolve();
await promise;
});
it('passes an empty result list and an error prop to the controller when errored', async function() {
expectRelayQuery({
name: 'issueishSearchContainerQuery',
variables: {
query: 'type:pr',
first: 20,
checkSuiteCount: CHECK_SUITE_PAGE_SIZE,
checkSuiteCursor: null,
checkRunCount: CHECK_RUN_PAGE_SIZE,
checkRunCursor: null,
},
}, op => {
return relayResponseBuilder(op)
.addError('uh oh')
.build();
}).resolve();
const wrapper = mount(buildApp({}));
await assert.async.isTrue(
wrapper.update().find('BareIssueishListController').filterWhere(n => !n.prop('isLoading')).exists(),
);
const controller = wrapper.find('BareIssueishListController');
assert.deepEqual(controller.prop('error').errors, [{message: 'uh oh'}]);
assert.lengthOf(controller.prop('results'), 0);
});
it('passes results to the controller', async function() {
const {promise, resolve} = expectRelayQuery({
name: 'issueishSearchContainerQuery',
variables: {
query: 'type:pr author:me',
first: 20,
checkSuiteCount: CHECK_SUITE_PAGE_SIZE,
checkSuiteCursor: null,
checkRunCount: CHECK_RUN_PAGE_SIZE,
checkRunCursor: null,
},
}, op => {
return relayResponseBuilder(op)
.search(s => {
s.issueCount(2);
s.addNode(n => n.bePullRequest(pr => {
pr.id('pr0');
pr.number(1);
pr.commits(conn => conn.addNode());
}));
s.addNode(n => n.bePullRequest(pr => {
pr.id('pr1');
pr.number(2);
pr.commits(conn => conn.addNode());
}));
})
.build();
});
const search = new Search('pull requests', 'type:pr author:me');
const wrapper = mount(buildApp({search}));
resolve();
await promise;
const controller = wrapper.update().find('BareIssueishListController');
assert.isFalse(controller.prop('isLoading'));
assert.strictEqual(controller.prop('total'), 2);
assert.isTrue(controller.prop('results').some(node => node.number === 1));
assert.isTrue(controller.prop('results').some(node => node.number === 2));
});
it('performs the query again when a remote operation completes', async function() {
const {promise: promise0, resolve: resolve0, disable: disable0} = expectRelayQuery({
name: 'issueishSearchContainerQuery',
variables: {
query: 'type:pr author:me',
first: 20,
checkSuiteCount: CHECK_SUITE_PAGE_SIZE,
checkSuiteCursor: null,
checkRunCount: CHECK_RUN_PAGE_SIZE,
checkRunCursor: null,
},
}, op => {
return relayResponseBuilder(op)
.search(s => {
s.issueCount(1);
s.addNode(n => n.bePullRequest(pr => {
pr.number(1);
pr.commits(conn => conn.addNode());
}));
})
.build();
});
const search = new Search('pull requests', 'type:pr author:me');
const wrapper = mount(buildApp({search}));
resolve0();
await promise0;
assert.isTrue(
wrapper.update().find('BareIssueishListController').prop('results').some(node => node.number === 1),
);
disable0();
const {promise: promise1, resolve: resolve1} = expectRelayQuery({
name: 'issueishSearchContainerQuery',
variables: {
query: 'type:pr author:me',
first: 20,
checkSuiteCount: CHECK_SUITE_PAGE_SIZE,
checkSuiteCursor: null,
checkRunCount: CHECK_RUN_PAGE_SIZE,
checkRunCursor: null,
},
}, op => {
return relayResponseBuilder(op)
.search(s => {
s.issueCount(1);
s.addNode(n => n.bePullRequest(pr => {
pr.number(2);
pr.commits(conn => conn.addNode());
}));
})
.build();
});
resolve1();
await promise1;
assert.isTrue(
wrapper.update().find('BareIssueishListController').prop('results').some(node => node.number === 1),
);
observer.trigger();
await assert.async.isTrue(
wrapper.update().find('BareIssueishListController').prop('results').some(node => node.number === 2),
);
});
});