This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy pathreviews-controller.test.js
More file actions
830 lines (678 loc) · 31.2 KB
/
reviews-controller.test.js
File metadata and controls
830 lines (678 loc) · 31.2 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
import React from 'react';
import {shallow} from 'enzyme';
import path from 'path';
import {BareReviewsController} from '../../lib/controllers/reviews-controller';
import PullRequestCheckoutController from '../../lib/controllers/pr-checkout-controller';
import ReviewsView from '../../lib/views/reviews-view';
import IssueishDetailItem from '../../lib/items/issueish-detail-item';
import BranchSet from '../../lib/models/branch-set';
import RemoteSet from '../../lib/models/remote-set';
import EnableableOperation from '../../lib/models/enableable-operation';
import WorkdirContextPool from '../../lib/models/workdir-context-pool';
import * as reporterProxy from '../../lib/reporter-proxy';
import {getEndpoint} from '../../lib/models/endpoint';
import {cloneRepository, buildRepository, registerGitHubOpener} from '../helpers';
import {multiFilePatchBuilder} from '../builder/patch';
import {userBuilder} from '../builder/graphql/user';
import {pullRequestBuilder} from '../builder/graphql/pr';
import RelayNetworkLayerManager, {expectRelayQuery} from '../../lib/relay-network-layer-manager';
import {relayResponseBuilder} from '../builder/graphql/query';
import viewerQuery from '../../lib/controllers/__generated__/reviewsController_viewer.graphql';
import pullRequestQuery from '../../lib/controllers/__generated__/reviewsController_pullRequest.graphql';
import addPrReviewMutation from '../../lib/mutations/__generated__/addPrReviewMutation.graphql';
import addPrReviewCommentMutation from '../../lib/mutations/__generated__/addPrReviewCommentMutation.graphql';
import deletePrReviewMutation from '../../lib/mutations/__generated__/deletePrReviewMutation.graphql';
import submitPrReviewMutation from '../../lib/mutations/__generated__/submitPrReviewMutation.graphql';
import resolveThreadMutation from '../../lib/mutations/__generated__/resolveReviewThreadMutation.graphql';
import unresolveThreadMutation from '../../lib/mutations/__generated__/unresolveReviewThreadMutation.graphql';
import updateReviewCommentMutation from '../../lib/mutations/__generated__/updatePrReviewCommentMutation.graphql';
import updatePrReviewMutation from '../../lib/mutations/__generated__/updatePrReviewSummaryMutation.graphql';
describe('ReviewsController', function() {
let atomEnv, relayEnv, localRepository, noop, clock;
beforeEach(async function() {
atomEnv = global.buildAtomEnvironment();
registerGitHubOpener(atomEnv);
localRepository = await buildRepository(await cloneRepository());
noop = new EnableableOperation(() => {});
relayEnv = RelayNetworkLayerManager.getEnvironmentForHost(getEndpoint('github.com'), '1234');
});
afterEach(function() {
atomEnv.destroy();
if (clock) {
clock.restore();
}
});
function buildApp(override = {}) {
const props = {
relay: {environment: relayEnv},
viewer: userBuilder(viewerQuery).build(),
repository: {},
pullRequest: pullRequestBuilder(pullRequestQuery).build(),
workdirContextPool: new WorkdirContextPool(),
localRepository,
isAbsent: false,
isLoading: false,
isPresent: true,
isMerging: true,
isRebasing: true,
branches: new BranchSet(),
remotes: new RemoteSet(),
multiFilePatch: multiFilePatchBuilder().build(),
endpoint: getEndpoint('github.com'),
owner: 'atom',
repo: 'github',
number: 1995,
workdir: localRepository.getWorkingDirectoryPath(),
workspace: atomEnv.workspace,
config: atomEnv.config,
commands: atomEnv.commands,
tooltips: atomEnv.tooltips,
confirm: () => {},
reportRelayError: () => {},
...override,
};
return <BareReviewsController {...props} />;
}
it('renders a ReviewsView inside a PullRequestCheckoutController', function() {
const extra = Symbol('extra');
const wrapper = shallow(buildApp({extra}));
const opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.strictEqual(opWrapper.find(ReviewsView).prop('extra'), extra);
});
it('scrolls to and highlight a specific thread on mount', function() {
clock = sinon.useFakeTimers();
const wrapper = shallow(buildApp({initThreadID: 'thread0'}));
let opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.include(opWrapper.find(ReviewsView).prop('threadIDsOpen'), 'thread0');
assert.include(opWrapper.find(ReviewsView).prop('highlightedThreadIDs'), 'thread0');
assert.strictEqual(opWrapper.find(ReviewsView).prop('scrollToThreadID'), 'thread0');
clock.tick(2000);
opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.notInclude(opWrapper.find(ReviewsView).prop('highlightedThreadIDs'), 'thread0');
assert.isNull(opWrapper.find(ReviewsView).prop('scrollToThreadID'));
});
it('scrolls to and highlight a specific thread on update', function() {
clock = sinon.useFakeTimers();
const wrapper = shallow(buildApp());
let opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.deepEqual(opWrapper.find(ReviewsView).prop('threadIDsOpen'), new Set([]));
wrapper.setProps({initThreadID: 'hang-by-a-thread'});
opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.include(opWrapper.find(ReviewsView).prop('threadIDsOpen'), 'hang-by-a-thread');
assert.include(opWrapper.find(ReviewsView).prop('highlightedThreadIDs'), 'hang-by-a-thread');
assert.isTrue(opWrapper.find(ReviewsView).prop('commentSectionOpen'));
assert.strictEqual(opWrapper.find(ReviewsView).prop('scrollToThreadID'), 'hang-by-a-thread');
clock.tick(2000);
opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.notInclude(opWrapper.find(ReviewsView).prop('highlightedThreadIDs'), 'hang-by-a-thread');
assert.isNull(opWrapper.find(ReviewsView).prop('scrollToThreadID'));
});
it('does not unset a different scrollToThreadID if two highlight actions collide', function() {
clock = sinon.useFakeTimers();
const wrapper = shallow(buildApp());
let opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.deepEqual(opWrapper.find(ReviewsView).prop('threadIDsOpen'), new Set([]));
wrapper.setProps({initThreadID: 'hang-by-a-thread'});
opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.deepEqual(
Array.from(opWrapper.find(ReviewsView).prop('threadIDsOpen')),
['hang-by-a-thread'],
);
assert.deepEqual(
Array.from(opWrapper.find(ReviewsView).prop('highlightedThreadIDs')),
['hang-by-a-thread'],
);
assert.isTrue(opWrapper.find(ReviewsView).prop('commentSectionOpen'));
assert.strictEqual(opWrapper.find(ReviewsView).prop('scrollToThreadID'), 'hang-by-a-thread');
clock.tick(1000);
wrapper.setProps({initThreadID: 'caught-in-a-web'});
opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.deepEqual(
Array.from(opWrapper.find(ReviewsView).prop('threadIDsOpen')),
['hang-by-a-thread', 'caught-in-a-web'],
);
assert.deepEqual(
Array.from(opWrapper.find(ReviewsView).prop('highlightedThreadIDs')),
['hang-by-a-thread', 'caught-in-a-web'],
);
assert.isTrue(opWrapper.find(ReviewsView).prop('commentSectionOpen'));
assert.strictEqual(opWrapper.find(ReviewsView).prop('scrollToThreadID'), 'caught-in-a-web');
clock.tick(1000);
opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.deepEqual(
Array.from(opWrapper.find(ReviewsView).prop('highlightedThreadIDs')),
['caught-in-a-web'],
);
assert.strictEqual(opWrapper.find(ReviewsView).prop('scrollToThreadID'), 'caught-in-a-web');
});
describe('openIssueish', function() {
it('opens an IssueishDetailItem for a different issueish', async function() {
const wrapper = shallow(buildApp({
endpoint: getEndpoint('github.enterprise.horse'),
}));
const opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
await opWrapper.find(ReviewsView).prop('openIssueish')('owner', 'repo', 10);
assert.include(
atomEnv.workspace.getPaneItems().map(item => item.getURI()),
IssueishDetailItem.buildURI({host: 'github.enterprise.horse', owner: 'owner', repo: 'repo', number: 10}),
);
});
it('locates a resident Repository in the context pool if exactly one is available', async function() {
const workdirContextPool = new WorkdirContextPool();
const otherDir = await cloneRepository();
const otherRepo = workdirContextPool.add(otherDir).getRepository();
await otherRepo.getLoadPromise();
await otherRepo.addRemote('up', 'git@github.com:owner/repo.git');
const wrapper = shallow(buildApp({
endpoint: getEndpoint('github.com'),
workdirContextPool,
}));
const opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
await opWrapper.find(ReviewsView).prop('openIssueish')('owner', 'repo', 10);
assert.include(
atomEnv.workspace.getPaneItems().map(item => item.getURI()),
IssueishDetailItem.buildURI({host: 'github.com', owner: 'owner', repo: 'repo', number: 10, workdir: otherDir}),
);
});
it('prefers the current Repository if it matches', async function() {
const workdirContextPool = new WorkdirContextPool();
const currentDir = await cloneRepository();
const currentRepo = workdirContextPool.add(currentDir).getRepository();
await currentRepo.getLoadPromise();
await currentRepo.addRemote('up', 'git@github.com:owner/repo.git');
const otherDir = await cloneRepository();
const otherRepo = workdirContextPool.add(otherDir).getRepository();
await otherRepo.getLoadPromise();
await otherRepo.addRemote('up', 'git@github.com:owner/repo.git');
const wrapper = shallow(buildApp({
endpoint: getEndpoint('github.com'),
workdirContextPool,
localRepository: currentRepo,
}));
const opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
await opWrapper.find(ReviewsView).prop('openIssueish')('owner', 'repo', 10);
assert.include(
atomEnv.workspace.getPaneItems().map(item => item.getURI()),
IssueishDetailItem.buildURI({
host: 'github.com', owner: 'owner', repo: 'repo', number: 10, workdir: currentDir,
}),
);
});
});
describe('context lines', function() {
it('defaults to 4 lines of context', function() {
const wrapper = shallow(buildApp());
const opWrapper = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.strictEqual(opWrapper.find(ReviewsView).prop('contextLines'), 4);
});
it('increases context lines with moreContext', function() {
const wrapper = shallow(buildApp());
const opWrapper0 = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
opWrapper0.find(ReviewsView).prop('moreContext')();
const opWrapper1 = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.strictEqual(opWrapper1.find(ReviewsView).prop('contextLines'), 5);
});
it('decreases context lines with lessContext', function() {
const wrapper = shallow(buildApp());
const opWrapper0 = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
opWrapper0.find(ReviewsView).prop('lessContext')();
const opWrapper1 = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.strictEqual(opWrapper1.find(ReviewsView).prop('contextLines'), 3);
});
it('ensures that at least one context line is present', function() {
const wrapper = shallow(buildApp());
const opWrapper0 = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
for (let i = 0; i < 3; i++) {
opWrapper0.find(ReviewsView).prop('lessContext')();
}
const opWrapper1 = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.strictEqual(opWrapper1.find(ReviewsView).prop('contextLines'), 1);
opWrapper1.find(ReviewsView).prop('lessContext')();
const opWrapper2 = wrapper.find(PullRequestCheckoutController).renderProp('children')(noop);
assert.strictEqual(opWrapper2.find(ReviewsView).prop('contextLines'), 1);
});
});
describe('adding a single comment', function() {
it('creates a review, attaches the comment, and submits it', async function() {
expectRelayQuery({
name: addPrReviewMutation.operation.name,
variables: {
input: {pullRequestId: 'pr0'},
},
}, op => {
return relayResponseBuilder(op)
.addPullRequestReview(m => {
m.reviewEdge(e => e.node(r => r.id('review0')));
})
.build();
}).resolve();
expectRelayQuery({
name: addPrReviewCommentMutation.operation.name,
variables: {
input: {body: 'body', inReplyTo: 'comment1', pullRequestReviewId: 'review0'},
},
}, op => {
return relayResponseBuilder(op)
.addPullRequestReviewComment(m => {
m.commentEdge(e => e.node(c => c.id('comment2')));
})
.build();
}).resolve();
expectRelayQuery({
name: submitPrReviewMutation.operation.name,
variables: {
input: {pullRequestReviewId: 'review0', event: 'COMMENT'},
},
}, op => {
return relayResponseBuilder(op)
.submitPullRequestReview(m => {
m.pullRequestReview(r => r.id('review0'));
})
.build();
}).resolve();
const pullRequest = pullRequestBuilder(pullRequestQuery).id('pr0').build();
const wrapper = shallow(buildApp({pullRequest}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
const didSubmitComment = sinon.spy();
const didFailComment = sinon.spy();
await wrapper.find(ReviewsView).prop('addSingleComment')(
'body', 'thread0', 'comment1', 'file0.txt', 10, {didSubmitComment, didFailComment},
);
assert.isTrue(didSubmitComment.called);
assert.isFalse(didFailComment.called);
});
it('creates a notification when the review cannot be created', async function() {
const reportRelayError = sinon.spy();
expectRelayQuery({
name: addPrReviewMutation.operation.name,
variables: {
input: {pullRequestId: 'pr0'},
},
}, op => {
return relayResponseBuilder(op)
.addError('Oh no')
.build();
}).resolve();
const pullRequest = pullRequestBuilder(pullRequestQuery).id('pr0').build();
const wrapper = shallow(buildApp({pullRequest, reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
const didSubmitComment = sinon.spy();
const didFailComment = sinon.spy();
await wrapper.find(ReviewsView).prop('addSingleComment')(
'body', 'thread0', 'comment1', 'file1.txt', 20, {didSubmitComment, didFailComment},
);
assert.isTrue(reportRelayError.calledWith('Unable to submit your comment'));
assert.isFalse(didSubmitComment.called);
assert.isTrue(didFailComment.called);
});
it('creates a notification and deletes the review when the comment cannot be added', async function() {
const reportRelayError = sinon.spy();
expectRelayQuery({
name: addPrReviewMutation.operation.name,
variables: {
input: {pullRequestId: 'pr0'},
},
}, op => {
return relayResponseBuilder(op)
.addPullRequestReview(m => {
m.reviewEdge(e => e.node(r => r.id('review0')));
})
.build();
}).resolve();
expectRelayQuery({
name: addPrReviewCommentMutation.operation.name,
variables: {
input: {body: 'body', inReplyTo: 'comment1', pullRequestReviewId: 'review0'},
},
}, op => {
return relayResponseBuilder(op)
.addError('Kerpow')
.addError('Wat')
.build();
}).resolve();
expectRelayQuery({
name: deletePrReviewMutation.operation.name,
variables: {
input: {pullRequestReviewId: 'review0'},
},
}, op => {
return relayResponseBuilder(op).build();
}).resolve();
const pullRequest = pullRequestBuilder(pullRequestQuery).id('pr0').build();
const wrapper = shallow(buildApp({pullRequest, reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
const didSubmitComment = sinon.spy();
const didFailComment = sinon.spy();
await wrapper.find(ReviewsView).prop('addSingleComment')(
'body', 'thread0', 'comment1', 'file2.txt', 5, {didSubmitComment, didFailComment},
);
assert.isTrue(reportRelayError.calledWith('Unable to submit your comment'));
assert.isTrue(didSubmitComment.called);
assert.isTrue(didFailComment.called);
});
it('includes errors from the review deletion', async function() {
const reportRelayError = sinon.spy();
expectRelayQuery({
name: addPrReviewMutation.operation.name,
variables: {
input: {pullRequestId: 'pr0'},
},
}, op => {
return relayResponseBuilder(op)
.addPullRequestReview(m => {
m.reviewEdge(e => e.node(r => r.id('review0')));
})
.build();
}).resolve();
expectRelayQuery({
name: addPrReviewCommentMutation.operation.name,
variables: {
input: {body: 'body', inReplyTo: 'comment1', pullRequestReviewId: 'review0'},
},
}, op => {
return relayResponseBuilder(op)
.addError('Kerpow')
.addError('Wat')
.build();
}).resolve();
expectRelayQuery({
name: deletePrReviewMutation.operation.name,
variables: {
input: {pullRequestReviewId: 'review0'},
},
}, op => {
return relayResponseBuilder(op)
.addError('Bam')
.build();
}).resolve();
const pullRequest = pullRequestBuilder(pullRequestQuery).id('pr0').build();
const wrapper = shallow(buildApp({pullRequest, reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await wrapper.find(ReviewsView).prop('addSingleComment')(
'body', 'thread0', 'comment1', 'file1.txt', 10,
);
});
it('creates a notification when the review cannot be submitted', async function() {
const reportRelayError = sinon.spy();
expectRelayQuery({
name: addPrReviewMutation.operation.name,
variables: {
input: {pullRequestId: 'pr0'},
},
}, op => {
return relayResponseBuilder(op)
.addPullRequestReview(m => {
m.reviewEdge(e => e.node(r => r.id('review0')));
})
.build();
}).resolve();
expectRelayQuery({
name: addPrReviewCommentMutation.operation.name,
variables: {
input: {body: 'body', inReplyTo: 'comment1', pullRequestReviewId: 'review0'},
},
}, op => {
return relayResponseBuilder(op)
.addPullRequestReviewComment(m => {
m.commentEdge(e => e.node(c => c.id('comment2')));
})
.build();
}).resolve();
expectRelayQuery({
name: submitPrReviewMutation.operation.name,
variables: {
input: {pullRequestReviewId: 'review0', event: 'COMMENT'},
},
}, op => {
return relayResponseBuilder(op)
.addError('Ouch')
.build();
}).resolve();
const pullRequest = pullRequestBuilder(pullRequestQuery).id('pr0').build();
const wrapper = shallow(buildApp({pullRequest, reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
const didSubmitComment = sinon.spy();
const didFailComment = sinon.spy();
await wrapper.find(ReviewsView).prop('addSingleComment')(
'body', 'thread0', 'comment1', 'file1.txt', 10, {didSubmitComment, didFailComment},
);
assert.isTrue(reportRelayError.calledWith('Unable to submit your comment'));
assert.isTrue(didSubmitComment.called);
assert.isTrue(didFailComment.called);
});
});
describe('resolving threads', function() {
it('hides the thread, then fires the mutation', async function() {
const reportRelayError = sinon.spy();
expectRelayQuery({
name: resolveThreadMutation.operation.name,
variables: {
input: {threadId: 'thread0'},
},
}, op => relayResponseBuilder(op).build()).resolve();
const wrapper = shallow(buildApp({reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await wrapper.find(ReviewsView).prop('showThreadID')('thread0');
assert.isTrue(wrapper.find(ReviewsView).prop('threadIDsOpen').has('thread0'));
await wrapper.find(ReviewsView).prop('resolveThread')({id: 'thread0', viewerCanResolve: true});
assert.isFalse(wrapper.find(ReviewsView).prop('threadIDsOpen').has('thread0'));
assert.isFalse(reportRelayError.called);
});
it('is a no-op if the viewer cannot resolve the thread', async function() {
const reportRelayError = sinon.spy();
const wrapper = shallow(buildApp({reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await wrapper.find(ReviewsView).prop('showThreadID')('thread0');
await wrapper.find(ReviewsView).prop('resolveThread')({id: 'thread0', viewerCanResolve: false});
assert.isTrue(wrapper.find(ReviewsView).prop('threadIDsOpen').has('thread0'));
assert.isFalse(reportRelayError.called);
});
it('re-shows the thread and creates a notification when the thread cannot be resolved', async function() {
const reportRelayError = sinon.spy();
expectRelayQuery({
name: resolveThreadMutation.operation.name,
variables: {
input: {threadId: 'thread0'},
},
}, op => relayResponseBuilder(op).addError('boom').build()).resolve();
const wrapper = shallow(buildApp({reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await wrapper.find(ReviewsView).prop('showThreadID')('thread0');
await wrapper.find(ReviewsView).prop('resolveThread')({id: 'thread0', viewerCanResolve: true});
assert.isTrue(wrapper.find(ReviewsView).prop('threadIDsOpen').has('thread0'));
assert.isTrue(reportRelayError.calledWith('Unable to resolve the comment thread'));
});
});
describe('unresolving threads', function() {
it('calls the unresolve mutation', async function() {
sinon.stub(atomEnv.notifications, 'addError').returns();
expectRelayQuery({
name: unresolveThreadMutation.operation.name,
variables: {
input: {threadId: 'thread1'},
},
}, op => relayResponseBuilder(op).build()).resolve();
const wrapper = shallow(buildApp())
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await wrapper.find(ReviewsView).prop('unresolveThread')({id: 'thread1', viewerCanUnresolve: true});
assert.isFalse(atomEnv.notifications.addError.called);
});
it("is a no-op if the viewer can't unresolve the thread", async function() {
const reportRelayError = sinon.spy();
const wrapper = shallow(buildApp({reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await wrapper.find(ReviewsView).prop('unresolveThread')({id: 'thread1', viewerCanUnresolve: false});
assert.isFalse(reportRelayError.called);
});
it('creates a notification if the thread cannot be unresolved', async function() {
const reportRelayError = sinon.spy();
expectRelayQuery({
name: unresolveThreadMutation.operation.name,
variables: {
input: {threadId: 'thread1'},
},
}, op => relayResponseBuilder(op).addError('ow').build()).resolve();
const wrapper = shallow(buildApp({reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await wrapper.find(ReviewsView).prop('unresolveThread')({id: 'thread1', viewerCanUnresolve: true});
assert.isTrue(reportRelayError.calledWith('Unable to unresolve the comment thread'));
});
});
describe('editing review comments', function() {
it('calls the review comment update mutation and increments a metric', async function() {
const reportRelayError = sinon.spy();
sinon.stub(reporterProxy, 'addEvent');
expectRelayQuery({
name: updateReviewCommentMutation.operation.name,
variables: {
input: {pullRequestReviewCommentId: 'comment-0', body: 'new text'},
},
}, op => relayResponseBuilder(op).build()).resolve();
const wrapper = shallow(buildApp({reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await wrapper.find(ReviewsView).prop('updateComment')('comment-0', 'new text');
assert.isFalse(reportRelayError.called);
assert.isTrue(reporterProxy.addEvent.calledWith('update-review-comment', {package: 'github'}));
});
it('creates a notification and and re-throws the error if the comment cannot be updated', async function() {
const reportRelayError = sinon.spy();
sinon.stub(reporterProxy, 'addEvent');
expectRelayQuery({
name: updateReviewCommentMutation.operation.name,
variables: {
input: {pullRequestReviewCommentId: 'comment-0', body: 'new text'},
},
}, op => relayResponseBuilder(op).addError('not right now').build()).resolve();
const wrapper = shallow(buildApp({reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await assert.isRejected(
wrapper.find(ReviewsView).prop('updateComment')('comment-0', 'new text'),
);
assert.isTrue(reportRelayError.calledWith('Unable to update comment'));
assert.isFalse(reporterProxy.addEvent.called);
});
});
describe('editing review summaries', function() {
it('calls the review summary update mutation and increments a metric', async function() {
const reportRelayError = sinon.spy();
sinon.stub(reporterProxy, 'addEvent');
expectRelayQuery({
name: updatePrReviewMutation.operation.name,
variables: {
input: {pullRequestReviewId: 'review-0', body: 'stuff'},
},
}, op => relayResponseBuilder(op).build()).resolve();
const wrapper = shallow(buildApp({reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await wrapper.find(ReviewsView).prop('updateSummary')('review-0', 'stuff');
assert.isFalse(reportRelayError.called);
assert.isTrue(reporterProxy.addEvent.calledWith('update-review-summary', {package: 'github'}));
});
it('creates a notification and and re-throws the error if the summary cannot be updated', async function() {
const reportRelayError = sinon.spy();
sinon.stub(reporterProxy, 'addEvent');
expectRelayQuery({
name: updatePrReviewMutation.operation.name,
variables: {
input: {pullRequestReviewId: 'review-0', body: 'stuff'},
},
}, op => relayResponseBuilder(op).addError('not right now').build()).resolve();
const wrapper = shallow(buildApp({reportRelayError}))
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
await assert.isRejected(
wrapper.find(ReviewsView).prop('updateSummary')('review-0', 'stuff'),
);
assert.isTrue(reportRelayError.calledWith('Unable to update review summary'));
assert.isFalse(reporterProxy.addEvent.called);
});
});
describe('action methods', function() {
let wrapper, openFilesTab, onTabSelected;
beforeEach(function() {
openFilesTab = sinon.spy();
onTabSelected = sinon.spy();
sinon.stub(atomEnv.workspace, 'open').resolves({openFilesTab, onTabSelected});
sinon.stub(reporterProxy, 'addEvent');
wrapper = shallow(buildApp())
.find(PullRequestCheckoutController)
.renderProp('children')(noop);
});
it('opens file on disk', async function() {
await wrapper.find(ReviewsView).prop('openFile')('filepath', 420);
assert.isTrue(atomEnv.workspace.open.calledWith(
path.join(localRepository.getWorkingDirectoryPath(), 'filepath'), {
initialLine: 420 - 1,
initialColumn: 0,
pending: true,
},
));
assert.isTrue(reporterProxy.addEvent.calledWith('reviews-dock-open-file', {package: 'github'}));
});
it('opens diff in PR detail item', async function() {
await wrapper.find(ReviewsView).prop('openDiff')('filepath', 420);
assert.isTrue(atomEnv.workspace.open.calledWith(
IssueishDetailItem.buildURI({
host: 'github.com',
owner: 'atom',
repo: 'github',
number: 1995,
workdir: localRepository.getWorkingDirectoryPath(),
}), {
pending: true,
searchAllPanes: true,
},
));
assert.isTrue(openFilesTab.calledWith({changedFilePath: 'filepath', changedFilePosition: 420}));
assert.isTrue(reporterProxy.addEvent.calledWith('reviews-dock-open-diff', {
package: 'github', component: 'BareReviewsController',
}));
});
it('opens overview of a PR detail item', async function() {
await wrapper.find(ReviewsView).prop('openPR')();
assert.isTrue(atomEnv.workspace.open.calledWith(
IssueishDetailItem.buildURI({
host: 'github.com',
owner: 'atom',
repo: 'github',
number: 1995,
workdir: localRepository.getWorkingDirectoryPath(),
}), {
pending: true,
searchAllPanes: true,
},
));
assert.isTrue(reporterProxy.addEvent.calledWith('reviews-dock-open-pr', {
package: 'github', component: 'BareReviewsController',
}));
});
it('manages the open/close state of the summary section', async function() {
assert.isTrue(await wrapper.find(ReviewsView).prop('summarySectionOpen'), true);
await wrapper.find(ReviewsView).prop('hideSummaries')();
assert.isTrue(await wrapper.find(ReviewsView).prop('summarySectionOpen'), false);
await wrapper.find(ReviewsView).prop('showSummaries')();
assert.isTrue(await wrapper.find(ReviewsView).prop('summarySectionOpen'), true);
});
it('manages the open/close state of the comment section', async function() {
assert.isTrue(await wrapper.find(ReviewsView).prop('commentSectionOpen'), true);
await wrapper.find(ReviewsView).prop('hideComments')();
assert.isTrue(await wrapper.find(ReviewsView).prop('commentSectionOpen'), false);
await wrapper.find(ReviewsView).prop('showComments')();
assert.isTrue(await wrapper.find(ReviewsView).prop('commentSectionOpen'), true);
});
});
});