@reltio/components 1.4.2153 → 1.4.2155

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.
@@ -64,7 +64,7 @@ var react_hooks_1 = require("@testing-library/react-hooks");
64
64
  var mdm_sdk_1 = require("@reltio/mdm-sdk");
65
65
  var MdmModuleContext_1 = require("../../contexts/MdmModuleContext");
66
66
  var useCollaboration_1 = require("./useCollaboration");
67
- jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getCommentsCount: jest.fn(), getComment: jest.fn(), createComment: jest.fn(), createReply: jest.fn(), updateComment: jest.fn(), deleteComment: jest.fn(), getComments: jest.fn(), deleteReply: jest.fn(), updateReply: jest.fn() })); });
67
+ jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getCommentsCount: jest.fn(), getTotalCommentsCount: jest.fn(), getComment: jest.fn(), createComment: jest.fn(), createReply: jest.fn(), updateComment: jest.fn(), deleteComment: jest.fn(), getComments: jest.fn(), deleteReply: jest.fn(), updateReply: jest.fn() })); });
68
68
  describe('useCollaboration behaviour', function () {
69
69
  var defaultMdmValues = {
70
70
  uiPath: 'https://localhost:3000/ui/alenat',
@@ -82,28 +82,54 @@ describe('useCollaboration behaviour', function () {
82
82
  return (0, react_hooks_1.renderHook)(useCollaboration_1.useCollaboration, { initialProps: props, wrapper: Providers });
83
83
  };
84
84
  beforeEach(function () {
85
- jest.clearAllMocks();
86
85
  mdm_sdk_1.getComment.mockResolvedValue({ commentId: 'commentId' });
87
86
  mdm_sdk_1.getCommentsCount.mockResolvedValue([{ objectId: 'uri1', comments: [] }]);
87
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 1 });
88
+ });
89
+ afterEach(function () {
90
+ jest.resetAllMocks();
88
91
  });
89
92
  it('should not call getCommentsCount if collaboration is not enabled', function () {
90
93
  var mdmValues = __assign(__assign({}, defaultMdmValues), { collaborationPath: undefined, isCollaborationEnabled: false });
91
94
  var result = setUp({ mdmValues: mdmValues }).result;
92
95
  expect(result.current.commentsMap).toBe(null);
96
+ expect(result.current.totalCommentsCount).toBe(null);
93
97
  expect(mdm_sdk_1.getCommentsCount).not.toHaveBeenCalled();
98
+ expect(mdm_sdk_1.getTotalCommentsCount).not.toHaveBeenCalled();
94
99
  });
100
+ it('should not call getCommentsCount if totalCommentsCount is 0', function () { return __awaiter(void 0, void 0, void 0, function () {
101
+ var result;
102
+ return __generator(this, function (_a) {
103
+ switch (_a.label) {
104
+ case 0:
105
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 0 });
106
+ result = setUp().result;
107
+ return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
108
+ return __generator(this, function (_a) {
109
+ switch (_a.label) {
110
+ case 0: return [4 /*yield*/, Promise.resolve()];
111
+ case 1:
112
+ _a.sent();
113
+ return [2 /*return*/];
114
+ }
115
+ });
116
+ }); })];
117
+ case 1:
118
+ _a.sent();
119
+ expect(mdm_sdk_1.getCommentsCount).not.toHaveBeenCalled();
120
+ expect(result.current.commentsMap).toEqual({});
121
+ return [2 /*return*/];
122
+ }
123
+ });
124
+ }); });
95
125
  it('should call getCommentsCount if collaboration is enabled and uris is undefined and update commentsMap value', function () { return __awaiter(void 0, void 0, void 0, function () {
96
126
  var result;
97
127
  return __generator(this, function (_a) {
98
128
  switch (_a.label) {
99
129
  case 0:
100
130
  mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([]);
131
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 1 });
101
132
  result = setUp().result;
102
- expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
103
- uris: [],
104
- tenant: 'alenat',
105
- collaborationPath: defaultMdmValues.collaborationPath
106
- });
107
133
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
108
134
  return __generator(this, function (_a) {
109
135
  switch (_a.label) {
@@ -116,12 +142,17 @@ describe('useCollaboration behaviour', function () {
116
142
  }); })];
117
143
  case 1:
118
144
  _a.sent();
145
+ expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
146
+ uris: [],
147
+ tenant: 'alenat',
148
+ collaborationPath: defaultMdmValues.collaborationPath
149
+ });
119
150
  expect(result.current.commentsMap).toEqual({});
120
151
  return [2 /*return*/];
121
152
  }
122
153
  });
123
154
  }); });
124
- it('should call getCommentsCount if collaboration is enabled and update commentsMap value', function () { return __awaiter(void 0, void 0, void 0, function () {
155
+ it('should call getCommentsCount if collaboration is enabled and totalCommentsCount is more then 0 and update commentsMap value', function () { return __awaiter(void 0, void 0, void 0, function () {
125
156
  var comments, result;
126
157
  return __generator(this, function (_a) {
127
158
  switch (_a.label) {
@@ -131,12 +162,8 @@ describe('useCollaboration behaviour', function () {
131
162
  { commentId: 'id2', status: 'open', replies: 2 }
132
163
  ];
133
164
  mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: comments }]);
165
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 2 });
134
166
  result = setUp({ props: { objectIds: ['uri1'] } }).result;
135
- expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
136
- uris: ['uri1'],
137
- tenant: 'alenat',
138
- collaborationPath: defaultMdmValues.collaborationPath
139
- });
140
167
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
141
168
  return __generator(this, function (_a) {
142
169
  switch (_a.label) {
@@ -149,19 +176,24 @@ describe('useCollaboration behaviour', function () {
149
176
  }); })];
150
177
  case 1:
151
178
  _a.sent();
179
+ expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
180
+ uris: ['uri1'],
181
+ tenant: 'alenat',
182
+ collaborationPath: defaultMdmValues.collaborationPath
183
+ });
152
184
  expect(result.current.commentsMap).toEqual({ uri1: comments });
153
185
  return [2 /*return*/];
154
186
  }
155
187
  });
156
188
  }); });
157
- it('should set commentsMap value as null in case of unsuccessful request', function () { return __awaiter(void 0, void 0, void 0, function () {
189
+ it('should set commentsMap value as null in case of unsuccessful getCommentsCount request', function () { return __awaiter(void 0, void 0, void 0, function () {
158
190
  var result;
159
191
  return __generator(this, function (_a) {
160
192
  switch (_a.label) {
161
193
  case 0:
162
- mdm_sdk_1.getCommentsCount.mockRejectedValueOnce(null);
194
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 1 });
195
+ mdm_sdk_1.getCommentsCount.mockRejectedValueOnce(new Error('Fail'));
163
196
  result = setUp().result;
164
- expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalled();
165
197
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
166
198
  return __generator(this, function (_a) {
167
199
  switch (_a.label) {
@@ -174,6 +206,7 @@ describe('useCollaboration behaviour', function () {
174
206
  }); })];
175
207
  case 1:
176
208
  _a.sent();
209
+ expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalled();
177
210
  expect(result.current.commentsMap).toBe(null);
178
211
  return [2 /*return*/];
179
212
  }
@@ -195,7 +228,20 @@ describe('useCollaboration behaviour', function () {
195
228
  return Promise.resolve([{ objectId: 'uri2', comments: secondComments }]);
196
229
  }
197
230
  });
231
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 3 });
198
232
  result = setUp({ props: { objectIds: ['uri1'] } }).result;
233
+ return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
234
+ return __generator(this, function (_a) {
235
+ switch (_a.label) {
236
+ case 0: return [4 /*yield*/, Promise.resolve()];
237
+ case 1:
238
+ _a.sent();
239
+ return [2 /*return*/];
240
+ }
241
+ });
242
+ }); })];
243
+ case 1:
244
+ _a.sent();
199
245
  expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
200
246
  uris: ['uri1'],
201
247
  tenant: 'alenat',
@@ -207,7 +253,7 @@ describe('useCollaboration behaviour', function () {
207
253
  return [2 /*return*/];
208
254
  });
209
255
  }); })];
210
- case 1:
256
+ case 2:
211
257
  _a.sent();
212
258
  expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
213
259
  uris: ['uri2'],
@@ -235,7 +281,20 @@ describe('useCollaboration behaviour', function () {
235
281
  return Promise.resolve([{ objectId: 'uri2', comments: secondComments }]);
236
282
  }
237
283
  });
284
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 3 });
238
285
  _a = setUp({ props: { objectIds: ['uri1'] } }), result = _a.result, rerender = _a.rerender;
286
+ return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
287
+ return __generator(this, function (_a) {
288
+ switch (_a.label) {
289
+ case 0: return [4 /*yield*/, Promise.resolve()];
290
+ case 1:
291
+ _a.sent();
292
+ return [2 /*return*/];
293
+ }
294
+ });
295
+ }); })];
296
+ case 1:
297
+ _b.sent();
239
298
  expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
240
299
  uris: ['uri1'],
241
300
  tenant: 'alenat',
@@ -253,7 +312,7 @@ describe('useCollaboration behaviour', function () {
253
312
  }
254
313
  });
255
314
  }); })];
256
- case 1:
315
+ case 2:
257
316
  _b.sent();
258
317
  expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
259
318
  uris: ['uri2'],
@@ -390,7 +449,12 @@ describe('useCollaboration behaviour', function () {
390
449
  replies: 2
391
450
  }
392
451
  ];
393
- mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: comments }]);
452
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 3 });
453
+ mdm_sdk_1.getCommentsCount
454
+ .mockResolvedValueOnce([{ objectId: 'uri1', comments: comments }])
455
+ .mockResolvedValueOnce([
456
+ { objectId: 'uri1', comments: __spreadArray(__spreadArray([], comments, true), [{ commentId: 'commentId', replies: 0, status: 'open' }], false) }
457
+ ]);
394
458
  mdm_sdk_1.createComment.mockResolvedValueOnce([{ commentId: 'commentId' }]);
395
459
  result = setUp().result;
396
460
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -408,33 +472,16 @@ describe('useCollaboration behaviour', function () {
408
472
  expect(result.current.commentsMap).toEqual({ uri1: comments });
409
473
  expect(result.current.currentComment).toBe(null);
410
474
  expect(result.current.sending).toBe(false);
411
- (0, react_hooks_1.act)(function () {
412
- result.current.createComment({
413
- content: 'content',
414
- namedUsers: [],
415
- objectType: 'entity',
416
- relatedObjectUris: ['uri1'],
417
- uri: 'uri1'
418
- });
419
- });
420
- expect(result.current.sending).toBe(true);
421
- expect(mdm_sdk_1.createComment).toHaveBeenCalledWith({
422
- collaborationPath: '123',
423
- tenant: 'alenat',
424
- data: {
425
- objectId: 'uri1',
426
- content: 'content',
427
- relatedObjectUris: ['uri1'],
428
- objectType: 'entity',
429
- visibility: 'public',
430
- namedUsers: [],
431
- permanentLink: 'https://tst-01.reltio.com/nui/alenat/profile?entityUri=entities%2F2jWtLtNc&commentId=%7BcommentId%7D'
432
- }
433
- });
434
475
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
435
476
  return __generator(this, function (_a) {
436
477
  switch (_a.label) {
437
- case 0: return [4 /*yield*/, Promise.resolve()];
478
+ case 0: return [4 /*yield*/, result.current.createComment({
479
+ content: 'content',
480
+ namedUsers: [],
481
+ objectType: 'entity',
482
+ relatedObjectUris: ['uri1'],
483
+ uri: 'uri1'
484
+ })];
438
485
  case 1:
439
486
  _a.sent();
440
487
  return [2 /*return*/];
@@ -451,15 +498,23 @@ describe('useCollaboration behaviour', function () {
451
498
  uri1: __spreadArray(__spreadArray([], comments, true), [{ commentId: 'commentId', replies: 0, status: 'open' }], false)
452
499
  });
453
500
  mdm_sdk_1.createComment.mockResolvedValueOnce([{ commentId: 'commentId2' }]);
501
+ mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([
502
+ { objectId: 'uri1', comments: __spreadArray(__spreadArray([], comments, true), [{ commentId: 'commentId', replies: 0, status: 'open' }], false) },
503
+ { objectId: 'uri2', comments: [{ commentId: 'commentId2', replies: 0, status: 'open' }] }
504
+ ]);
454
505
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
455
506
  return __generator(this, function (_a) {
456
- result.current.createComment({
457
- content: 'content',
458
- namedUsers: [],
459
- objectType: 'entity',
460
- uri: 'uri2'
461
- });
462
- return [2 /*return*/];
507
+ switch (_a.label) {
508
+ case 0: return [4 /*yield*/, result.current.createComment({
509
+ content: 'content',
510
+ namedUsers: [],
511
+ objectType: 'entity',
512
+ uri: 'uri2'
513
+ })];
514
+ case 1:
515
+ _a.sent();
516
+ return [2 /*return*/];
517
+ }
463
518
  });
464
519
  }); })];
465
520
  case 3:
@@ -488,7 +543,14 @@ describe('useCollaboration behaviour', function () {
488
543
  { commentId: 'id1', content: 'first comment', status: 'open', replies: [] },
489
544
  { commentId: 'id2', content: 'second comment', status: 'open', replies: [] }
490
545
  ];
491
- mdm_sdk_1.getCommentsCount.mockResolvedValue([{ objectId: 'uri1', comments: commentsCount }]);
546
+ mdm_sdk_1.getCommentsCount
547
+ .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
548
+ .mockResolvedValueOnce([
549
+ { objectId: 'uri1', comments: [commentsCount[0], { commentId: 'id2', status: 'open', replies: 3 }] }
550
+ ])
551
+ .mockResolvedValueOnce([
552
+ { objectId: 'uri1', comments: [commentsCount[0], { commentId: 'id2', status: 'resolved', replies: 4 }] }
553
+ ]);
492
554
  mdm_sdk_1.getComments.mockResolvedValue({ items: comments });
493
555
  mdm_sdk_1.getComment.mockResolvedValueOnce({
494
556
  commentId: 'id2',
@@ -621,7 +683,11 @@ describe('useCollaboration behaviour', function () {
621
683
  { commentId: 'id1', status: 'open', content: 'first comment', replies: [] },
622
684
  { commentId: 'id2', status: 'open', content: 'second comment', replies: [] }
623
685
  ];
624
- mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
686
+ mdm_sdk_1.getCommentsCount
687
+ .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
688
+ .mockResolvedValueOnce([
689
+ { objectId: 'uri1', comments: [commentsCount[0], { commentId: 'id2', status: 'resolved', replies: 3 }] }
690
+ ]);
625
691
  mdm_sdk_1.getComment.mockResolvedValueOnce({ commentId: 'id2', replies: [] });
626
692
  mdm_sdk_1.getComments.mockResolvedValue({ items: comments });
627
693
  mdm_sdk_1.createReply.mockResolvedValueOnce([{ content: '', action: 'resolve' }]);
@@ -694,7 +760,11 @@ describe('useCollaboration behaviour', function () {
694
760
  { commentId: 'id1', status: 'open', content: 'first comment', replies: [] },
695
761
  { commentId: 'id2', status: 'open', content: 'second comment', replies: [] }
696
762
  ];
697
- mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
763
+ mdm_sdk_1.getCommentsCount
764
+ .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
765
+ .mockResolvedValueOnce([
766
+ { objectId: 'uri1', comments: [commentsCount[0], { commentId: 'id2', status: 'open', replies: 3 }] }
767
+ ]);
698
768
  mdm_sdk_1.getComment.mockResolvedValueOnce({ commentId: 'id2', replies: [] });
699
769
  mdm_sdk_1.getComments.mockResolvedValue({
700
770
  items: comments
@@ -867,9 +937,12 @@ describe('useCollaboration behaviour', function () {
867
937
  { commentId: 'id1', content: 'text 1', status: 'open', replies: [] },
868
938
  { commentId: 'id2', content: 'text2', status: 'open', replies: [] }
869
939
  ];
870
- expectedCommentsCount = commentsCount.slice(1);
871
- expectedComments = comments.slice(1);
872
- mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
940
+ expectedCommentsCount = [{ commentId: 'id2', status: 'open', replies: 0 }];
941
+ expectedComments = [{ commentId: 'id2', content: 'text2', status: 'open', replies: [] }];
942
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 2 });
943
+ mdm_sdk_1.getCommentsCount
944
+ .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
945
+ .mockResolvedValueOnce([{ objectId: 'uri1', comments: expectedCommentsCount }]);
873
946
  mdm_sdk_1.getComments.mockResolvedValueOnce({ items: comments });
874
947
  mdm_sdk_1.deleteComment.mockResolvedValueOnce('');
875
948
  result = setUp().result;
@@ -884,28 +957,20 @@ describe('useCollaboration behaviour', function () {
884
957
  expect(result.current.comments).toEqual(comments);
885
958
  expect(result.current.commentsMap).toEqual({ uri1: commentsCount });
886
959
  expect(result.current.sending).toBe(false);
887
- (0, react_hooks_1.act)(function () {
888
- result.current.deleteComment({ commentId: 'id1', uri: 'uri1' });
889
- });
890
- expect(result.current.sending).toBe(true);
891
- expect(mdm_sdk_1.deleteComment).toHaveBeenCalledWith({
892
- collaborationPath: '123',
893
- tenant: 'alenat',
894
- commentId: 'id1'
895
- });
896
960
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
897
961
  return __generator(this, function (_a) {
898
- switch (_a.label) {
899
- case 0: return [4 /*yield*/, Promise.resolve()];
900
- case 1:
901
- _a.sent();
902
- return [2 /*return*/];
903
- }
962
+ result.current.deleteComment({ commentId: 'id1', uri: 'uri1' });
963
+ return [2 /*return*/];
904
964
  });
905
965
  }); })];
906
966
  case 2:
907
967
  _a.sent();
908
968
  expect(result.current.sending).toBe(false);
969
+ expect(mdm_sdk_1.deleteComment).toHaveBeenCalledWith({
970
+ collaborationPath: '123',
971
+ tenant: 'alenat',
972
+ commentId: 'id1'
973
+ });
909
974
  expect(result.current.commentsMap).toEqual({
910
975
  uri1: expectedCommentsCount
911
976
  });
@@ -923,13 +988,23 @@ describe('useCollaboration behaviour', function () {
923
988
  { commentId: 'id1', status: 'open', replies: 1 },
924
989
  { commentId: 'id2', status: 'open', replies: 2 }
925
990
  ];
926
- mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
991
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: commentsCount.length });
992
+ mdm_sdk_1.getCommentsCount
993
+ .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
994
+ .mockResolvedValueOnce([
995
+ { objectId: 'uri1', comments: [commentsCount[0], { commentId: 'id2', status: 'open', replies: 2 }] },
996
+ { objectId: 'uri2', comments: [] }
997
+ ]);
927
998
  mdm_sdk_1.createReply.mockResolvedValueOnce([{ content: 'reply message' }]);
928
999
  result = setUp().result;
929
1000
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
930
1001
  return __generator(this, function (_a) {
931
- Promise.resolve();
932
- return [2 /*return*/];
1002
+ switch (_a.label) {
1003
+ case 0: return [4 /*yield*/, Promise.resolve()];
1004
+ case 1:
1005
+ _a.sent();
1006
+ return [2 /*return*/];
1007
+ }
933
1008
  });
934
1009
  }); })];
935
1010
  case 1:
@@ -946,6 +1021,9 @@ describe('useCollaboration behaviour', function () {
946
1021
  uri: 'uri2'
947
1022
  })];
948
1023
  case 1:
1024
+ _a.sent();
1025
+ return [4 /*yield*/, Promise.resolve()];
1026
+ case 2:
949
1027
  _a.sent();
950
1028
  return [2 /*return*/];
951
1029
  }
@@ -972,14 +1050,23 @@ describe('useCollaboration behaviour', function () {
972
1050
  ];
973
1051
  expectedCommentsCount = [{ commentId: 'id1', status: 'open', replies: 0 }];
974
1052
  expectedComments = [{ commentId: 'id1', content: 'text 1', status: 'open', replies: [] }];
975
- mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
1053
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 2 }).mockResolvedValueOnce({ total: 1 });
1054
+ mdm_sdk_1.getCommentsCount
1055
+ .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
1056
+ .mockResolvedValueOnce([{ objectId: 'uri1', comments: expectedCommentsCount }]);
976
1057
  mdm_sdk_1.getComments.mockResolvedValue({ items: comments });
977
1058
  mdm_sdk_1.deleteReply.mockResolvedValueOnce('');
978
1059
  result = setUp().result;
979
1060
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
980
1061
  return __generator(this, function (_a) {
981
- result.current.getComments('uri');
982
- return [2 /*return*/];
1062
+ switch (_a.label) {
1063
+ case 0:
1064
+ result.current.getComments('uri');
1065
+ return [4 /*yield*/, Promise.resolve()];
1066
+ case 1:
1067
+ _a.sent();
1068
+ return [2 /*return*/];
1069
+ }
983
1070
  });
984
1071
  }); })];
985
1072
  case 1:
@@ -987,24 +1074,16 @@ describe('useCollaboration behaviour', function () {
987
1074
  expect(result.current.comments).toEqual(comments);
988
1075
  expect(result.current.commentsMap).toEqual({ uri1: commentsCount });
989
1076
  expect(result.current.sending).toBe(false);
990
- (0, react_hooks_1.act)(function () {
991
- result.current.deleteReply({
992
- commentId: 'id1',
993
- uri: 'uri1',
994
- reply: comments[0].replies[0]
995
- });
996
- });
997
- expect(result.current.sending).toBe(true);
998
- expect(mdm_sdk_1.deleteReply).toHaveBeenCalledWith({
999
- collaborationPath: '123',
1000
- tenant: 'alenat',
1001
- commentId: 'id1',
1002
- replyId: 'replyId1'
1003
- });
1004
1077
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1005
1078
  return __generator(this, function (_a) {
1006
1079
  switch (_a.label) {
1007
- case 0: return [4 /*yield*/, Promise.resolve()];
1080
+ case 0:
1081
+ result.current.deleteReply({
1082
+ commentId: 'id1',
1083
+ uri: 'uri1',
1084
+ reply: comments[0].replies[0]
1085
+ });
1086
+ return [4 /*yield*/, Promise.resolve()];
1008
1087
  case 1:
1009
1088
  _a.sent();
1010
1089
  return [2 /*return*/];
@@ -1014,6 +1093,12 @@ describe('useCollaboration behaviour', function () {
1014
1093
  case 2:
1015
1094
  _a.sent();
1016
1095
  expect(result.current.sending).toBe(false);
1096
+ expect(mdm_sdk_1.deleteReply).toHaveBeenCalledWith({
1097
+ collaborationPath: '123',
1098
+ tenant: 'alenat',
1099
+ commentId: 'id1',
1100
+ replyId: 'replyId1'
1101
+ });
1017
1102
  expect(result.current.commentsMap).toEqual({
1018
1103
  uri1: expectedCommentsCount
1019
1104
  });
@@ -1045,6 +1130,7 @@ describe('useCollaboration behaviour', function () {
1045
1130
  mdm_sdk_1.updateReply.mockResolvedValueOnce(editedReply);
1046
1131
  mdm_sdk_1.getComment.mockResolvedValueOnce(initialComment);
1047
1132
  mdm_sdk_1.getComments.mockResolvedValueOnce({ items: initialComments });
1133
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 2 });
1048
1134
  result = setUp().result;
1049
1135
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1050
1136
  return __generator(this, function (_a) {
@@ -1101,6 +1187,7 @@ describe('useCollaboration behaviour', function () {
1101
1187
  return __generator(this, function (_a) {
1102
1188
  switch (_a.label) {
1103
1189
  case 0:
1190
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 1 });
1104
1191
  result = setUp().result;
1105
1192
  expect(result.current.getCommentState('attrUri', 'commentUri')).toEqual({});
1106
1193
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -1143,6 +1230,7 @@ describe('useCollaboration behaviour', function () {
1143
1230
  return __generator(this, function (_a) {
1144
1231
  switch (_a.label) {
1145
1232
  case 0:
1233
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 1 });
1146
1234
  result = setUp().result;
1147
1235
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1148
1236
  return __generator(this, function (_a) {
@@ -1179,6 +1267,7 @@ describe('useCollaboration behaviour', function () {
1179
1267
  return __generator(this, function (_a) {
1180
1268
  switch (_a.label) {
1181
1269
  case 0:
1270
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 1 });
1182
1271
  result = setUp().result;
1183
1272
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1184
1273
  return __generator(this, function (_a) {
@@ -1235,4 +1324,66 @@ describe('useCollaboration behaviour', function () {
1235
1324
  }
1236
1325
  });
1237
1326
  }); });
1327
+ describe('totalCommentsCount behavior', function () {
1328
+ it('should not call getTotalCommentsCount if collaboration is not enabled', function () {
1329
+ var mdmValues = __assign(__assign({}, defaultMdmValues), { collaborationPath: undefined, isCollaborationEnabled: false });
1330
+ var result = setUp({ mdmValues: mdmValues }).result;
1331
+ expect(result.current.totalCommentsCount).toBe(null);
1332
+ expect(mdm_sdk_1.getTotalCommentsCount).not.toHaveBeenCalled();
1333
+ });
1334
+ it('should call getTotalCommentsCount if collaboration is enabled and update totalCommentsCount value', function () { return __awaiter(void 0, void 0, void 0, function () {
1335
+ var result;
1336
+ return __generator(this, function (_a) {
1337
+ switch (_a.label) {
1338
+ case 0:
1339
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 15 });
1340
+ result = setUp().result;
1341
+ expect(mdm_sdk_1.getTotalCommentsCount).toHaveBeenCalledWith({
1342
+ relatedObjectUri: '1',
1343
+ collaborationPath: '123',
1344
+ tenant: 'alenat'
1345
+ });
1346
+ return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1347
+ return __generator(this, function (_a) {
1348
+ switch (_a.label) {
1349
+ case 0: return [4 /*yield*/, Promise.resolve()];
1350
+ case 1:
1351
+ _a.sent();
1352
+ return [2 /*return*/];
1353
+ }
1354
+ });
1355
+ }); })];
1356
+ case 1:
1357
+ _a.sent();
1358
+ expect(result.current.totalCommentsCount).toBe(15);
1359
+ return [2 /*return*/];
1360
+ }
1361
+ });
1362
+ }); });
1363
+ it('should set totalCommentsCount as null in case of unsuccessful request', function () { return __awaiter(void 0, void 0, void 0, function () {
1364
+ var result;
1365
+ return __generator(this, function (_a) {
1366
+ switch (_a.label) {
1367
+ case 0:
1368
+ mdm_sdk_1.getTotalCommentsCount.mockRejectedValueOnce(new Error('Network error'));
1369
+ result = setUp().result;
1370
+ expect(mdm_sdk_1.getTotalCommentsCount).toHaveBeenCalled();
1371
+ return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1372
+ return __generator(this, function (_a) {
1373
+ switch (_a.label) {
1374
+ case 0: return [4 /*yield*/, Promise.resolve()];
1375
+ case 1:
1376
+ _a.sent();
1377
+ return [2 /*return*/];
1378
+ }
1379
+ });
1380
+ }); })];
1381
+ case 1:
1382
+ _a.sent();
1383
+ expect(result.current.totalCommentsCount).toBe(null);
1384
+ return [2 /*return*/];
1385
+ }
1386
+ });
1387
+ }); });
1388
+ });
1238
1389
  });
@@ -22,6 +22,7 @@ export declare const InitialCollaborationContextValue: {
22
22
  pageToken: any;
23
23
  deleteReply: any;
24
24
  editReply: () => Promise<void>;
25
+ totalCommentsCount: any;
25
26
  };
26
27
  export declare const CollaborationContext: React.Context<{
27
28
  objectTypes?: CollaborationObjectTypes[];
@@ -67,6 +68,7 @@ export declare const CollaborationContext: React.Context<{
67
68
  sending: boolean;
68
69
  loading: boolean;
69
70
  pageToken: string;
71
+ totalCommentsCount: number | null;
70
72
  }>;
71
73
  export declare const CollaborationContextProvider: ({ collaboration, children }: {
72
74
  collaboration: any;
@@ -23,7 +23,8 @@ export var InitialCollaborationContextValue = {
23
23
  loading: false,
24
24
  pageToken: null,
25
25
  deleteReply: identity,
26
- editReply: function () { return new Promise(identity); }
26
+ editReply: function () { return new Promise(identity); },
27
+ totalCommentsCount: null
27
28
  };
28
29
  export var CollaborationContext = React.createContext(InitialCollaborationContextValue);
29
30
  CollaborationContext.displayName = 'CollaborationContext';
@@ -27,5 +27,6 @@ export declare const useCollaboration: ({ objectIds, objectTypes, enabled }: Pro
27
27
  sending: boolean;
28
28
  deleteReply: ({ uri, commentId, reply }: any) => void;
29
29
  editReply: ({ content, namedUsers, commentId, replyId }: any) => Promise<void>;
30
+ totalCommentsCount: number;
30
31
  };
31
32
  export {};