forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissueish-list-controller.test.js
124 lines (97 loc) · 3.96 KB
/
issueish-list-controller.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
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
import React from 'react';
import {shallow} from 'enzyme';
import {shell} from 'electron';
import {createPullRequestResult} from '../fixtures/factories/pull-request-result';
import Issueish from '../../lib/models/issueish';
import {BareIssueishListController} from '../../lib/controllers/issueish-list-controller';
import * as reporterProxy from '../../lib/reporter-proxy';
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]);
});
describe('openOnGitHub', function() {
const url = 'https://github.com/atom/github/pull/2084';
it('calls shell.openExternal with specified url', async function() {
const wrapper = shallow(buildApp());
sinon.stub(shell, 'openExternal').callsFake(() => { });
await wrapper.instance().openOnGitHub(url);
assert.isTrue(shell.openExternal.calledWith(url));
});
it('fires `open-issueish-in-browser` event upon success', async function() {
const wrapper = shallow(buildApp());
sinon.stub(shell, 'openExternal').callsFake(() => {});
sinon.stub(reporterProxy, 'addEvent');
await wrapper.instance().openOnGitHub(url);
assert.strictEqual(reporterProxy.addEvent.callCount, 1);
await assert.isTrue(reporterProxy.addEvent.calledWith('open-issueish-in-browser', {package: 'github', component: 'BareIssueishListController'}));
});
it('handles error when openOnGitHub fails', async function() {
const wrapper = shallow(buildApp());
sinon.stub(shell, 'openExternal').throws(new Error('oh noes'));
sinon.stub(reporterProxy, 'addEvent');
try {
await wrapper.instance().openOnGitHub(url);
} catch (err) {
assert.strictEqual(err.message, 'oh noes');
}
assert.strictEqual(reporterProxy.addEvent.callCount, 0);
});
});
});