This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy patheditor-comment-decorations-controller.test.js
More file actions
169 lines (140 loc) · 5.48 KB
/
editor-comment-decorations-controller.test.js
File metadata and controls
169 lines (140 loc) · 5.48 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import React from 'react';
import {shallow} from 'enzyme';
import {Range} from 'atom';
import EditorCommentDecorationsController from '../../lib/controllers/editor-comment-decorations-controller';
import CommentGutterDecorationController from '../../lib/controllers/comment-gutter-decoration-controller';
import Marker from '../../lib/atom/marker';
import Decoration from '../../lib/atom/decoration';
import {getEndpoint} from '../../lib/models/endpoint';
import ReviewsItem from '../../lib/items/reviews-item';
describe('EditorCommentDecorationsController', function() {
let atomEnv, workspace, editor, wrapper;
beforeEach(async function() {
atomEnv = global.buildAtomEnvironment();
workspace = atomEnv.workspace;
editor = await workspace.open(__filename);
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(opts = {}) {
const props = {
endpoint: getEndpoint('github.com'),
owner: 'owner',
repo: 'repo',
number: 123,
workdir: __dirname,
workspace,
editor,
threadsForPath: [],
commentTranslationsForPath: {
diffToFilePosition: new Map(),
removed: false,
},
...opts,
};
return <EditorCommentDecorationsController {...props} />;
}
it('renders nothing if no position translations are available for this path', function() {
wrapper = shallow(buildApp({commentTranslationsForPath: null}));
assert.isTrue(wrapper.isEmptyRender());
});
it('creates a marker and decoration controller for each comment thread at its translated line position', function() {
const threadsForPath = [
{rootCommentID: 'comment0', position: 4, threadID: 'thread0'},
{rootCommentID: 'comment1', position: 10, threadID: 'thread1'},
{rootCommentID: 'untranslateable', position: 20, threadID: 'thread2'},
{rootCommentID: 'positionless', position: null, threadID: 'thread3'},
];
const commentTranslationsForPath = {
diffToFilePosition: new Map([
[4, 7],
[10, 13],
]),
removed: false,
};
wrapper = shallow(buildApp({threadsForPath, commentTranslationsForPath}));
const markers = wrapper.find(Marker);
assert.lengthOf(markers, 2);
assert.isTrue(markers.someWhere(w => w.prop('bufferRange').isEqual([[6, 0], [6, Infinity]])));
assert.isTrue(markers.someWhere(w => w.prop('bufferRange').isEqual([[12, 0], [12, Infinity]])));
const controllers = wrapper.find(CommentGutterDecorationController);
assert.lengthOf(controllers, 2);
assert.isTrue(controllers.someWhere(w => w.prop('commentRow') === 6));
assert.isTrue(controllers.someWhere(w => w.prop('commentRow') === 12));
});
it('creates a line decoration for each line with a comment', function() {
const threadsForPath = [
{rootCommentID: 'comment0', position: 4, threadID: 'thread0'},
{rootCommentID: 'comment1', position: 10, threadID: 'thread1'},
];
const commentTranslationsForPath = {
diffToFilePosition: new Map([
[4, 5],
[10, 11],
]),
removed: false,
};
wrapper = shallow(buildApp({threadsForPath, commentTranslationsForPath}));
const decorations = wrapper.find(Decoration);
assert.lengthOf(decorations.findWhere(decoration => decoration.prop('type') === 'line'), 2);
});
it('updates rendered marker positions as the underlying buffer is modified', function() {
const threadsForPath = [
{rootCommentID: 'comment0', position: 4, threadID: 'thread0'},
];
const commentTranslationsForPath = {
diffToFilePosition: new Map([[4, 4]]),
removed: false,
digest: '1111',
};
wrapper = shallow(buildApp({threadsForPath, commentTranslationsForPath}));
const marker = wrapper.find(Marker);
assert.isTrue(marker.prop('bufferRange').isEqual([[3, 0], [3, Infinity]]));
marker.prop('didChange')({newRange: Range.fromObject([[5, 0], [5, 3]])});
// Ensure the component re-renders
wrapper.setProps({
commentTranslationsForPath: {
...commentTranslationsForPath,
digest: '2222',
},
});
assert.isTrue(wrapper.find(Marker).prop('bufferRange').isEqual([[5, 0], [5, 3]]));
});
it('creates a block decoration if the diff was too large to parse', async function() {
const threadsForPath = [
{rootCommentID: 'comment0', position: 4, threadID: 'thread0'},
{rootCommentID: 'comment1', position: 10, threadID: 'thread1'},
];
const commentTranslationsForPath = {
diffToFilePosition: new Map(),
removed: true,
};
wrapper = shallow(buildApp({
threadsForPath,
commentTranslationsForPath,
endpoint: getEndpoint('github.enterprise.horse'),
owner: 'some-owner',
repo: 'a-repo',
number: 400,
workdir: __dirname,
}));
const decorations = wrapper.find(Decoration);
assert.lengthOf(decorations.findWhere(decoration => decoration.prop('type') === 'line'), 0);
assert.lengthOf(decorations.findWhere(decoration => decoration.prop('type') === 'block'), 1);
const reviewsItem = {jumpToThread: sinon.spy()};
sinon.stub(workspace, 'open').resolves(reviewsItem);
await wrapper.find('button').prop('onClick')();
assert.isTrue(workspace.open.calledWith(
ReviewsItem.buildURI({
host: 'github.enterprise.horse',
owner: 'some-owner',
repo: 'a-repo',
number: 400,
workdir: __dirname,
}),
{searchAllPanes: true},
));
assert.isTrue(reviewsItem.jumpToThread.calledWith('thread0'));
});
});