forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr-changed-files-container.test.js
More file actions
112 lines (88 loc) · 4.46 KB
/
Copy pathpr-changed-files-container.test.js
File metadata and controls
112 lines (88 loc) · 4.46 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
import React from 'react';
import {shallow} from 'enzyme';
import {getEndpoint} from '../../lib/models/endpoint';
import {multiFilePatchBuilder} from '../builder/patch';
import PullRequestChangedFilesContainer from '../../lib/containers/pr-changed-files-container';
import IssueishDetailItem from '../../lib/items/issueish-detail-item';
describe('PullRequestChangedFilesContainer', function() {
function buildApp(overrideProps = {}) {
return (
<PullRequestChangedFilesContainer
owner="atom"
repo="github"
number={1804}
token="1234"
endpoint={getEndpoint('github.com')}
itemType={IssueishDetailItem}
destroy={() => {}}
shouldRefetch={false}
workspace={{}}
commands={{}}
keymaps={{}}
tooltips={{}}
config={{}}
localRepository={{}}
reviewCommentsLoading={false}
reviewCommentThreads={[]}
onOpenFilesTab={() => {}}
{...overrideProps}
/>
);
}
describe('when the patch is loading', function() {
it('renders a LoadingView', function() {
const wrapper = shallow(buildApp());
const subwrapper = wrapper.find('PullRequestPatchContainer').renderProp('children')(null, null);
assert.isTrue(subwrapper.exists('LoadingView'));
});
});
describe('when the patch is fetched successfully', function() {
it('passes the MultiFilePatch to a MultiFilePatchController', function() {
const {multiFilePatch} = multiFilePatchBuilder().build();
const wrapper = shallow(buildApp());
const subwrapper = wrapper.find('PullRequestPatchContainer').renderProp('children')(null, multiFilePatch);
assert.strictEqual(subwrapper.find('MultiFilePatchController').prop('multiFilePatch'), multiFilePatch);
});
it('passes extra props through to MultiFilePatchController', function() {
const {multiFilePatch} = multiFilePatchBuilder().build();
const extraProp = Symbol('really really extra');
const wrapper = shallow(buildApp({extraProp}));
const subwrapper = wrapper.find('PullRequestPatchContainer').renderProp('children')(null, multiFilePatch);
assert.strictEqual(subwrapper.find('MultiFilePatchController').prop('extraProp'), extraProp);
});
it('re-fetches data when shouldRefetch is true', function() {
const wrapper = shallow(buildApp({shouldRefetch: true}));
assert.isTrue(wrapper.find('PullRequestPatchContainer').prop('refetch'));
});
it('manages a subscription on the active MultiFilePatch', function() {
const {multiFilePatch: mfp0} = multiFilePatchBuilder().addFilePatch().build();
const wrapper = shallow(buildApp());
wrapper.find('PullRequestPatchContainer').renderProp('children')(null, mfp0);
assert.strictEqual(mfp0.getFilePatches()[0].emitter.listenerCountForEventName('change-render-status'), 1);
wrapper.find('PullRequestPatchContainer').renderProp('children')(null, mfp0);
assert.strictEqual(mfp0.getFilePatches()[0].emitter.listenerCountForEventName('change-render-status'), 1);
const {multiFilePatch: mfp1} = multiFilePatchBuilder().addFilePatch().build();
wrapper.find('PullRequestPatchContainer').renderProp('children')(null, mfp1);
assert.strictEqual(mfp0.getFilePatches()[0].emitter.listenerCountForEventName('change-render-status'), 0);
assert.strictEqual(mfp1.getFilePatches()[0].emitter.listenerCountForEventName('change-render-status'), 1);
});
it('disposes the MultiFilePatch subscription on unmount', function() {
const {multiFilePatch} = multiFilePatchBuilder().addFilePatch().build();
const wrapper = shallow(buildApp());
const subwrapper = wrapper.find('PullRequestPatchContainer').renderProp('children')(null, multiFilePatch);
const mfp = subwrapper.find('MultiFilePatchController').prop('multiFilePatch');
const [fp] = mfp.getFilePatches();
assert.strictEqual(fp.emitter.listenerCountForEventName('change-render-status'), 1);
wrapper.unmount();
assert.strictEqual(fp.emitter.listenerCountForEventName('change-render-status'), 0);
});
});
describe('when the patch load fails', function() {
it('renders the message in an ErrorView', function() {
const error = 'oh noooooo';
const wrapper = shallow(buildApp());
const subwrapper = wrapper.find('PullRequestPatchContainer').renderProp('children')(error, null);
assert.deepEqual(subwrapper.find('ErrorView').prop('descriptions'), [error]);
});
});
});