box-ui-elements 23.4.0-beta.36 → 23.4.0-beta.37

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.
Files changed (69) hide show
  1. package/dist/explorer.js +1 -1
  2. package/dist/preview.js +1 -1
  3. package/dist/sidebar.js +1 -1
  4. package/es/elements/content-preview/PreviewNavigation.js +0 -2
  5. package/es/elements/content-preview/PreviewNavigation.js.flow +0 -2
  6. package/es/elements/content-preview/PreviewNavigation.js.map +1 -1
  7. package/es/elements/content-sidebar/versions/VersionsSidebarContainer.js +29 -7
  8. package/es/elements/content-sidebar/versions/VersionsSidebarContainer.js.flow +44 -5
  9. package/es/elements/content-sidebar/versions/VersionsSidebarContainer.js.map +1 -1
  10. package/es/elements/content-sidebar/withSidebarAnnotations.js +141 -35
  11. package/es/elements/content-sidebar/withSidebarAnnotations.js.flow +199 -37
  12. package/es/elements/content-sidebar/withSidebarAnnotations.js.map +1 -1
  13. package/i18n/bn-IN.js +1 -1
  14. package/i18n/bn-IN.properties +4 -0
  15. package/i18n/da-DK.js +1 -1
  16. package/i18n/da-DK.properties +4 -0
  17. package/i18n/de-DE.js +1 -1
  18. package/i18n/de-DE.properties +4 -0
  19. package/i18n/en-AU.js +1 -1
  20. package/i18n/en-AU.properties +4 -0
  21. package/i18n/en-CA.js +1 -1
  22. package/i18n/en-CA.properties +4 -0
  23. package/i18n/en-GB.js +1 -1
  24. package/i18n/en-GB.properties +4 -0
  25. package/i18n/es-419.js +1 -1
  26. package/i18n/es-419.properties +4 -0
  27. package/i18n/es-ES.js +1 -1
  28. package/i18n/es-ES.properties +4 -0
  29. package/i18n/fi-FI.js +1 -1
  30. package/i18n/fi-FI.properties +4 -0
  31. package/i18n/fr-CA.js +1 -1
  32. package/i18n/fr-CA.properties +4 -0
  33. package/i18n/fr-FR.js +1 -1
  34. package/i18n/fr-FR.properties +4 -0
  35. package/i18n/hi-IN.js +1 -1
  36. package/i18n/hi-IN.properties +4 -0
  37. package/i18n/it-IT.js +1 -1
  38. package/i18n/it-IT.properties +4 -0
  39. package/i18n/ja-JP.js +1 -1
  40. package/i18n/ja-JP.properties +4 -0
  41. package/i18n/ko-KR.js +1 -1
  42. package/i18n/ko-KR.properties +4 -0
  43. package/i18n/nb-NO.js +1 -1
  44. package/i18n/nb-NO.properties +4 -0
  45. package/i18n/nl-NL.js +1 -1
  46. package/i18n/nl-NL.properties +4 -0
  47. package/i18n/pl-PL.js +1 -1
  48. package/i18n/pl-PL.properties +4 -0
  49. package/i18n/pt-BR.js +1 -1
  50. package/i18n/pt-BR.properties +4 -0
  51. package/i18n/ru-RU.js +1 -1
  52. package/i18n/ru-RU.properties +4 -0
  53. package/i18n/sv-SE.js +1 -1
  54. package/i18n/sv-SE.properties +4 -0
  55. package/i18n/tr-TR.js +1 -1
  56. package/i18n/tr-TR.properties +4 -0
  57. package/i18n/zh-CN.js +1 -1
  58. package/i18n/zh-CN.properties +4 -0
  59. package/i18n/zh-TW.js +1 -1
  60. package/i18n/zh-TW.properties +4 -0
  61. package/package.json +1 -1
  62. package/src/elements/content-preview/PreviewNavigation.js +0 -2
  63. package/src/elements/content-preview/__tests__/PreviewNavigation.test.js +12 -12
  64. package/src/elements/content-sidebar/__tests__/withSidebarAnnotations.rtl.test.js +1152 -0
  65. package/src/elements/content-sidebar/versions/VersionsSidebarContainer.js +44 -5
  66. package/src/elements/content-sidebar/versions/__tests__/VersionsSidebarContainer.test.js +200 -43
  67. package/src/elements/content-sidebar/versions/__tests__/__snapshots__/VersionsSidebarContainer.test.js.snap +2 -2
  68. package/src/elements/content-sidebar/withSidebarAnnotations.js +199 -37
  69. package/src/elements/content-sidebar/__tests__/withSidebarAnnotations.test.js +0 -626
@@ -1,626 +0,0 @@
1
- import * as React from 'react';
2
- import { shallow } from 'enzyme';
3
- import withSidebarAnnotations from '../withSidebarAnnotations';
4
- import { Action } from '../../common/annotator-context/types';
5
- import { FEED_ITEM_TYPE_VERSION } from '../../../constants';
6
-
7
- describe('elements/content-sidebar/withSidebarAnnotations', () => {
8
- const TestComponent = props => <div {...props} />;
9
- const WrappedComponent = withSidebarAnnotations(TestComponent);
10
-
11
- const annotatorContextProps = {
12
- getAnnotationsMatchPath: jest.fn(),
13
- getAnnotationsPath: jest.fn(),
14
- };
15
-
16
- const currentUser = {
17
- id: 'foo',
18
- };
19
-
20
- const file = {
21
- id: 'id',
22
- file_version: {
23
- id: '123',
24
- },
25
- };
26
-
27
- const feedAPI = {
28
- addAnnotation: jest.fn(),
29
- addPendingReply: jest.fn(),
30
- feedItems: jest.fn(),
31
- getCachedItems: jest.fn(),
32
- deleteAnnotation: jest.fn(),
33
- deleteFeedItem: jest.fn(),
34
- deleteReplyItem: jest.fn(),
35
- modifyFeedItemRepliesCountBy: jest.fn(),
36
- updateFeedItem: jest.fn(),
37
- updateReplyItem: jest.fn(),
38
- };
39
-
40
- const api = {
41
- getFeedAPI: () => feedAPI,
42
- };
43
-
44
- const defaultProps = { api, ...annotatorContextProps, file };
45
-
46
- const getWrapper = props => shallow(<WrappedComponent {...defaultProps} {...props} />);
47
-
48
- describe('constructor', () => {
49
- test('should call redirectDeeplinkedAnnotation', () => {
50
- getWrapper();
51
-
52
- expect(annotatorContextProps.getAnnotationsMatchPath).toHaveBeenCalledTimes(1);
53
- });
54
- });
55
-
56
- describe('componentDidUpdate', () => {
57
- test.each`
58
- prevFileVersionId | fileVersionId | expectedCallCount
59
- ${'122'} | ${'122'} | ${0}
60
- ${'122'} | ${undefined} | ${0}
61
- ${'122'} | ${'123'} | ${1}
62
- `(
63
- 'should call updateActiveVersion if fileVersionId changes',
64
- ({ prevFileVersionId, fileVersionId, expectedCallCount }) => {
65
- const match = { params: { fileVersionId } };
66
- const prevMatch = { params: { fileVersionId: prevFileVersionId } };
67
- const wrapper = getWrapper({ location: 'foo' });
68
- const instance = wrapper.instance();
69
-
70
- instance.updateActiveVersion = jest.fn();
71
- annotatorContextProps.getAnnotationsMatchPath.mockReturnValueOnce(match).mockReturnValueOnce(prevMatch);
72
-
73
- wrapper.setProps({ location: 'bar' });
74
- expect(instance.updateActiveVersion).toHaveBeenCalledTimes(expectedCallCount);
75
- },
76
- );
77
-
78
- test.each`
79
- condition | prevActiveAnnotationId | activeAnnotationId | isAnnotationsPath | expectedCount
80
- ${'annotation ids are the same'} | ${'123'} | ${'123'} | ${true} | ${0}
81
- ${'annotation ids are different'} | ${'123'} | ${'456'} | ${true} | ${1}
82
- ${'annotation deselected on annotations path'} | ${'123'} | ${null} | ${true} | ${1}
83
- ${'annotation deselected not on annotations path'} | ${'123'} | ${null} | ${false} | ${0}
84
- ${'annotation selected not on annotations path'} | ${null} | ${'123'} | ${false} | ${1}
85
- ${'annotation selected on annotations path'} | ${null} | ${'123'} | ${true} | ${1}
86
- `(
87
- 'should call updateActiveAnnotation $expectedCount times if $condition',
88
- ({ prevActiveAnnotationId, activeAnnotationId, isAnnotationsPath, expectedCount }) => {
89
- const wrapper = getWrapper({ annotatorState: { activeAnnotationId: prevActiveAnnotationId } });
90
- const instance = wrapper.instance();
91
-
92
- instance.updateActiveAnnotation = jest.fn();
93
- annotatorContextProps.getAnnotationsMatchPath.mockReturnValue(isAnnotationsPath);
94
-
95
- wrapper.setProps({ annotatorState: { activeAnnotationId, action: Action.SET_ACTIVE } });
96
-
97
- expect(instance.updateActiveAnnotation).toHaveBeenCalledTimes(expectedCount);
98
- },
99
- );
100
-
101
- test.each`
102
- annotation | expectedCount
103
- ${{}} | ${1}
104
- ${undefined} | ${0}
105
- ${null} | ${0}
106
- `(
107
- 'should call addAnnotation $expectedCount times if annotation changed to $annotation',
108
- ({ annotation, expectedCount }) => {
109
- const wrapper = getWrapper();
110
- wrapper.instance().addAnnotation = jest.fn();
111
- wrapper.setProps({ annotatorState: { annotation, action: Action.CREATE_END } });
112
-
113
- expect(wrapper.instance().addAnnotation).toHaveBeenCalledTimes(expectedCount);
114
- },
115
- );
116
-
117
- test.each`
118
- action
119
- ${Action.UPDATE_START}
120
- ${Action.UPDATE_END}
121
- `('should call updateAnnotation if given action = $action', ({ action }) => {
122
- const annotation = { id: '123', status: 'resolved' };
123
-
124
- const wrapper = getWrapper();
125
- const instance = wrapper.instance();
126
- instance.updateAnnotation = jest.fn();
127
- wrapper.setProps({ annotatorState: { annotation, action } });
128
- expect(instance.updateAnnotation).toBeCalled();
129
- });
130
-
131
- test.each`
132
- action
133
- ${Action.DELETE_START}
134
- ${Action.DELETE_END}
135
- `('should call deleteAnnotation if given action = $action', ({ action }) => {
136
- const annotation = { id: '123' };
137
-
138
- const wrapper = getWrapper();
139
- const instance = wrapper.instance();
140
- instance.deleteAnnotation = jest.fn();
141
- wrapper.setProps({ annotatorState: { annotation, action } });
142
- expect(instance.deleteAnnotation).toBeCalled();
143
- });
144
-
145
- test.each`
146
- action
147
- ${Action.REPLY_CREATE_START}
148
- ${Action.REPLY_CREATE_END}
149
- `('should call addAnnotationReply if given action = $action', ({ action }) => {
150
- const annotation = { id: '123' };
151
- const annotationReply = { id: '456', tagged_message: 'abc' };
152
-
153
- const wrapper = getWrapper();
154
- const instance = wrapper.instance();
155
- instance.addAnnotationReply = jest.fn();
156
- wrapper.setProps({ annotatorState: { action, annotation, annotationReply } });
157
- expect(instance.addAnnotationReply).toBeCalled();
158
- });
159
-
160
- test.each`
161
- action
162
- ${Action.REPLY_DELETE_START}
163
- ${Action.REPLY_DELETE_END}
164
- `('should call deleteAnnotationReply if given action = $action', ({ action }) => {
165
- const annotation = { id: '123' };
166
- const annotationReply = { id: '456' };
167
-
168
- const wrapper = getWrapper();
169
- const instance = wrapper.instance();
170
- instance.deleteAnnotationReply = jest.fn();
171
- wrapper.setProps({ annotatorState: { action, annotation, annotationReply } });
172
- expect(instance.deleteAnnotationReply).toBeCalled();
173
- });
174
-
175
- test.each`
176
- action
177
- ${Action.REPLY_UPDATE_START}
178
- ${Action.REPLY_UPDATE_END}
179
- `('should call updateAnnotationReply if given action = $action', ({ action }) => {
180
- const annotation = { id: '123' };
181
- const annotationReply = { id: '456', tagged_message: 'abc' };
182
-
183
- const wrapper = getWrapper();
184
- const instance = wrapper.instance();
185
- instance.updateAnnotationReply = jest.fn();
186
- wrapper.setProps({ annotatorState: { action, annotation, annotationReply } });
187
- expect(instance.updateAnnotationReply).toBeCalled();
188
- });
189
-
190
- test.each`
191
- fileId | expectedCount
192
- ${'123'} | ${0}
193
- ${'456'} | ${1}
194
- `('should call onVersionChange appropriately if file id changes to $fileId', ({ fileId, expectedCount }) => {
195
- const onVersionChange = jest.fn();
196
- const wrapper = getWrapper({ fileId: '123', onVersionChange });
197
-
198
- wrapper.setProps({ fileId });
199
-
200
- expect(onVersionChange).toHaveBeenCalledTimes(expectedCount);
201
- });
202
- });
203
-
204
- describe('redirectDeeplinkedAnnotation()', () => {
205
- const history = {
206
- replace: jest.fn(),
207
- };
208
- const getAnnotationsMatchPath = jest.fn();
209
- const getAnnotationsPath = jest.fn();
210
-
211
- beforeEach(() => {
212
- jest.resetAllMocks();
213
- });
214
-
215
- test.each`
216
- fileVersionId | annotationId | expectedCallCount
217
- ${undefined} | ${'987'} | ${0}
218
- ${'123'} | ${'987'} | ${0}
219
- ${'124'} | ${'987'} | ${1}
220
- ${'124'} | ${undefined} | ${1}
221
- `(
222
- 'should call history.replace appropriately if router location annotationId=$annotationId and fileVersionId=$fileVersionId',
223
- ({ annotationId, fileVersionId, expectedCallCount }) => {
224
- const wrapper = getWrapper({ file, getAnnotationsMatchPath, getAnnotationsPath, history });
225
- const instance = wrapper.instance();
226
- getAnnotationsMatchPath.mockReturnValue({ params: { annotationId, fileVersionId } });
227
-
228
- instance.redirectDeeplinkedAnnotation();
229
-
230
- expect(history.replace).toHaveBeenCalledTimes(expectedCallCount);
231
- },
232
- );
233
-
234
- test.each`
235
- fileVersionId | annotationId | expectedPath
236
- ${'124'} | ${'987'} | ${'/activity/annotations/123/987'}
237
- ${'124'} | ${undefined} | ${'/activity/annotations/123'}
238
- `('should call history.replace with $expectedPath', ({ fileVersionId, annotationId, expectedPath }) => {
239
- const wrapper = getWrapper({ file, getAnnotationsMatchPath, getAnnotationsPath, history });
240
- const instance = wrapper.instance();
241
- getAnnotationsMatchPath.mockReturnValue({ params: { annotationId, fileVersionId } });
242
- getAnnotationsPath.mockReturnValue(expectedPath);
243
-
244
- instance.redirectDeeplinkedAnnotation();
245
-
246
- expect(history.replace).toHaveBeenCalledWith(expectedPath);
247
- });
248
- });
249
-
250
- describe('addAnnotation()', () => {
251
- beforeEach(() => {
252
- annotatorContextProps.getAnnotationsMatchPath.mockReturnValueOnce({ params: { fileVersionId: '123' } });
253
- });
254
-
255
- test('should throw if no user', () => {
256
- const instance = getWrapper({ annotatorState: { meta: { requestId: '123' } } }).instance();
257
-
258
- expect(() => instance.addAnnotation()).toThrow('Bad box user!');
259
- });
260
-
261
- test('should do nothing if meta or requestId is not present', () => {
262
- const instance = getWrapper().instance();
263
-
264
- instance.addAnnotation();
265
-
266
- // Only call to getAnnotationsMatchPath comes in the constructor, the one in addAnnotation should not occur
267
- expect(annotatorContextProps.getAnnotationsMatchPath).toHaveBeenCalledTimes(1);
268
- });
269
-
270
- test.each`
271
- hasItems | expectedAddCount
272
- ${undefined} | ${0}
273
- ${[]} | ${1}
274
- `(
275
- 'should add the annotation to the feed cache accordingly if the cache items is $hasItems',
276
- ({ hasItems, expectedAddCount }) => {
277
- const annotatorStateMock = {
278
- meta: {
279
- requestId: '123',
280
- },
281
- };
282
-
283
- const wrapper = getWrapper({ annotatorState: annotatorStateMock, currentUser });
284
- const instance = wrapper.instance();
285
- feedAPI.getCachedItems.mockReturnValueOnce({ items: hasItems });
286
-
287
- instance.addAnnotation();
288
-
289
- expect(feedAPI.addAnnotation).toHaveBeenCalledTimes(expectedAddCount);
290
- },
291
- );
292
- });
293
-
294
- describe('addAnnotationReply()', () => {
295
- test('should add appropriate reply into the feed given action = reply_create_start', () => {
296
- const annotation = { id: '123' };
297
- const annotationReply = { tagged_message: 'abc' };
298
- const requestId = 'comment_456';
299
- const annotatorStateMock = {
300
- action: Action.REPLY_CREATE_START,
301
- annotation,
302
- annotationReply,
303
- meta: { requestId },
304
- };
305
-
306
- const wrapper = getWrapper({ annotatorState: annotatorStateMock, currentUser });
307
- const instance = wrapper.instance();
308
-
309
- instance.addAnnotationReply();
310
-
311
- const expectedReplyData = { ...annotationReply, id: requestId };
312
- expect(feedAPI.addPendingReply).toBeCalledWith(annotation.id, currentUser, expectedReplyData);
313
- });
314
-
315
- test('should update appropriate annotation and its reply in the feed given action = reply_create_end', () => {
316
- feedAPI.getCachedItems.mockReturnValueOnce({
317
- items: [
318
- {
319
- id: '123',
320
- replies: [{ id: 'comment_456', tagged_message: 'abc' }],
321
- total_reply_count: 2,
322
- },
323
- ],
324
- });
325
- const annotation = { id: '123' };
326
- const annotationReply = { id: '456', tagged_message: 'abc' };
327
- const requestId = 'comment_456';
328
- const annotatorStateMock = {
329
- action: Action.REPLY_CREATE_END,
330
- annotation,
331
- annotationReply,
332
- meta: { requestId },
333
- };
334
-
335
- const wrapper = getWrapper({ annotatorState: annotatorStateMock, currentUser });
336
- const instance = wrapper.instance();
337
-
338
- instance.addAnnotationReply();
339
-
340
- const expectedReplyData = { ...annotationReply, isPending: false };
341
- expect(feedAPI.modifyFeedItemRepliesCountBy).toBeCalledWith(annotation.id, 1);
342
- expect(feedAPI.updateReplyItem).toBeCalledWith(expectedReplyData, annotation.id, requestId);
343
- });
344
- });
345
-
346
- describe('deleteAnnotation()', () => {
347
- test('should change appropriate annotation to pending when action = delete_start', () => {
348
- const annotation = { id: '123' };
349
- const annotatorStateMock = {
350
- annotation,
351
- action: Action.DELETE_START,
352
- };
353
-
354
- const wrapper = getWrapper({ annotatorState: annotatorStateMock });
355
- const instance = wrapper.instance();
356
-
357
- instance.deleteAnnotation();
358
-
359
- expect(feedAPI.updateFeedItem).toBeCalledWith({ isPending: true }, annotation.id);
360
- });
361
-
362
- test('should remove appropriate annotation from feed when action = delete_end', () => {
363
- const annotation = { id: '123' };
364
- const annotatorStateMock = {
365
- annotation,
366
- action: Action.DELETE_END,
367
- };
368
-
369
- const wrapper = getWrapper({ annotatorState: annotatorStateMock });
370
- const instance = wrapper.instance();
371
-
372
- instance.deleteAnnotation();
373
-
374
- expect(feedAPI.deleteFeedItem).toBeCalledWith(annotation.id);
375
- });
376
- });
377
-
378
- describe('deleteAnnotationReply()', () => {
379
- test('should update appropriate reply in the feed given action = reply_delete_start', () => {
380
- const annotation = { id: '123' };
381
- const annotationReply = { id: '456' };
382
- const annotatorStateMock = {
383
- action: Action.REPLY_DELETE_START,
384
- annotation,
385
- annotationReply,
386
- };
387
-
388
- const wrapper = getWrapper({ annotatorState: annotatorStateMock });
389
- const instance = wrapper.instance();
390
-
391
- instance.deleteAnnotationReply();
392
-
393
- expect(feedAPI.updateReplyItem).toBeCalledWith({ isPending: true }, annotation.id, annotationReply.id);
394
- });
395
-
396
- test('should update appropriate annotation if reply is currently not in the feed given action = reply_delete_end', () => {
397
- feedAPI.getCachedItems.mockReturnValueOnce({
398
- items: [
399
- {
400
- id: '123',
401
- replies: [{ id: '999', tagged_message: 'abc' }],
402
- total_reply_count: 2,
403
- },
404
- ],
405
- });
406
- const annotation = { id: '123' };
407
- const annotationReply = { id: '456', tagged_message: 'abc' };
408
- const annotatorStateMock = {
409
- action: Action.REPLY_DELETE_END,
410
- annotation,
411
- annotationReply,
412
- };
413
-
414
- const wrapper = getWrapper({ annotatorState: annotatorStateMock });
415
- const instance = wrapper.instance();
416
-
417
- instance.deleteAnnotationReply();
418
-
419
- expect(feedAPI.modifyFeedItemRepliesCountBy).toBeCalledWith(annotation.id, -1);
420
- });
421
-
422
- test('should delete appropriate reply from the feed if it is currently in the feed given action = reply_delete_end', () => {
423
- feedAPI.getCachedItems.mockReturnValueOnce({
424
- items: [
425
- {
426
- id: '123',
427
- replies: [{ id: '456', tagged_message: 'abc' }],
428
- total_reply_count: 2,
429
- },
430
- ],
431
- });
432
- const annotation = { id: '123' };
433
- const annotationReply = { id: '456', tagged_message: 'abc' };
434
- const annotatorStateMock = {
435
- action: Action.REPLY_DELETE_END,
436
- annotation,
437
- annotationReply,
438
- };
439
-
440
- const wrapper = getWrapper({ annotatorState: annotatorStateMock });
441
- const instance = wrapper.instance();
442
-
443
- instance.deleteAnnotationReply();
444
-
445
- expect(feedAPI.deleteReplyItem).toBeCalledWith(annotationReply.id, annotation.id);
446
- expect(feedAPI.modifyFeedItemRepliesCountBy).toBeCalledWith(annotation.id, -1);
447
- });
448
- });
449
-
450
- describe('updateAnnotation()', () => {
451
- test.each`
452
- action | expectedIsPending
453
- ${Action.UPDATE_START} | ${true}
454
- ${Action.UPDATE_END} | ${false}
455
- `(
456
- 'should update appropriate annotation in the feed given action = $action',
457
- ({ action, expectedIsPending }) => {
458
- const annotation = { id: '123', status: 'resolved' };
459
- const annotatorStateMock = {
460
- annotation,
461
- action,
462
- };
463
-
464
- const wrapper = getWrapper({ annotatorState: annotatorStateMock });
465
- const instance = wrapper.instance();
466
-
467
- instance.updateAnnotation();
468
-
469
- const expectedAnnotationData = { ...annotation, isPending: expectedIsPending };
470
- expect(feedAPI.updateFeedItem).toBeCalledWith(expectedAnnotationData, annotation.id);
471
- },
472
- );
473
- });
474
-
475
- describe('updateAnnotationReply()', () => {
476
- test.each`
477
- action | expectedIsPending
478
- ${Action.REPLY_UPDATE_START} | ${true}
479
- ${Action.REPLY_UPDATE_END} | ${false}
480
- `('should update appropriate reply in the feed given action = $action', ({ action, expectedIsPending }) => {
481
- const annotation = { id: '123', status: 'resolved' };
482
- const annotationReply = { id: '456', tagged_message: 'abc' };
483
- const annotatorStateMock = {
484
- annotation,
485
- annotationReply,
486
- action,
487
- };
488
-
489
- const wrapper = getWrapper({ annotatorState: annotatorStateMock });
490
- const instance = wrapper.instance();
491
-
492
- instance.updateAnnotationReply();
493
-
494
- const expectedReplyData = { ...annotationReply, isPending: expectedIsPending };
495
- expect(feedAPI.updateReplyItem).toBeCalledWith(expectedReplyData, annotation.id, annotationReply.id);
496
- });
497
- });
498
-
499
- describe('updateActiveAnnotation()', () => {
500
- test.each`
501
- activeAnnotationId | fileVersionId | location | expectedPath | expectedState
502
- ${'234'} | ${'456'} | ${{ pathname: '/' }} | ${'/activity/annotations/456/234'} | ${{ open: true }}
503
- ${'234'} | ${undefined} | ${{ pathname: '/' }} | ${'/activity/annotations/123/234'} | ${{ open: true }}
504
- ${null} | ${'456'} | ${{ pathname: '/' }} | ${'/activity/annotations/456'} | ${undefined}
505
- ${null} | ${'456'} | ${{ pathname: '/', state: { foo: 'bar' } }} | ${'/activity/annotations/456'} | ${{ foo: 'bar' }}
506
- ${'234'} | ${'456'} | ${{ pathname: '/', state: { foo: 'bar' } }} | ${'/activity/annotations/456/234'} | ${{ open: true }}
507
- `(
508
- 'should set location path based on match param fileVersionId=$fileVersionId and activeAnnotationId=$activeAnnotationId',
509
- ({ activeAnnotationId, fileVersionId, location, expectedPath, expectedState }) => {
510
- annotatorContextProps.getAnnotationsMatchPath.mockReturnValue({ params: { fileVersionId } });
511
- annotatorContextProps.getAnnotationsPath.mockReturnValue(expectedPath);
512
-
513
- const annotatorState = {
514
- activeAnnotationId,
515
- };
516
- const history = { push: jest.fn(), replace: jest.fn() };
517
- const wrapper = getWrapper({ annotatorState, history, location });
518
- const instance = wrapper.instance();
519
-
520
- instance.updateActiveAnnotation();
521
-
522
- expect(history.push).toHaveBeenCalledWith({ pathname: expectedPath, state: expectedState });
523
- },
524
- );
525
-
526
- test('should use the provided fileVersionId in the annotatorState if provided', () => {
527
- const annotatorState = {
528
- activeAnnotationFileVersionId: '456',
529
- activeAnnotationId: '123',
530
- };
531
- const history = { push: jest.fn(), replace: jest.fn() };
532
- const wrapper = getWrapper({ annotatorState, history, location: { pathname: '/' } });
533
- const instance = wrapper.instance();
534
-
535
- instance.updateActiveAnnotation();
536
-
537
- expect(annotatorContextProps.getAnnotationsPath).toHaveBeenCalledWith('456', '123');
538
- });
539
-
540
- test('should fall back to the fileVersionId in the file if none other is provided', () => {
541
- const history = { push: jest.fn(), replace: jest.fn() };
542
- const wrapper = getWrapper({ history, location: { pathname: '/' } });
543
- const instance = wrapper.instance();
544
-
545
- instance.updateActiveAnnotation();
546
-
547
- expect(annotatorContextProps.getAnnotationsPath).toHaveBeenCalledWith('123', undefined);
548
- });
549
- });
550
-
551
- describe('updateActiveVersion()', () => {
552
- const onVersionChange = jest.fn();
553
- const version = { type: FEED_ITEM_TYPE_VERSION, id: '124' };
554
-
555
- beforeEach(() => {
556
- annotatorContextProps.getAnnotationsMatchPath.mockReturnValueOnce({ params: { fileVersionId: '123' } });
557
- });
558
-
559
- test.each`
560
- fileVersionId | expectedCallCount
561
- ${'123'} | ${0}
562
- ${'124'} | ${1}
563
- `(
564
- 'should onVersionChange $expectedCallCount times based on fileVersionId $fileVersionId',
565
- ({ fileVersionId, expectedCallCount }) => {
566
- const match = { params: { fileVersionId } };
567
- const wrapper = getWrapper({ file, onVersionChange });
568
- const instance = wrapper.instance();
569
- annotatorContextProps.getAnnotationsMatchPath.mockReturnValueOnce(match);
570
- feedAPI.getCachedItems.mockReturnValueOnce({ items: [version] });
571
-
572
- instance.updateActiveVersion();
573
-
574
- expect(onVersionChange).toHaveBeenCalledTimes(expectedCallCount);
575
- },
576
- );
577
- });
578
-
579
- describe('refreshActivitySidebar()', () => {
580
- const history = { replace: jest.fn() };
581
- const sidebarPanelsRef = { refresh: jest.fn() };
582
-
583
- test.each`
584
- pathname | isOpen | current | expectedCount
585
- ${'/'} | ${false} | ${null} | ${0}
586
- ${'/details'} | ${true} | ${null} | ${0}
587
- ${'/activity'} | ${false} | ${null} | ${0}
588
- ${'/activity'} | ${true} | ${null} | ${0}
589
- ${'/activity'} | ${false} | ${sidebarPanelsRef} | ${0}
590
- ${'/activity'} | ${true} | ${sidebarPanelsRef} | ${1}
591
- ${'/activity/versions/12345'} | ${true} | ${sidebarPanelsRef} | ${1}
592
- ${'/activity/versions/12345/67890'} | ${true} | ${sidebarPanelsRef} | ${1}
593
- ${'/details'} | ${true} | ${sidebarPanelsRef} | ${0}
594
- ${'/'} | ${true} | ${sidebarPanelsRef} | ${0}
595
- `(
596
- 'should refresh the sidebarPanels ref accordingly if pathname=$pathname, isOpen=$isOpen, current=$current',
597
- ({ current, expectedCount, isOpen, pathname }) => {
598
- const annotationUpdate = {
599
- id: '123',
600
- description: {
601
- message: 'text',
602
- },
603
- };
604
- const annotatorStateMock = {
605
- action: Action.UPDATE_END,
606
- annotation: annotationUpdate,
607
- };
608
- const wrapper = getWrapper({
609
- annotatorState: annotatorStateMock,
610
- currentUser,
611
- history,
612
- isOpen,
613
- location: { pathname },
614
- });
615
- const instance = wrapper.instance();
616
- instance.sidebarPanels = {
617
- current,
618
- };
619
-
620
- instance.updateAnnotation();
621
-
622
- expect(sidebarPanelsRef.refresh).toBeCalledTimes(expectedCount);
623
- },
624
- );
625
- });
626
- });