forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissueish-list-controller.test.js
More file actions
84 lines (67 loc) · 2.55 KB
/
issueish-list-controller.test.js
File metadata and controls
84 lines (67 loc) · 2.55 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
import React from 'react';
import {shallow} from 'enzyme';
import {createPullRequestResult} from '../fixtures/factories/pull-request-result';
import Issueish from '../../lib/models/issueish';
import {BareIssueishListController} from '../../lib/controllers/issueish-list-controller';
describe('IssueishListController', function() {
function buildApp(overrideProps = {}) {
return (
<BareIssueishListController
title="title"
results={null}
repository={null}
isLoading={false}
onOpenIssueish={() => {}}
onOpenMore={() => {}}
{...overrideProps}
/>
);
}
it('renders an IssueishListView in a loading state', function() {
const wrapper = shallow(buildApp({isLoading: true}));
const view = wrapper.find('IssueishListView');
assert.isTrue(view.prop('isLoading'));
assert.strictEqual(view.prop('total'), 0);
assert.lengthOf(view.prop('issueishes'), 0);
});
it('renders an IssueishListView in an error state', function() {
const error = new Error("d'oh");
error.rawStack = error.stack;
const wrapper = shallow(buildApp({error}));
const view = wrapper.find('IssueishListView');
assert.strictEqual(view.prop('error'), error);
});
it('renders an IssueishListView with issueish results', function() {
const mockPullRequest = createPullRequestResult({number: 1});
const onOpenIssueish = sinon.stub();
const onOpenMore = sinon.stub();
const wrapper = shallow(buildApp({
results: [mockPullRequest],
total: 1,
onOpenIssueish,
onOpenMore,
}));
const view = wrapper.find('IssueishListView');
assert.isFalse(view.prop('isLoading'));
assert.strictEqual(view.prop('total'), 1);
assert.lengthOf(view.prop('issueishes'), 1);
assert.deepEqual(view.prop('issueishes'), [
new Issueish(mockPullRequest),
]);
const payload = Symbol('payload');
view.prop('onIssueishClick')(payload);
assert.isTrue(onOpenIssueish.calledWith(payload));
view.prop('onMoreClick')(payload);
assert.isTrue(onOpenMore.calledWith(payload));
});
it('applies a resultFilter to limit its results', function() {
const wrapper = shallow(buildApp({
resultFilter: issueish => issueish.getNumber() > 10,
results: [0, 11, 13, 5, 12].map(number => createPullRequestResult({number})),
total: 5,
}));
const view = wrapper.find('IssueishListView');
assert.strictEqual(view.prop('total'), 5);
assert.deepEqual(view.prop('issueishes').map(issueish => issueish.getNumber()), [11, 13, 12]);
});
});