forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpr-commits-view.test.js
92 lines (81 loc) · 3.02 KB
/
pr-commits-view.test.js
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
import React from 'react';
import {shallow} from 'enzyme';
import PrCommitView from '../../lib/views/pr-commit-view';
import {PrCommitsView} from '../../lib/views/pr-commits-view';
const commitSpec = {
committer: {
avatarUrl: 'https://avatars3.githubusercontent.com/u/3781742',
name: 'Margaret Hamilton',
date: '2018-05-16T21:54:24.500Z',
},
messageHeadline: 'This one weird trick for getting to the moon will blow your mind 🚀',
shortSha: 'bad1dea',
sha: 'bad1deaea3d816383721478fc631b5edd0c2b370',
url: 'https://github.com/atom/github/pull/1684/commits/bad1deaea3d816383721478fc631b5edd0c2b370',
};
describe('PrCommitsView', function() {
function buildApp(opts, overloadProps = {}) {
const o = {
relayHasMore: () => false,
relayLoadMore: () => {},
relayIsLoading: () => false,
commitSpecs: [],
commitStartCursor: 0,
...opts,
};
if (o.commitTotal === undefined) {
o.commitTotal = o.commitSpecs.length;
}
const props = {
relay: {
hasMore: o.relayHasMore,
loadMore: o.relayLoadMore,
isLoading: o.relayIsLoading,
},
...overloadProps,
};
const commits = {
edges: o.commitSpecs.map((spec, i) => ({
cursor: `result${i}`,
node: {
commit: spec,
id: i,
},
})),
pageInfo: {
startCursor: `result${o.commitStartCursor}`,
endCursor: `result${o.commitStartCursor + o.commitSpecs.length}`,
hasNextPage: o.commitStartCursor + o.commitSpecs.length < o.commitTotal,
hasPreviousPage: o.commitCursor !== 0,
},
totalCount: o.commitTotal,
};
props.pullRequest = {commits};
return <PrCommitsView {...props} />;
}
it('renders commits', function() {
const commitSpecs = [commitSpec, commitSpec];
const wrapper = shallow(buildApp({commitSpecs}));
assert.lengthOf(wrapper.find(PrCommitView), commitSpecs.length);
});
describe('load more button', function() {
it('is not rendered if there are no more commits', function() {
const commitSpecs = [commitSpec, commitSpec];
const wrapper = shallow(buildApp({relayHasMore: () => false, commitSpecs}));
assert.lengthOf(wrapper.find('.github-PrCommitsView-load-more-button'), 0);
});
it('is rendered if there are more commits', function() {
const commitSpecs = [commitSpec, commitSpec];
const wrapper = shallow(buildApp({relayHasMore: () => true, commitSpecs}));
assert.lengthOf(wrapper.find('.github-PrCommitsView-load-more-button'), 1);
});
it('calls relay.loadMore when load more button is clicked', function() {
const commitSpecs = [commitSpec, commitSpec];
const loadMoreStub = sinon.stub(PrCommitsView.prototype, 'loadMore');
const wrapper = shallow(buildApp({relayHasMore: () => true, commitSpecs}));
assert.strictEqual(loadMoreStub.callCount, 0);
wrapper.find('.github-PrCommitsView-load-more-button').simulate('click');
assert.strictEqual(loadMoreStub.callCount, 1);
});
});
});