box-ui-elements 23.4.0-beta.33 → 23.4.0-beta.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/explorer.js +1 -1
- package/dist/preview.js +1 -1
- package/dist/sidebar.js +1 -1
- package/es/elements/common/types/SidebarNavigation.js +4 -2
- package/es/elements/common/types/SidebarNavigation.js.flow +7 -4
- package/es/elements/common/types/SidebarNavigation.js.map +1 -1
- package/es/elements/content-preview/PreviewNavigation.js +65 -2
- package/es/elements/content-preview/PreviewNavigation.js.flow +86 -2
- package/es/elements/content-preview/PreviewNavigation.js.map +1 -1
- package/es/elements/content-sidebar/ActivitySidebar.js +39 -7
- package/es/elements/content-sidebar/ActivitySidebar.js.flow +42 -6
- package/es/elements/content-sidebar/ActivitySidebar.js.map +1 -1
- package/es/src/elements/common/types/SidebarNavigation.d.ts +10 -4
- package/package.json +1 -1
- package/src/elements/common/types/SidebarNavigation.js.flow +7 -4
- package/src/elements/common/types/SidebarNavigation.ts +11 -3
- package/src/elements/content-preview/PreviewNavigation.js +86 -2
- package/src/elements/content-preview/__tests__/PreviewNavigation.test.js +202 -62
- package/src/elements/content-sidebar/ActivitySidebar.js +42 -6
- package/src/elements/content-sidebar/__tests__/ActivitySidebar.rtl.test.js +521 -0
- package/src/elements/content-sidebar/__tests__/ActivitySidebar.test.js +1 -123
- package/src/elements/content-sidebar/__tests__/AddTaskButton.test.js +6 -5
- package/src/elements/content-sidebar/versions/__tests__/StaticVersionSidebar.test.js +3 -5
- package/src/elements/content-preview/__tests__/__snapshots__/PreviewNavigation.test.js.snap +0 -361
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
3
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
4
|
+
import { render } from '../../../test-utils/testing-library';
|
|
5
|
+
import { ActivitySidebarComponent } from '../ActivitySidebar';
|
|
6
|
+
import { formattedReplies } from '../fixtures';
|
|
7
|
+
import ActivityFeed from '../activity-feed';
|
|
8
|
+
import { ViewType, FeedEntryType } from '../../common/types/SidebarNavigation';
|
|
9
|
+
|
|
10
|
+
// Mock generatePath from react-router-dom
|
|
11
|
+
const mockGeneratePath = jest.fn();
|
|
12
|
+
jest.mock('react-router-dom', () => ({
|
|
13
|
+
...jest.requireActual('react-router-dom'),
|
|
14
|
+
generatePath: mockGeneratePath,
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
jest.mock('lodash/debounce', () => jest.fn(i => i));
|
|
18
|
+
jest.mock('lodash/uniqueId', () => () => 'uniqueId');
|
|
19
|
+
|
|
20
|
+
jest.mock('../activity-feed', () => {
|
|
21
|
+
return jest.fn(() => <div data-testid="activity-feed-mock">Activity Feed Mock</div>);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
jest.mock('../SidebarContent', () => {
|
|
25
|
+
return jest.fn(({ children, actions, className, elementId, sidebarView, title }) => (
|
|
26
|
+
<div
|
|
27
|
+
data-testid="sidebar-content-mock"
|
|
28
|
+
className={className}
|
|
29
|
+
data-element-id={elementId}
|
|
30
|
+
data-sidebar-view={sidebarView}
|
|
31
|
+
>
|
|
32
|
+
<div data-testid="sidebar-title">{title}</div>
|
|
33
|
+
<div data-testid="sidebar-actions">{actions}</div>
|
|
34
|
+
<div data-testid="sidebar-children">{children}</div>
|
|
35
|
+
</div>
|
|
36
|
+
));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('elements/content-sidebar/ActivitySidebar', () => {
|
|
40
|
+
const feedAPI = {
|
|
41
|
+
createComment: jest.fn(),
|
|
42
|
+
createReply: jest.fn(),
|
|
43
|
+
createTaskNew: jest.fn(),
|
|
44
|
+
createThreadedComment: jest.fn(),
|
|
45
|
+
deleteAnnotation: jest.fn(),
|
|
46
|
+
deleteComment: jest.fn(),
|
|
47
|
+
deleteReply: jest.fn(),
|
|
48
|
+
deleteTaskNew: jest.fn(),
|
|
49
|
+
deleteThreadedComment: jest.fn(),
|
|
50
|
+
feedItems: jest.fn(),
|
|
51
|
+
fetchReplies: jest.fn(),
|
|
52
|
+
fetchThreadedComment: jest.fn(),
|
|
53
|
+
updateAnnotation: jest.fn(),
|
|
54
|
+
updateComment: jest.fn(),
|
|
55
|
+
updateFeedItem: jest.fn(),
|
|
56
|
+
updateReply: jest.fn(),
|
|
57
|
+
updateTaskCollaborator: jest.fn(),
|
|
58
|
+
updateTaskNew: jest.fn(),
|
|
59
|
+
updateThreadedComment: jest.fn(),
|
|
60
|
+
};
|
|
61
|
+
const usersAPI = {
|
|
62
|
+
get: jest.fn(),
|
|
63
|
+
getAvatarUrlWithAccessToken: jest.fn().mockResolvedValue('foo'),
|
|
64
|
+
getUser: jest.fn(),
|
|
65
|
+
};
|
|
66
|
+
const fileCollaboratorsAPI = {
|
|
67
|
+
getCollaboratorsWithQuery: jest.fn(),
|
|
68
|
+
};
|
|
69
|
+
const api = {
|
|
70
|
+
getUsersAPI: () => usersAPI,
|
|
71
|
+
getFeedAPI: () => feedAPI,
|
|
72
|
+
getFileCollaboratorsAPI: () => fileCollaboratorsAPI,
|
|
73
|
+
};
|
|
74
|
+
const file = {
|
|
75
|
+
id: 'I_AM_A_FILE',
|
|
76
|
+
file_version: {
|
|
77
|
+
id: '123',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
const currentUser = {
|
|
81
|
+
id: '123',
|
|
82
|
+
name: 'foo bar',
|
|
83
|
+
};
|
|
84
|
+
const onError = jest.fn();
|
|
85
|
+
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
jest.clearAllMocks();
|
|
88
|
+
mockGeneratePath.mockClear();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const renderActivitySidebar = (props = {}) => {
|
|
92
|
+
const defaultProps = {
|
|
93
|
+
api,
|
|
94
|
+
currentUser,
|
|
95
|
+
file,
|
|
96
|
+
logger: { onReadyMetric: jest.fn(), onDataReadyMetric: jest.fn() },
|
|
97
|
+
onError,
|
|
98
|
+
...props,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return render(
|
|
102
|
+
<MemoryRouter initialEntries={['/activity']}>
|
|
103
|
+
<ActivitySidebarComponent {...defaultProps} />
|
|
104
|
+
</MemoryRouter>,
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
describe('handleAnnotationSelect()', () => {
|
|
109
|
+
let emitActiveAnnotationChangeEvent;
|
|
110
|
+
let getAnnotationsMatchPath;
|
|
111
|
+
let getAnnotationsPath;
|
|
112
|
+
let history;
|
|
113
|
+
let onAnnotationSelect;
|
|
114
|
+
let annotation;
|
|
115
|
+
|
|
116
|
+
beforeEach(() => {
|
|
117
|
+
emitActiveAnnotationChangeEvent = jest.fn();
|
|
118
|
+
getAnnotationsMatchPath = jest.fn().mockReturnValue({ params: { fileVersionId: '456' } });
|
|
119
|
+
getAnnotationsPath = jest.fn().mockReturnValue('/activity/annotations/235/124');
|
|
120
|
+
history = { push: jest.fn(), replace: jest.fn() };
|
|
121
|
+
onAnnotationSelect = jest.fn();
|
|
122
|
+
annotation = { file_version: { id: '235' }, id: '124' };
|
|
123
|
+
|
|
124
|
+
feedAPI.feedItems = jest
|
|
125
|
+
.fn()
|
|
126
|
+
.mockImplementationOnce((_, __, callback) => callback([]))
|
|
127
|
+
.mockImplementation(() => {});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('should call emitActiveAnnotationChangeEvent and onAnnotationSelect appropriately', () => {
|
|
131
|
+
ActivityFeed.mockImplementation(({ onAnnotationSelect: onAnnotationSelectProp }) => {
|
|
132
|
+
if (onAnnotationSelectProp) {
|
|
133
|
+
onAnnotationSelectProp(annotation);
|
|
134
|
+
}
|
|
135
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
renderActivitySidebar({
|
|
139
|
+
emitActiveAnnotationChangeEvent,
|
|
140
|
+
getAnnotationsMatchPath,
|
|
141
|
+
getAnnotationsPath,
|
|
142
|
+
history,
|
|
143
|
+
onAnnotationSelect,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
expect(emitActiveAnnotationChangeEvent).toHaveBeenCalledWith('124');
|
|
147
|
+
expect(history.push).toHaveBeenCalledWith('/activity/annotations/235/124');
|
|
148
|
+
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('should not call history.push if file versions are the same', () => {
|
|
152
|
+
getAnnotationsPath.mockReturnValue('/activity/annotations/456/124');
|
|
153
|
+
annotation = { file_version: { id: '456' }, id: '124' };
|
|
154
|
+
|
|
155
|
+
ActivityFeed.mockImplementation(({ onAnnotationSelect: onAnnotationSelectProp }) => {
|
|
156
|
+
if (onAnnotationSelectProp) {
|
|
157
|
+
onAnnotationSelectProp(annotation);
|
|
158
|
+
}
|
|
159
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
renderActivitySidebar({
|
|
163
|
+
emitActiveAnnotationChangeEvent,
|
|
164
|
+
getAnnotationsMatchPath,
|
|
165
|
+
getAnnotationsPath,
|
|
166
|
+
history,
|
|
167
|
+
onAnnotationSelect,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(emitActiveAnnotationChangeEvent).toHaveBeenCalledWith('124');
|
|
171
|
+
expect(history.push).not.toHaveBeenCalled();
|
|
172
|
+
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('should use current file version if match params returns null', () => {
|
|
176
|
+
getAnnotationsMatchPath.mockReturnValue({ params: { fileVersionId: undefined } });
|
|
177
|
+
|
|
178
|
+
ActivityFeed.mockImplementation(({ onAnnotationSelect: onAnnotationSelectProp }) => {
|
|
179
|
+
if (onAnnotationSelectProp) {
|
|
180
|
+
onAnnotationSelectProp(annotation);
|
|
181
|
+
}
|
|
182
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
renderActivitySidebar({
|
|
186
|
+
emitActiveAnnotationChangeEvent,
|
|
187
|
+
getAnnotationsMatchPath,
|
|
188
|
+
getAnnotationsPath,
|
|
189
|
+
history,
|
|
190
|
+
onAnnotationSelect,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
expect(emitActiveAnnotationChangeEvent).toHaveBeenCalledWith('124');
|
|
194
|
+
expect(history.push).toHaveBeenCalledWith('/activity/annotations/235/124');
|
|
195
|
+
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('should not call history.push if no file version id on the annotation', () => {
|
|
199
|
+
getAnnotationsMatchPath.mockReturnValue({ params: { fileVersionId: undefined } });
|
|
200
|
+
getAnnotationsPath.mockReturnValue('/activity/annotations/null/124');
|
|
201
|
+
annotation = { file_version: null, id: '124' };
|
|
202
|
+
|
|
203
|
+
ActivityFeed.mockImplementation(({ onAnnotationSelect: onAnnotationSelectProp }) => {
|
|
204
|
+
if (onAnnotationSelectProp) {
|
|
205
|
+
onAnnotationSelectProp(annotation);
|
|
206
|
+
}
|
|
207
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
renderActivitySidebar({
|
|
211
|
+
emitActiveAnnotationChangeEvent,
|
|
212
|
+
getAnnotationsMatchPath,
|
|
213
|
+
getAnnotationsPath,
|
|
214
|
+
history,
|
|
215
|
+
onAnnotationSelect,
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
expect(emitActiveAnnotationChangeEvent).toHaveBeenCalledWith('124');
|
|
219
|
+
expect(history.push).not.toHaveBeenCalled();
|
|
220
|
+
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe('handleAnnotationSelect() - Router Disabled', () => {
|
|
225
|
+
let emitActiveAnnotationChangeEvent;
|
|
226
|
+
let getAnnotationsMatchPath;
|
|
227
|
+
let getAnnotationsPath;
|
|
228
|
+
let internalSidebarNavigationHandler;
|
|
229
|
+
let onAnnotationSelect;
|
|
230
|
+
let annotation;
|
|
231
|
+
|
|
232
|
+
beforeEach(() => {
|
|
233
|
+
emitActiveAnnotationChangeEvent = jest.fn();
|
|
234
|
+
getAnnotationsMatchPath = jest.fn().mockReturnValue({ params: { fileVersionId: '456' } });
|
|
235
|
+
getAnnotationsPath = jest.fn().mockReturnValue('/activity/annotations/235/124');
|
|
236
|
+
internalSidebarNavigationHandler = jest.fn();
|
|
237
|
+
onAnnotationSelect = jest.fn();
|
|
238
|
+
annotation = { file_version: { id: '235' }, id: '124' };
|
|
239
|
+
|
|
240
|
+
feedAPI.feedItems = jest
|
|
241
|
+
.fn()
|
|
242
|
+
.mockImplementationOnce((_, __, callback) => callback([]))
|
|
243
|
+
.mockImplementation(() => {});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('should call emitActiveAnnotationChangeEvent and onAnnotationSelect appropriately', () => {
|
|
247
|
+
ActivityFeed.mockImplementation(({ onAnnotationSelect: onAnnotationSelectProp }) => {
|
|
248
|
+
if (onAnnotationSelectProp) {
|
|
249
|
+
onAnnotationSelectProp(annotation);
|
|
250
|
+
}
|
|
251
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
renderActivitySidebar({
|
|
255
|
+
routerDisabled: true,
|
|
256
|
+
internalSidebarNavigationHandler,
|
|
257
|
+
emitActiveAnnotationChangeEvent,
|
|
258
|
+
getAnnotationsMatchPath,
|
|
259
|
+
getAnnotationsPath,
|
|
260
|
+
onAnnotationSelect,
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
expect(emitActiveAnnotationChangeEvent).toHaveBeenCalledWith('124');
|
|
264
|
+
expect(internalSidebarNavigationHandler).toHaveBeenCalledWith({
|
|
265
|
+
sidebar: ViewType.ACTIVITY,
|
|
266
|
+
activeFeedEntryType: FeedEntryType.ANNOTATIONS,
|
|
267
|
+
activeFeedEntryId: '124',
|
|
268
|
+
fileVersionId: '235',
|
|
269
|
+
});
|
|
270
|
+
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test('should not call internalSidebarNavigationHandler if file versions are the same', () => {
|
|
274
|
+
getAnnotationsPath.mockReturnValue('/activity/annotations/456/124');
|
|
275
|
+
annotation = { file_version: { id: '456' }, id: '124' };
|
|
276
|
+
|
|
277
|
+
ActivityFeed.mockImplementation(({ onAnnotationSelect: onAnnotationSelectProp }) => {
|
|
278
|
+
if (onAnnotationSelectProp) {
|
|
279
|
+
onAnnotationSelectProp(annotation);
|
|
280
|
+
}
|
|
281
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
renderActivitySidebar({
|
|
285
|
+
routerDisabled: true,
|
|
286
|
+
internalSidebarNavigationHandler,
|
|
287
|
+
emitActiveAnnotationChangeEvent,
|
|
288
|
+
getAnnotationsMatchPath,
|
|
289
|
+
getAnnotationsPath,
|
|
290
|
+
onAnnotationSelect,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
expect(emitActiveAnnotationChangeEvent).toHaveBeenCalledWith('124');
|
|
294
|
+
expect(internalSidebarNavigationHandler).not.toHaveBeenCalled();
|
|
295
|
+
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test('should use current file version if match params returns null', () => {
|
|
299
|
+
getAnnotationsMatchPath.mockReturnValue({ params: { fileVersionId: undefined } });
|
|
300
|
+
|
|
301
|
+
ActivityFeed.mockImplementation(({ onAnnotationSelect: onAnnotationSelectProp }) => {
|
|
302
|
+
if (onAnnotationSelectProp) {
|
|
303
|
+
onAnnotationSelectProp(annotation);
|
|
304
|
+
}
|
|
305
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
renderActivitySidebar({
|
|
309
|
+
routerDisabled: true,
|
|
310
|
+
internalSidebarNavigationHandler,
|
|
311
|
+
emitActiveAnnotationChangeEvent,
|
|
312
|
+
getAnnotationsMatchPath,
|
|
313
|
+
getAnnotationsPath,
|
|
314
|
+
onAnnotationSelect,
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
expect(emitActiveAnnotationChangeEvent).toHaveBeenCalledWith('124');
|
|
318
|
+
expect(internalSidebarNavigationHandler).toHaveBeenCalledWith({
|
|
319
|
+
sidebar: ViewType.ACTIVITY,
|
|
320
|
+
activeFeedEntryType: FeedEntryType.ANNOTATIONS,
|
|
321
|
+
activeFeedEntryId: '124',
|
|
322
|
+
fileVersionId: '235',
|
|
323
|
+
});
|
|
324
|
+
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test('should not call internalSidebarNavigationHandler if no file version id on the annotation', () => {
|
|
328
|
+
getAnnotationsMatchPath.mockReturnValue({ params: { fileVersionId: undefined } });
|
|
329
|
+
getAnnotationsPath.mockReturnValue('/activity/annotations/null/124');
|
|
330
|
+
annotation = { file_version: null, id: '124' };
|
|
331
|
+
|
|
332
|
+
ActivityFeed.mockImplementation(({ onAnnotationSelect: onAnnotationSelectProp }) => {
|
|
333
|
+
if (onAnnotationSelectProp) {
|
|
334
|
+
onAnnotationSelectProp(annotation);
|
|
335
|
+
}
|
|
336
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
renderActivitySidebar({
|
|
340
|
+
routerDisabled: true,
|
|
341
|
+
internalSidebarNavigationHandler,
|
|
342
|
+
emitActiveAnnotationChangeEvent,
|
|
343
|
+
getAnnotationsMatchPath,
|
|
344
|
+
getAnnotationsPath,
|
|
345
|
+
onAnnotationSelect,
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
expect(emitActiveAnnotationChangeEvent).toHaveBeenCalledWith('124');
|
|
349
|
+
expect(internalSidebarNavigationHandler).not.toHaveBeenCalled();
|
|
350
|
+
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
describe('updateReplies()', () => {
|
|
355
|
+
test('should call updateFeedItem API', () => {
|
|
356
|
+
const id = '123';
|
|
357
|
+
const replies = cloneDeep(formattedReplies);
|
|
358
|
+
|
|
359
|
+
ActivityFeed.mockImplementation(({ onHideReplies }) => {
|
|
360
|
+
if (onHideReplies) {
|
|
361
|
+
onHideReplies(id, replies);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
feedAPI.feedItems = jest
|
|
368
|
+
.fn()
|
|
369
|
+
.mockImplementationOnce((_, __, callback) => callback(['test']))
|
|
370
|
+
.mockImplementation(() => {});
|
|
371
|
+
|
|
372
|
+
renderActivitySidebar();
|
|
373
|
+
|
|
374
|
+
expect(feedAPI.updateFeedItem).toHaveBeenCalledWith({ replies }, id);
|
|
375
|
+
expect(feedAPI.feedItems).toHaveBeenCalled();
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test('should disable active item if replies are being hidden and activeFeedEntryId belongs to a reply that is in currently being updated parent', () => {
|
|
379
|
+
const historyReplace = jest.fn();
|
|
380
|
+
const activeReplyId = '123';
|
|
381
|
+
const itemId = '999';
|
|
382
|
+
const lastReplyId = '456';
|
|
383
|
+
const replies = [{ id: lastReplyId }];
|
|
384
|
+
|
|
385
|
+
mockGeneratePath.mockReturnValue('/activity');
|
|
386
|
+
|
|
387
|
+
feedAPI.feedItems = jest
|
|
388
|
+
.fn()
|
|
389
|
+
.mockImplementationOnce((_, __, callback) =>
|
|
390
|
+
callback([{ id: itemId, replies: [{ id: activeReplyId }, { id: lastReplyId }], type: 'comment' }]),
|
|
391
|
+
)
|
|
392
|
+
.mockImplementation(() => {});
|
|
393
|
+
|
|
394
|
+
ActivityFeed.mockImplementation(({ onHideReplies }) => {
|
|
395
|
+
if (onHideReplies) {
|
|
396
|
+
onHideReplies(itemId, replies);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
renderActivitySidebar({
|
|
403
|
+
activeFeedEntryId: activeReplyId,
|
|
404
|
+
history: { replace: historyReplace },
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
expect(historyReplace).toHaveBeenCalledWith('/activity');
|
|
408
|
+
expect(feedAPI.updateFeedItem).toHaveBeenCalledWith({ replies }, itemId);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test('should call generatePath when getActiveCommentPath is called with commentId', () => {
|
|
412
|
+
const historyReplace = jest.fn();
|
|
413
|
+
const activeReplyId = '123';
|
|
414
|
+
const itemId = '999';
|
|
415
|
+
const lastReplyId = '456';
|
|
416
|
+
const replies = [{ id: lastReplyId }];
|
|
417
|
+
|
|
418
|
+
mockGeneratePath.mockReturnValue('/activity/comments/123');
|
|
419
|
+
|
|
420
|
+
feedAPI.feedItems = jest
|
|
421
|
+
.fn()
|
|
422
|
+
.mockImplementationOnce((_, __, callback) =>
|
|
423
|
+
callback([
|
|
424
|
+
{ id: activeReplyId, type: 'comment' },
|
|
425
|
+
{ id: itemId, replies: [{ id: lastReplyId }], type: 'comment' },
|
|
426
|
+
]),
|
|
427
|
+
)
|
|
428
|
+
.mockImplementation(() => {});
|
|
429
|
+
|
|
430
|
+
ActivityFeed.mockImplementation(({ onHideReplies }) => {
|
|
431
|
+
if (onHideReplies) {
|
|
432
|
+
onHideReplies(itemId, replies);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
renderActivitySidebar({
|
|
439
|
+
activeFeedEntryId: activeReplyId,
|
|
440
|
+
history: { replace: historyReplace },
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
expect(historyReplace).not.toHaveBeenCalled();
|
|
444
|
+
expect(mockGeneratePath).not.toHaveBeenCalled();
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
describe('updateReplies() - Router Disabled', () => {
|
|
449
|
+
test('should disable active item if replies are being hidden and activeFeedEntryId belongs to a reply that is in currently being updated parent', () => {
|
|
450
|
+
const internalSidebarNavigationHandler = jest.fn();
|
|
451
|
+
const activeReplyId = '123';
|
|
452
|
+
const itemId = '999';
|
|
453
|
+
const lastReplyId = '456';
|
|
454
|
+
const replies = [{ id: lastReplyId }];
|
|
455
|
+
|
|
456
|
+
feedAPI.feedItems = jest
|
|
457
|
+
.fn()
|
|
458
|
+
.mockImplementationOnce((_, __, callback) =>
|
|
459
|
+
callback([{ id: itemId, replies: [{ id: activeReplyId }, { id: lastReplyId }], type: 'comment' }]),
|
|
460
|
+
)
|
|
461
|
+
.mockImplementation(() => {});
|
|
462
|
+
|
|
463
|
+
ActivityFeed.mockImplementation(({ onHideReplies }) => {
|
|
464
|
+
if (onHideReplies) {
|
|
465
|
+
onHideReplies(itemId, replies);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
renderActivitySidebar({
|
|
472
|
+
routerDisabled: true,
|
|
473
|
+
internalSidebarNavigationHandler,
|
|
474
|
+
activeFeedEntryId: activeReplyId,
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
expect(internalSidebarNavigationHandler).toHaveBeenCalledWith(
|
|
478
|
+
{
|
|
479
|
+
sidebar: ViewType.ACTIVITY,
|
|
480
|
+
},
|
|
481
|
+
true,
|
|
482
|
+
);
|
|
483
|
+
expect(feedAPI.updateFeedItem).toHaveBeenCalledWith({ replies }, itemId);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
test('should not call internalSidebarNavigationHandler when activeReplyId is not being removed', () => {
|
|
487
|
+
const internalSidebarNavigationHandler = jest.fn();
|
|
488
|
+
const activeReplyId = '123';
|
|
489
|
+
const itemId = '999';
|
|
490
|
+
const lastReplyId = '456';
|
|
491
|
+
const replies = [{ id: lastReplyId }];
|
|
492
|
+
|
|
493
|
+
feedAPI.feedItems = jest
|
|
494
|
+
.fn()
|
|
495
|
+
.mockImplementationOnce((_, __, callback) =>
|
|
496
|
+
callback([
|
|
497
|
+
{ id: activeReplyId, type: 'comment' },
|
|
498
|
+
{ id: itemId, replies: [{ id: lastReplyId }], type: 'comment' },
|
|
499
|
+
]),
|
|
500
|
+
)
|
|
501
|
+
.mockImplementation(() => {});
|
|
502
|
+
|
|
503
|
+
ActivityFeed.mockImplementation(({ onHideReplies }) => {
|
|
504
|
+
if (onHideReplies) {
|
|
505
|
+
onHideReplies(itemId, replies);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return <div data-testid="activity-feed-mock">Activity Feed Mock</div>;
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
renderActivitySidebar({
|
|
512
|
+
routerDisabled: true,
|
|
513
|
+
internalSidebarNavigationHandler,
|
|
514
|
+
activeFeedEntryId: activeReplyId,
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
expect(internalSidebarNavigationHandler).not.toHaveBeenCalled();
|
|
518
|
+
expect(feedAPI.updateFeedItem).toHaveBeenCalledWith({ replies }, itemId);
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
});
|
|
@@ -3,15 +3,12 @@ import { shallow, mount } from 'enzyme';
|
|
|
3
3
|
import cloneDeep from 'lodash/cloneDeep';
|
|
4
4
|
import { ActivitySidebarComponent, activityFeedInlineError } from '../ActivitySidebar';
|
|
5
5
|
import ActivitySidebarFilter from '../ActivitySidebarFilter';
|
|
6
|
-
import { filterableActivityFeedItems
|
|
6
|
+
import { filterableActivityFeedItems } from '../fixtures';
|
|
7
7
|
import { FEED_ITEM_TYPE_COMMENT } from '../../../constants';
|
|
8
8
|
|
|
9
9
|
jest.mock('lodash/debounce', () => jest.fn(i => i));
|
|
10
10
|
jest.mock('lodash/uniqueId', () => () => 'uniqueId');
|
|
11
11
|
|
|
12
|
-
// const mockReplace = jest.fn();
|
|
13
|
-
// jest.mock('lodash/uniqueId', () => () => 'uniqueId');
|
|
14
|
-
|
|
15
12
|
const userError = 'Bad box user!';
|
|
16
13
|
|
|
17
14
|
describe('elements/content-sidebar/ActivitySidebar', () => {
|
|
@@ -548,52 +545,6 @@ describe('elements/content-sidebar/ActivitySidebar', () => {
|
|
|
548
545
|
});
|
|
549
546
|
});
|
|
550
547
|
|
|
551
|
-
describe('updateReplies()', () => {
|
|
552
|
-
test('should call updateFeedItem API', () => {
|
|
553
|
-
const wrapper = getWrapper();
|
|
554
|
-
const instance = wrapper.instance();
|
|
555
|
-
|
|
556
|
-
wrapper.setState({
|
|
557
|
-
feedItems: [],
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
const id = '123';
|
|
561
|
-
const replies = cloneDeep(formattedReplies);
|
|
562
|
-
|
|
563
|
-
instance.fetchFeedItems = jest.fn();
|
|
564
|
-
|
|
565
|
-
instance.updateReplies(id, replies);
|
|
566
|
-
|
|
567
|
-
expect(api.getFeedAPI().updateFeedItem).toBeCalledWith({ replies }, id);
|
|
568
|
-
expect(instance.fetchFeedItems).toBeCalled();
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
test('should disable active item if replies are being hidden and activeFeedEntryId belongs to a reply that is in currently being updated parent', () => {
|
|
572
|
-
const historyReplace = jest.fn();
|
|
573
|
-
const activeReplyId = '123';
|
|
574
|
-
|
|
575
|
-
const wrapper = getWrapper({
|
|
576
|
-
activeFeedEntryId: activeReplyId,
|
|
577
|
-
history: { replace: historyReplace },
|
|
578
|
-
});
|
|
579
|
-
const instance = wrapper.instance();
|
|
580
|
-
instance.getActiveCommentPath = jest.fn();
|
|
581
|
-
|
|
582
|
-
const itemId = '999';
|
|
583
|
-
const lastReplyId = '456';
|
|
584
|
-
const replies = [{ id: lastReplyId }];
|
|
585
|
-
|
|
586
|
-
wrapper.setState({
|
|
587
|
-
feedItems: [{ id: itemId, replies: [{ id: activeReplyId }, { id: lastReplyId }], type: 'comment' }],
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
instance.updateReplies(itemId, replies);
|
|
591
|
-
|
|
592
|
-
expect(instance.getActiveCommentPath).toBeCalledWith();
|
|
593
|
-
expect(historyReplace).toBeCalled();
|
|
594
|
-
});
|
|
595
|
-
});
|
|
596
|
-
|
|
597
548
|
describe('fetchRepliesForFeedItems()', () => {
|
|
598
549
|
test('should not call getActiveFeedEntryData if activeFeedEntryId is not set', () => {
|
|
599
550
|
const wrapper = getWrapper();
|
|
@@ -1330,79 +1281,6 @@ describe('elements/content-sidebar/ActivitySidebar', () => {
|
|
|
1330
1281
|
});
|
|
1331
1282
|
});
|
|
1332
1283
|
|
|
1333
|
-
describe('handleAnnotationSelect()', () => {
|
|
1334
|
-
const annotatorState = { activeAnnotationId: '123' };
|
|
1335
|
-
const emitActiveAnnotationChangeEvent = jest.fn();
|
|
1336
|
-
const getAnnotationsMatchPath = jest.fn().mockReturnValue({ params: { fileVersionId: '456' } });
|
|
1337
|
-
const getAnnotationsPath = jest.fn().mockReturnValue('/activity/annotations/235/124');
|
|
1338
|
-
const history = {
|
|
1339
|
-
push: jest.fn(),
|
|
1340
|
-
replace: jest.fn(),
|
|
1341
|
-
};
|
|
1342
|
-
const onAnnotationSelect = jest.fn();
|
|
1343
|
-
|
|
1344
|
-
const getAnnotationWrapper = () =>
|
|
1345
|
-
getWrapper({
|
|
1346
|
-
annotatorState,
|
|
1347
|
-
emitActiveAnnotationChangeEvent,
|
|
1348
|
-
file,
|
|
1349
|
-
getAnnotationsMatchPath,
|
|
1350
|
-
getAnnotationsPath,
|
|
1351
|
-
history,
|
|
1352
|
-
onAnnotationSelect,
|
|
1353
|
-
});
|
|
1354
|
-
|
|
1355
|
-
test('should call emitAnnotatorActiveChangeEvent and onAnnotatorSelect appropriately', () => {
|
|
1356
|
-
const wrapper = getAnnotationWrapper();
|
|
1357
|
-
const instance = wrapper.instance();
|
|
1358
|
-
const annotation = { file_version: { id: '235' }, id: '124' };
|
|
1359
|
-
|
|
1360
|
-
instance.handleAnnotationSelect(annotation);
|
|
1361
|
-
|
|
1362
|
-
expect(emitActiveAnnotationChangeEvent).toBeCalledWith('124');
|
|
1363
|
-
expect(history.push).toHaveBeenCalledWith('/activity/annotations/235/124');
|
|
1364
|
-
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
1365
|
-
});
|
|
1366
|
-
|
|
1367
|
-
test('should not call history.push if file versions are the same', () => {
|
|
1368
|
-
const wrapper = getAnnotationWrapper();
|
|
1369
|
-
const instance = wrapper.instance();
|
|
1370
|
-
const annotation = { file_version: { id: '456' }, id: '124' };
|
|
1371
|
-
|
|
1372
|
-
instance.handleAnnotationSelect(annotation);
|
|
1373
|
-
|
|
1374
|
-
expect(emitActiveAnnotationChangeEvent).toBeCalledWith('124');
|
|
1375
|
-
expect(history.push).not.toHaveBeenCalled();
|
|
1376
|
-
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
1377
|
-
});
|
|
1378
|
-
|
|
1379
|
-
test('should use current file version if match params returns null', () => {
|
|
1380
|
-
const wrapper = getAnnotationWrapper();
|
|
1381
|
-
const instance = wrapper.instance();
|
|
1382
|
-
const annotation = { file_version: { id: '235' }, id: '124' };
|
|
1383
|
-
getAnnotationsMatchPath.mockReturnValue({ params: { fileVersionId: undefined } });
|
|
1384
|
-
|
|
1385
|
-
instance.handleAnnotationSelect(annotation);
|
|
1386
|
-
|
|
1387
|
-
expect(emitActiveAnnotationChangeEvent).toBeCalledWith('124');
|
|
1388
|
-
expect(history.push).toHaveBeenCalledWith('/activity/annotations/235/124');
|
|
1389
|
-
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
1390
|
-
});
|
|
1391
|
-
|
|
1392
|
-
test('should not call history.push if no file version id on the annotation', () => {
|
|
1393
|
-
const wrapper = getAnnotationWrapper();
|
|
1394
|
-
const instance = wrapper.instance();
|
|
1395
|
-
const annotation = { file_version: null, id: '124' };
|
|
1396
|
-
getAnnotationsMatchPath.mockReturnValue({ params: { fileVersionId: undefined } });
|
|
1397
|
-
|
|
1398
|
-
instance.handleAnnotationSelect(annotation);
|
|
1399
|
-
|
|
1400
|
-
expect(emitActiveAnnotationChangeEvent).toBeCalledWith('124');
|
|
1401
|
-
expect(history.push).not.toHaveBeenCalled();
|
|
1402
|
-
expect(onAnnotationSelect).toHaveBeenCalledWith(annotation);
|
|
1403
|
-
});
|
|
1404
|
-
});
|
|
1405
|
-
|
|
1406
1284
|
describe('handleAnnotationEdit()', () => {
|
|
1407
1285
|
test('should call updateAnnotation API and call emitAnnotationUpdateEvent', () => {
|
|
1408
1286
|
const mockEmitAnnotationUpdateEvent = jest.fn();
|