forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment-gutter-decoration-controller.test.js
72 lines (62 loc) · 2.44 KB
/
comment-gutter-decoration-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
import React from 'react';
import {shallow} from 'enzyme';
import CommentGutterDecorationController from '../../lib/controllers/comment-gutter-decoration-controller';
import {getEndpoint} from '../../lib/models/endpoint';
import {Range} from 'atom';
import * as reporterProxy from '../../lib/reporter-proxy';
import ReviewsItem from '../../lib/items/reviews-item';
describe('CommentGutterDecorationController', function() {
let atomEnv, workspace, editor;
function buildApp(opts = {}) {
const props = {
workspace,
editor,
commentRow: 420,
threadId: 'my-thread-will-go-on',
extraClasses: ['celine', 'dion'],
endpoint: getEndpoint('github.com'),
owner: 'owner',
repo: 'repo',
number: 1337,
workdir: 'dir/path',
parent: 'TheThingThatMadeChildren',
...opts,
};
return <CommentGutterDecorationController {...props} />;
}
beforeEach(async function() {
atomEnv = global.buildAtomEnvironment();
workspace = atomEnv.workspace;
editor = await workspace.open(__filename);
});
afterEach(function() {
atomEnv.destroy();
});
it('decorates the comment gutter', function() {
const wrapper = shallow(buildApp());
editor.addGutter({name: 'github-comment-icon'});
const marker = wrapper.find('Marker');
const decoration = marker.find('Decoration');
assert.deepEqual(marker.prop('bufferRange'), new Range([420, 0], [420, Infinity]));
assert.isTrue(decoration.hasClass('celine'));
assert.isTrue(decoration.hasClass('dion'));
assert.isTrue(decoration.hasClass('github-editorCommentGutterIcon'));
assert.strictEqual(decoration.children('button.icon.icon-comment').length, 1);
});
it('opens review dock and jumps to thread when clicked', async function() {
sinon.stub(reporterProxy, 'addEvent');
const jumpToThread = sinon.spy();
sinon.stub(atomEnv.workspace, 'open').resolves({jumpToThread});
const wrapper = shallow(buildApp());
wrapper.find('button.icon-comment').simulate('click');
assert.isTrue(atomEnv.workspace.open.calledWith(
ReviewsItem.buildURI({host: 'github.com', owner: 'owner', repo: 'repo', number: 1337, workdir: 'dir/path'}),
{searchAllPanes: true},
));
await assert.async.isTrue(jumpToThread.calledWith('my-thread-will-go-on'));
assert.isTrue(reporterProxy.addEvent.calledWith('open-review-thread', {
package: 'github',
from: 'TheThingThatMadeChildren',
}));
});
});