forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreviews-item.test.js
More file actions
138 lines (111 loc) · 4.03 KB
/
Copy pathreviews-item.test.js
File metadata and controls
138 lines (111 loc) · 4.03 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
import React from 'react';
import {mount} from 'enzyme';
import ReviewsItem from '../../lib/items/reviews-item';
import {cloneRepository} from '../helpers';
import PaneItem from '../../lib/atom/pane-item';
import {InMemoryStrategy} from '../../lib/shared/keytar-strategy';
import GithubLoginModel from '../../lib/models/github-login-model';
import WorkdirContextPool from '../../lib/models/workdir-context-pool';
describe('ReviewsItem', function() {
let atomEnv, repository, pool;
beforeEach(async function() {
atomEnv = global.buildAtomEnvironment();
const workdir = await cloneRepository();
pool = new WorkdirContextPool({
workspace: atomEnv.workspace,
});
repository = pool.add(workdir).getRepository();
});
afterEach(function() {
atomEnv.destroy();
pool.clear();
});
function buildPaneApp(override = {}) {
const props = {
workdirContextPool: pool,
loginModel: new GithubLoginModel(InMemoryStrategy),
workspace: atomEnv.workspace,
config: atomEnv.config,
commands: atomEnv.commands,
tooltips: atomEnv.tooltips,
reportRelayError: () => {},
...override,
};
return (
<PaneItem workspace={atomEnv.workspace} uriPattern={ReviewsItem.uriPattern}>
{({itemHolder, params}) => (
<ReviewsItem
ref={itemHolder.setter}
{...params}
number={parseInt(params.number, 10)}
{...props}
/>
)}
</PaneItem>
);
}
async function open(wrapper, options = {}) {
const opts = {
host: 'github.com',
owner: 'atom',
repo: 'github',
number: 1848,
workdir: repository.getWorkingDirectoryPath(),
...options,
};
const uri = ReviewsItem.buildURI(opts);
const item = await atomEnv.workspace.open(uri);
wrapper.update();
return item;
}
it('constructs and opens the correct URI', async function() {
const wrapper = mount(buildPaneApp());
assert.isFalse(wrapper.exists('ReviewsItem'));
await open(wrapper);
assert.isTrue(wrapper.exists('ReviewsItem'));
});
it('locates the repository from the context pool', async function() {
const wrapper = mount(buildPaneApp());
await open(wrapper);
assert.strictEqual(wrapper.find('ReviewsContainer').prop('repository'), repository);
});
it('uses an absent repository if no workdir is provided', async function() {
const wrapper = mount(buildPaneApp());
await open(wrapper, {workdir: null});
assert.isTrue(wrapper.find('ReviewsContainer').prop('repository').isAbsent());
});
it('returns a title containing the pull request number', async function() {
const wrapper = mount(buildPaneApp());
const item = await open(wrapper, {number: 1234});
assert.strictEqual(item.getTitle(), 'Reviews #1234');
});
it('may be destroyed once', async function() {
const wrapper = mount(buildPaneApp());
const item = await open(wrapper);
const callback = sinon.spy();
const sub = item.onDidDestroy(callback);
assert.strictEqual(callback.callCount, 0);
item.destroy();
assert.strictEqual(callback.callCount, 1);
sub.dispose();
});
it('serializes itself as a ReviewsItemStub', async function() {
const wrapper = mount(buildPaneApp());
const item = await open(wrapper, {host: 'github.horse', owner: 'atom', repo: 'atom', number: 12, workdir: '/here'});
assert.deepEqual(item.serialize(), {
deserializer: 'ReviewsStub',
uri: 'atom-github://reviews/github.horse/atom/atom/12?workdir=%2Fhere',
});
});
it('jumps to thread', async function() {
const wrapper = mount(buildPaneApp());
const item = await open(wrapper);
assert.isNull(item.state.initThreadID);
await item.jumpToThread('an-id');
assert.strictEqual(item.state.initThreadID, 'an-id');
// Jumping to the same ID toggles initThreadID to null and back, but we can't really test the intermediate
// state there so OH WELL
await item.jumpToThread('an-id');
assert.strictEqual(item.state.initThreadID, 'an-id');
});
});