@reltio/components 1.4.2189 → 1.4.2190

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.
@@ -46,6 +46,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
49
58
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
59
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
60
  };
@@ -265,4 +274,62 @@ describe('AddWorkflowDialog tests', function () {
265
274
  }
266
275
  });
267
276
  }); });
277
+ describe('Required comments', function () {
278
+ it('should not allow to start workflow if comment is required with empty comment', function () { return __awaiter(void 0, void 0, void 0, function () {
279
+ var definitionsWithRequiredComment, mockAnchorEl, props, user, commentField, startButton, comment;
280
+ return __generator(this, function (_a) {
281
+ switch (_a.label) {
282
+ case 0:
283
+ mdm_sdk_1.startProcessInstance.mockResolvedValue(null);
284
+ definitionsWithRequiredComment = __spreadArray(__spreadArray([], definitions, true), [
285
+ {
286
+ type: 'workflowWithRequiredComment',
287
+ displayName: 'Workflow With Required Comment',
288
+ manualStart: true,
289
+ requiresCommentOnStart: true,
290
+ objectTypes: ['configuration/entityTypes/HCO']
291
+ }
292
+ ], false);
293
+ mdm_sdk_1.processDefinitions.mockReturnValue(Promise.resolve({
294
+ data: definitionsWithRequiredComment
295
+ }));
296
+ mockAnchorEl = document.createElement('div');
297
+ props = {
298
+ onClose: jest.fn(),
299
+ anchorEl: mockAnchorEl
300
+ };
301
+ user = setUp(props).user;
302
+ expect(react_2.screen.getByText('Add new workflow')).toBeInTheDocument();
303
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('combobox'))];
304
+ case 1:
305
+ _a.sent();
306
+ return [4 /*yield*/, user.click(react_2.screen.getByText('Workflow With Required Comment'))];
307
+ case 2:
308
+ _a.sent();
309
+ commentField = react_2.screen.getByRole('textbox', { name: /type a comment/i });
310
+ expect(commentField).toBeRequired();
311
+ startButton = react_2.screen.getByText('Start');
312
+ expect(startButton).toBeDisabled();
313
+ comment = 'Some comment';
314
+ return [4 /*yield*/, user.type(commentField, comment)];
315
+ case 3:
316
+ _a.sent();
317
+ expect(startButton).not.toBeDisabled();
318
+ return [4 /*yield*/, user.click(startButton)];
319
+ case 4:
320
+ _a.sent();
321
+ expect(mdm_sdk_1.startProcessInstance).toHaveBeenCalledWith({
322
+ workflowPath: workflowPath,
323
+ environment: workflowEnvironmentUrl,
324
+ tenant: tenant.id,
325
+ processType: 'workflowWithRequiredComment',
326
+ comment: comment,
327
+ objectURIs: ['entities/uri1']
328
+ });
329
+ expect(react_2.screen.getByText('A new workflow has started')).toBeInTheDocument();
330
+ return [2 /*return*/];
331
+ }
332
+ });
333
+ }); });
334
+ });
268
335
  });
@@ -139,7 +139,7 @@ describe('TaskActionButtons tests', function () {
139
139
  }
140
140
  });
141
141
  }); });
142
- describe('required comments', function () {
142
+ describe('Required comments', function () {
143
143
  it('should show comment dialog if commentRequired is true', function () { return __awaiter(void 0, void 0, void 0, function () {
144
144
  var task, user, dialog, textfield;
145
145
  return __generator(this, function (_a) {
@@ -69,8 +69,11 @@ var mdm_sdk_1 = require("@reltio/mdm-sdk");
69
69
  var MdmModuleContext_1 = require("../../../../../contexts/MdmModuleContext");
70
70
  var CommentDialogContext_1 = require("../../../../../contexts/CommentDialogContext");
71
71
  var DataChangeRequestTaskCard_1 = require("./DataChangeRequestTaskCard");
72
- jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getDataChangeRequest: jest.fn(), getEntitiesByUris: jest.fn() })); });
72
+ var WorkflowTasksContext_1 = require("../../../../../contexts/WorkflowTasksContext");
73
+ jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getDataChangeRequest: jest.fn(), getEntitiesByUris: jest.fn(), runTaskAction: jest.fn() })); });
73
74
  jest.mock('../../../../../contexts/MdmModuleContext', function () { return (__assign(__assign({}, jest.requireActual('../../../../../contexts/MdmModuleContext')), { useMdmMetadata: jest.fn() })); });
75
+ var onActionSuccess = jest.fn();
76
+ var workflowTaskContextValue = { onActionSuccess: onActionSuccess };
74
77
  describe('DataChangeRequestTaskCard tests', function () {
75
78
  var _a, _b;
76
79
  var metadata = {
@@ -180,7 +183,7 @@ describe('DataChangeRequestTaskCard tests', function () {
180
183
  var dcrUri = "changeRequests/".concat(dcrId);
181
184
  var dueDate = 1731825314640;
182
185
  var newStartDate = (0, moment_1.default)('11/15/2024', 'MM/DD/YYYY').valueOf();
183
- var task = {
186
+ var defaultTask = {
184
187
  assignee: userName,
185
188
  processInstanceId: '60260030',
186
189
  processType: 'dataChangeRequestReview',
@@ -260,17 +263,32 @@ describe('DataChangeRequestTaskCard tests', function () {
260
263
  label: relationEntityLabel
261
264
  }
262
265
  ];
263
- var setUp = function () {
266
+ var tenant = { id: 't1', name: 't1' };
267
+ var workflowPath = 'workflowPath';
268
+ var workflowEnvironmentUrl = 'workflowEnvironmentUrl';
269
+ var mdmValues = {
270
+ user: {
271
+ username: userName
272
+ },
273
+ tenant: tenant,
274
+ workflowPath: workflowPath,
275
+ workflowEnvironmentUrl: workflowEnvironmentUrl
276
+ };
277
+ var setUp = function (_a) {
278
+ var _b = _a === void 0 ? {} : _a, _c = _b.task, task = _c === void 0 ? defaultTask : _c;
264
279
  var user = user_event_1.default.setup();
265
280
  var Providers = function (_a) {
266
281
  var children = _a.children;
267
- return (react_1.default.createElement(LocalizationProvider_1.LocalizationProvider, { dateAdapter: AdapterMoment_1.AdapterMoment },
268
- react_1.default.createElement(CommentDialogContext_1.CommentDialogProvider, null, children)));
282
+ return (react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues },
283
+ react_1.default.createElement(LocalizationProvider_1.LocalizationProvider, { dateAdapter: AdapterMoment_1.AdapterMoment },
284
+ react_1.default.createElement(WorkflowTasksContext_1.WorkflowTasksContext.Provider, { value: workflowTaskContextValue },
285
+ react_1.default.createElement(CommentDialogContext_1.CommentDialogProvider, null, children)))));
269
286
  };
270
287
  return __assign(__assign({}, (0, react_2.render)(react_1.default.createElement(DataChangeRequestTaskCard_1.DataChangeRequestTaskCard, { task: task }), { wrapper: Providers })), { user: user });
271
288
  };
272
289
  beforeAll(function () {
273
290
  mdm_sdk_1.getEntitiesByUris.mockResolvedValue(entities);
291
+ mdm_sdk_1.runTaskAction.mockResolvedValue(null);
274
292
  });
275
293
  beforeEach(function () {
276
294
  MdmModuleContext_1.useMdmMetadata.mockReturnValue(metadata);
@@ -517,4 +535,61 @@ describe('DataChangeRequestTaskCard tests', function () {
517
535
  }
518
536
  });
519
537
  }); });
538
+ describe('Required comments', function () {
539
+ it('should show comment dialog when user runs action and comment is required', function () { return __awaiter(void 0, void 0, void 0, function () {
540
+ var task, user, dialog, comment, commentInput;
541
+ return __generator(this, function (_a) {
542
+ switch (_a.label) {
543
+ case 0:
544
+ task = __assign(__assign({}, defaultTask), { possibleActions: [
545
+ {
546
+ action: 'Approve',
547
+ label: 'Approve',
548
+ commentRequired: true
549
+ },
550
+ {
551
+ action: 'Reject',
552
+ label: 'Reject',
553
+ commentRequired: false
554
+ }
555
+ ] });
556
+ mdm_sdk_1.getDataChangeRequest.mockResolvedValue(dcr);
557
+ user = setUp({ task: task }).user;
558
+ return [4 /*yield*/, user.click(react_2.screen.getByTestId('task-actions'))];
559
+ case 1:
560
+ _a.sent();
561
+ return [4 /*yield*/, user.click(react_2.screen.getByText(task.possibleActions[0].label))];
562
+ case 2:
563
+ _a.sent();
564
+ expect(mdm_sdk_1.runTaskAction).not.toHaveBeenCalled();
565
+ dialog = react_2.screen.getAllByRole('presentation')[1];
566
+ expect((0, react_2.within)(dialog).getByText('Please provide a comment for your action')).toBeInTheDocument();
567
+ expect((0, react_2.within)(dialog).getByText('Type a comment')).toBeInTheDocument();
568
+ expect((0, react_2.within)(dialog).getByText('Cancel')).toBeInTheDocument();
569
+ expect((0, react_2.within)(dialog).getByText('Done')).toBeInTheDocument();
570
+ comment = 'Some comment';
571
+ commentInput = react_2.screen.getAllByRole('textbox')[0];
572
+ return [4 /*yield*/, user.click(commentInput)];
573
+ case 3:
574
+ _a.sent();
575
+ return [4 /*yield*/, user.paste(comment)];
576
+ case 4:
577
+ _a.sent();
578
+ return [4 /*yield*/, user.click((0, react_2.within)(dialog).getByText('Done'))];
579
+ case 5:
580
+ _a.sent();
581
+ expect(react_2.screen.queryByText('Please provide a comment for your action')).not.toBeInTheDocument();
582
+ expect(mdm_sdk_1.runTaskAction).toHaveBeenCalledWith({
583
+ workflowPath: workflowPath,
584
+ environment: workflowEnvironmentUrl,
585
+ tenant: tenant.id,
586
+ taskId: task.taskId,
587
+ action: task.possibleActions[0].action,
588
+ processInstanceComment: comment
589
+ });
590
+ return [2 /*return*/];
591
+ }
592
+ });
593
+ }); });
594
+ });
520
595
  });
@@ -456,4 +456,108 @@ describe('GenericWorkflowTaskCard tests', function () {
456
456
  }
457
457
  });
458
458
  }); });
459
+ describe('Required comments', function () {
460
+ it('should show comment dialog when user runs action and comment is required', function () { return __awaiter(void 0, void 0, void 0, function () {
461
+ var task, user, dialog, comment, commentInput;
462
+ return __generator(this, function (_a) {
463
+ switch (_a.label) {
464
+ case 0:
465
+ task = __assign(__assign({}, defaultTask), { possibleActions: [
466
+ {
467
+ action: 'Delete',
468
+ label: 'Delete',
469
+ commentRequired: true
470
+ },
471
+ {
472
+ action: 'Cancel',
473
+ label: 'Cancel',
474
+ commentRequired: false
475
+ }
476
+ ] });
477
+ user = setUp({ task: task }).user;
478
+ return [4 /*yield*/, user.click(react_2.screen.getByTestId('task-actions'))];
479
+ case 1:
480
+ _a.sent();
481
+ return [4 /*yield*/, user.click(react_2.screen.getByText(task.possibleActions[0].label))];
482
+ case 2:
483
+ _a.sent();
484
+ expect(mdm_sdk_1.runTaskAction).not.toHaveBeenCalled();
485
+ dialog = react_2.screen.getAllByRole('presentation')[1];
486
+ expect((0, react_2.within)(dialog).getByText('Please provide a comment for your action')).toBeInTheDocument();
487
+ expect((0, react_2.within)(dialog).getByText('Type a comment')).toBeInTheDocument();
488
+ expect((0, react_2.within)(dialog).getByText('Cancel')).toBeInTheDocument();
489
+ expect((0, react_2.within)(dialog).getByText('Done')).toBeInTheDocument();
490
+ comment = 'comment';
491
+ commentInput = react_2.screen.getAllByRole('textbox')[0];
492
+ return [4 /*yield*/, user.click(commentInput)];
493
+ case 3:
494
+ _a.sent();
495
+ return [4 /*yield*/, user.paste(comment)];
496
+ case 4:
497
+ _a.sent();
498
+ return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getAllByRole('presentation')[1]).getByText('Done'))];
499
+ case 5:
500
+ _a.sent();
501
+ expect(mdm_sdk_1.runTaskAction).toHaveBeenCalledWith({
502
+ workflowPath: workflowPath,
503
+ environment: workflowEnvironmentUrl,
504
+ tenant: tenant.id,
505
+ taskId: defaultTask.taskId,
506
+ action: defaultTask.possibleActions[0].action,
507
+ processInstanceComment: comment
508
+ });
509
+ return [2 /*return*/];
510
+ }
511
+ });
512
+ }); });
513
+ it('should not show comment dialog when user types comment and run action', function () { return __awaiter(void 0, void 0, void 0, function () {
514
+ var task, user, comment, commentInput;
515
+ var _a;
516
+ return __generator(this, function (_b) {
517
+ switch (_b.label) {
518
+ case 0:
519
+ task = __assign(__assign({}, defaultTask), { possibleActions: [
520
+ {
521
+ action: 'Delete',
522
+ label: 'Delete',
523
+ commentRequired: true
524
+ },
525
+ {
526
+ action: 'Cancel',
527
+ label: 'Cancel',
528
+ commentRequired: false
529
+ }
530
+ ] });
531
+ user = setUp({ task: task }).user;
532
+ return [4 /*yield*/, user.click(react_2.screen.getByTestId('collapse-button'))];
533
+ case 1:
534
+ _b.sent();
535
+ comment = 'comment';
536
+ commentInput = react_2.screen.getByPlaceholderText('Write a comment');
537
+ return [4 /*yield*/, user.click(commentInput)];
538
+ case 2:
539
+ _b.sent();
540
+ return [4 /*yield*/, user.paste(comment)];
541
+ case 3:
542
+ _b.sent();
543
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('button', { name: (_a = task.preferredAction) === null || _a === void 0 ? void 0 : _a.label }))];
544
+ case 4:
545
+ _b.sent();
546
+ return [4 /*yield*/, user.click(react_2.screen.getByTestId("reltio-profile-select-mode-".concat(task.possibleActions[0].label)))];
547
+ case 5:
548
+ _b.sent();
549
+ expect(react_2.screen.queryByText('Please provide a comment for your action')).not.toBeInTheDocument();
550
+ expect(mdm_sdk_1.runTaskAction).toHaveBeenCalledWith({
551
+ workflowPath: workflowPath,
552
+ environment: workflowEnvironmentUrl,
553
+ tenant: tenant.id,
554
+ taskId: defaultTask.taskId,
555
+ action: defaultTask.possibleActions[0].action,
556
+ processInstanceComment: comment
557
+ });
558
+ return [2 /*return*/];
559
+ }
560
+ });
561
+ }); });
562
+ });
459
563
  });
@@ -59,17 +59,24 @@ var AdapterMoment_1 = require("@mui/x-date-pickers/AdapterMoment");
59
59
  var MdmModuleContext_1 = require("../../../../../contexts/MdmModuleContext");
60
60
  var CommentDialogContext_1 = require("../../../../../contexts/CommentDialogContext");
61
61
  var PotentialMatchTaskCard_1 = require("./PotentialMatchTaskCard");
62
+ jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { runTaskAction: jest.fn() })); });
62
63
  describe('PotentialMatchTaskCard tests', function () {
64
+ var tenant = { id: 't1', name: 't1' };
65
+ var workflowPath = 'workflowPath';
66
+ var workflowEnvironmentUrl = 'workflowEnvironmentUrl';
63
67
  var mdmValues = {
64
68
  metadata: { entityTypes: [], relationTypes: [] },
65
69
  entity: { uri: 'entities/uri1', type: 'configuration/entityTypes/HCO' },
66
- tenant: { id: 't1', name: 't1' },
70
+ tenant: tenant,
71
+ workflowPath: workflowPath,
72
+ workflowEnvironmentUrl: workflowEnvironmentUrl,
73
+ user: { username: 'egorshkov' },
67
74
  dtssPath: 'path',
68
75
  dataTenants: [],
69
76
  activityFilter: mdm_sdk_1.ActivityFilter.ACTIVE_ONLY
70
77
  };
71
78
  var relatedEntityUri = 'entities/6hj8baQ';
72
- var task = {
79
+ var defaultTask = {
73
80
  assignee: 'egorshkov',
74
81
  objectURIs: [relatedEntityUri, 'entities/1RdgehCi'],
75
82
  createdBy: 'egorshkov',
@@ -103,7 +110,7 @@ describe('PotentialMatchTaskCard tests', function () {
103
110
  uri: 'entities/6hj8baQ'
104
111
  }
105
112
  };
106
- var defaultProps = { task: task, match: match, entitiesMap: entitiesMap };
113
+ var defaultProps = { task: defaultTask, match: match, entitiesMap: entitiesMap };
107
114
  var setUp = function (props) {
108
115
  if (props === void 0) { props = {}; }
109
116
  var user = user_event_1.default.setup();
@@ -115,6 +122,9 @@ describe('PotentialMatchTaskCard tests', function () {
115
122
  };
116
123
  return __assign({ user: user }, (0, react_2.render)(react_1.default.createElement(PotentialMatchTaskCard_1.PotentialMatchTaskCard, __assign({}, defaultProps, props)), { wrapper: Providers }));
117
124
  };
125
+ beforeAll(function () {
126
+ mdm_sdk_1.runTaskAction.mockResolvedValue(null);
127
+ });
118
128
  afterEach(function () {
119
129
  jest.clearAllMocks();
120
130
  });
@@ -163,4 +173,60 @@ describe('PotentialMatchTaskCard tests', function () {
163
173
  }
164
174
  });
165
175
  }); });
176
+ describe('Required comments', function () {
177
+ it('should show comment dialog when user runs action and comment is required', function () { return __awaiter(void 0, void 0, void 0, function () {
178
+ var task, user, dialog, comment, commentInput;
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0:
182
+ task = __assign(__assign({}, defaultTask), { isOpen: true, possibleActions: [
183
+ {
184
+ action: 'Approve',
185
+ label: 'Approve',
186
+ commentRequired: true
187
+ },
188
+ {
189
+ action: 'Reject',
190
+ label: 'Reject',
191
+ commentRequired: false
192
+ }
193
+ ] });
194
+ user = setUp({ task: task }).user;
195
+ return [4 /*yield*/, user.click(react_2.screen.getByTestId('task-actions'))];
196
+ case 1:
197
+ _a.sent();
198
+ return [4 /*yield*/, user.click(react_2.screen.getByText(task.possibleActions[0].label))];
199
+ case 2:
200
+ _a.sent();
201
+ expect(mdm_sdk_1.runTaskAction).not.toHaveBeenCalled();
202
+ dialog = react_2.screen.getAllByRole('presentation')[1];
203
+ expect((0, react_2.within)(dialog).getByText('Please provide a comment for your action')).toBeInTheDocument();
204
+ expect((0, react_2.within)(dialog).getByText('Type a comment')).toBeInTheDocument();
205
+ expect((0, react_2.within)(dialog).getByText('Cancel')).toBeInTheDocument();
206
+ expect((0, react_2.within)(dialog).getByText('Done')).toBeInTheDocument();
207
+ comment = 'Some comment';
208
+ commentInput = react_2.screen.getAllByRole('textbox')[0];
209
+ return [4 /*yield*/, user.click(commentInput)];
210
+ case 3:
211
+ _a.sent();
212
+ return [4 /*yield*/, user.paste(comment)];
213
+ case 4:
214
+ _a.sent();
215
+ return [4 /*yield*/, user.click((0, react_2.within)(dialog).getByText('Done'))];
216
+ case 5:
217
+ _a.sent();
218
+ expect(react_2.screen.queryByText('Please provide a comment for your action')).not.toBeInTheDocument();
219
+ expect(mdm_sdk_1.runTaskAction).toHaveBeenCalledWith({
220
+ workflowPath: workflowPath,
221
+ environment: workflowEnvironmentUrl,
222
+ tenant: tenant.id,
223
+ taskId: task.taskId,
224
+ action: task.possibleActions[0].action,
225
+ processInstanceComment: comment
226
+ });
227
+ return [2 /*return*/];
228
+ }
229
+ });
230
+ }); });
231
+ });
166
232
  });
@@ -45,6 +45,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
48
57
  import React from 'react';
49
58
  import { act, render, screen } from '@testing-library/react';
50
59
  import userEvent from '@testing-library/user-event';
@@ -260,4 +269,62 @@ describe('AddWorkflowDialog tests', function () {
260
269
  }
261
270
  });
262
271
  }); });
272
+ describe('Required comments', function () {
273
+ it('should not allow to start workflow if comment is required with empty comment', function () { return __awaiter(void 0, void 0, void 0, function () {
274
+ var definitionsWithRequiredComment, mockAnchorEl, props, user, commentField, startButton, comment;
275
+ return __generator(this, function (_a) {
276
+ switch (_a.label) {
277
+ case 0:
278
+ startProcessInstance.mockResolvedValue(null);
279
+ definitionsWithRequiredComment = __spreadArray(__spreadArray([], definitions, true), [
280
+ {
281
+ type: 'workflowWithRequiredComment',
282
+ displayName: 'Workflow With Required Comment',
283
+ manualStart: true,
284
+ requiresCommentOnStart: true,
285
+ objectTypes: ['configuration/entityTypes/HCO']
286
+ }
287
+ ], false);
288
+ processDefinitions.mockReturnValue(Promise.resolve({
289
+ data: definitionsWithRequiredComment
290
+ }));
291
+ mockAnchorEl = document.createElement('div');
292
+ props = {
293
+ onClose: jest.fn(),
294
+ anchorEl: mockAnchorEl
295
+ };
296
+ user = setUp(props).user;
297
+ expect(screen.getByText('Add new workflow')).toBeInTheDocument();
298
+ return [4 /*yield*/, user.click(screen.getByRole('combobox'))];
299
+ case 1:
300
+ _a.sent();
301
+ return [4 /*yield*/, user.click(screen.getByText('Workflow With Required Comment'))];
302
+ case 2:
303
+ _a.sent();
304
+ commentField = screen.getByRole('textbox', { name: /type a comment/i });
305
+ expect(commentField).toBeRequired();
306
+ startButton = screen.getByText('Start');
307
+ expect(startButton).toBeDisabled();
308
+ comment = 'Some comment';
309
+ return [4 /*yield*/, user.type(commentField, comment)];
310
+ case 3:
311
+ _a.sent();
312
+ expect(startButton).not.toBeDisabled();
313
+ return [4 /*yield*/, user.click(startButton)];
314
+ case 4:
315
+ _a.sent();
316
+ expect(startProcessInstance).toHaveBeenCalledWith({
317
+ workflowPath: workflowPath,
318
+ environment: workflowEnvironmentUrl,
319
+ tenant: tenant.id,
320
+ processType: 'workflowWithRequiredComment',
321
+ comment: comment,
322
+ objectURIs: ['entities/uri1']
323
+ });
324
+ expect(screen.getByText('A new workflow has started')).toBeInTheDocument();
325
+ return [2 /*return*/];
326
+ }
327
+ });
328
+ }); });
329
+ });
263
330
  });
@@ -134,7 +134,7 @@ describe('TaskActionButtons tests', function () {
134
134
  }
135
135
  });
136
136
  }); });
137
- describe('required comments', function () {
137
+ describe('Required comments', function () {
138
138
  it('should show comment dialog if commentRequired is true', function () { return __awaiter(void 0, void 0, void 0, function () {
139
139
  var task, user, dialog, textfield;
140
140
  return __generator(this, function (_a) {
@@ -60,12 +60,15 @@ import userEvent from '@testing-library/user-event';
60
60
  import moment from 'moment';
61
61
  import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
62
62
  import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
63
- import { DCROperationTypes, DCRTypes, getDataChangeRequest, getEntitiesByUris } from '@reltio/mdm-sdk';
64
- import { useMdmMetadata } from '../../../../../contexts/MdmModuleContext';
63
+ import { DCROperationTypes, DCRTypes, getDataChangeRequest, getEntitiesByUris, runTaskAction } from '@reltio/mdm-sdk';
64
+ import { MdmModuleProvider, useMdmMetadata } from '../../../../../contexts/MdmModuleContext';
65
65
  import { CommentDialogProvider } from '../../../../../contexts/CommentDialogContext';
66
66
  import { DataChangeRequestTaskCard } from './DataChangeRequestTaskCard';
67
- jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getDataChangeRequest: jest.fn(), getEntitiesByUris: jest.fn() })); });
67
+ import { WorkflowTasksContext } from '../../../../../contexts/WorkflowTasksContext';
68
+ jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getDataChangeRequest: jest.fn(), getEntitiesByUris: jest.fn(), runTaskAction: jest.fn() })); });
68
69
  jest.mock('../../../../../contexts/MdmModuleContext', function () { return (__assign(__assign({}, jest.requireActual('../../../../../contexts/MdmModuleContext')), { useMdmMetadata: jest.fn() })); });
70
+ var onActionSuccess = jest.fn();
71
+ var workflowTaskContextValue = { onActionSuccess: onActionSuccess };
69
72
  describe('DataChangeRequestTaskCard tests', function () {
70
73
  var _a, _b;
71
74
  var metadata = {
@@ -175,7 +178,7 @@ describe('DataChangeRequestTaskCard tests', function () {
175
178
  var dcrUri = "changeRequests/".concat(dcrId);
176
179
  var dueDate = 1731825314640;
177
180
  var newStartDate = moment('11/15/2024', 'MM/DD/YYYY').valueOf();
178
- var task = {
181
+ var defaultTask = {
179
182
  assignee: userName,
180
183
  processInstanceId: '60260030',
181
184
  processType: 'dataChangeRequestReview',
@@ -255,17 +258,32 @@ describe('DataChangeRequestTaskCard tests', function () {
255
258
  label: relationEntityLabel
256
259
  }
257
260
  ];
258
- var setUp = function () {
261
+ var tenant = { id: 't1', name: 't1' };
262
+ var workflowPath = 'workflowPath';
263
+ var workflowEnvironmentUrl = 'workflowEnvironmentUrl';
264
+ var mdmValues = {
265
+ user: {
266
+ username: userName
267
+ },
268
+ tenant: tenant,
269
+ workflowPath: workflowPath,
270
+ workflowEnvironmentUrl: workflowEnvironmentUrl
271
+ };
272
+ var setUp = function (_a) {
273
+ var _b = _a === void 0 ? {} : _a, _c = _b.task, task = _c === void 0 ? defaultTask : _c;
259
274
  var user = userEvent.setup();
260
275
  var Providers = function (_a) {
261
276
  var children = _a.children;
262
- return (React.createElement(LocalizationProvider, { dateAdapter: AdapterMoment },
263
- React.createElement(CommentDialogProvider, null, children)));
277
+ return (React.createElement(MdmModuleProvider, { values: mdmValues },
278
+ React.createElement(LocalizationProvider, { dateAdapter: AdapterMoment },
279
+ React.createElement(WorkflowTasksContext.Provider, { value: workflowTaskContextValue },
280
+ React.createElement(CommentDialogProvider, null, children)))));
264
281
  };
265
282
  return __assign(__assign({}, render(React.createElement(DataChangeRequestTaskCard, { task: task }), { wrapper: Providers })), { user: user });
266
283
  };
267
284
  beforeAll(function () {
268
285
  getEntitiesByUris.mockResolvedValue(entities);
286
+ runTaskAction.mockResolvedValue(null);
269
287
  });
270
288
  beforeEach(function () {
271
289
  useMdmMetadata.mockReturnValue(metadata);
@@ -512,4 +530,61 @@ describe('DataChangeRequestTaskCard tests', function () {
512
530
  }
513
531
  });
514
532
  }); });
533
+ describe('Required comments', function () {
534
+ it('should show comment dialog when user runs action and comment is required', function () { return __awaiter(void 0, void 0, void 0, function () {
535
+ var task, user, dialog, comment, commentInput;
536
+ return __generator(this, function (_a) {
537
+ switch (_a.label) {
538
+ case 0:
539
+ task = __assign(__assign({}, defaultTask), { possibleActions: [
540
+ {
541
+ action: 'Approve',
542
+ label: 'Approve',
543
+ commentRequired: true
544
+ },
545
+ {
546
+ action: 'Reject',
547
+ label: 'Reject',
548
+ commentRequired: false
549
+ }
550
+ ] });
551
+ getDataChangeRequest.mockResolvedValue(dcr);
552
+ user = setUp({ task: task }).user;
553
+ return [4 /*yield*/, user.click(screen.getByTestId('task-actions'))];
554
+ case 1:
555
+ _a.sent();
556
+ return [4 /*yield*/, user.click(screen.getByText(task.possibleActions[0].label))];
557
+ case 2:
558
+ _a.sent();
559
+ expect(runTaskAction).not.toHaveBeenCalled();
560
+ dialog = screen.getAllByRole('presentation')[1];
561
+ expect(within(dialog).getByText('Please provide a comment for your action')).toBeInTheDocument();
562
+ expect(within(dialog).getByText('Type a comment')).toBeInTheDocument();
563
+ expect(within(dialog).getByText('Cancel')).toBeInTheDocument();
564
+ expect(within(dialog).getByText('Done')).toBeInTheDocument();
565
+ comment = 'Some comment';
566
+ commentInput = screen.getAllByRole('textbox')[0];
567
+ return [4 /*yield*/, user.click(commentInput)];
568
+ case 3:
569
+ _a.sent();
570
+ return [4 /*yield*/, user.paste(comment)];
571
+ case 4:
572
+ _a.sent();
573
+ return [4 /*yield*/, user.click(within(dialog).getByText('Done'))];
574
+ case 5:
575
+ _a.sent();
576
+ expect(screen.queryByText('Please provide a comment for your action')).not.toBeInTheDocument();
577
+ expect(runTaskAction).toHaveBeenCalledWith({
578
+ workflowPath: workflowPath,
579
+ environment: workflowEnvironmentUrl,
580
+ tenant: tenant.id,
581
+ taskId: task.taskId,
582
+ action: task.possibleActions[0].action,
583
+ processInstanceComment: comment
584
+ });
585
+ return [2 /*return*/];
586
+ }
587
+ });
588
+ }); });
589
+ });
515
590
  });
@@ -57,7 +57,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
57
57
  import React from 'react';
58
58
  import i18n from 'ui-i18n';
59
59
  import { identity } from 'ramda';
60
- import { render, screen } from '@testing-library/react';
60
+ import { render, screen, within } from '@testing-library/react';
61
61
  import userEvent from '@testing-library/user-event';
62
62
  import { createTheme } from '@mui/material/styles';
63
63
  import { ThemeProvider } from '@mui/styles';
@@ -451,4 +451,108 @@ describe('GenericWorkflowTaskCard tests', function () {
451
451
  }
452
452
  });
453
453
  }); });
454
+ describe('Required comments', function () {
455
+ it('should show comment dialog when user runs action and comment is required', function () { return __awaiter(void 0, void 0, void 0, function () {
456
+ var task, user, dialog, comment, commentInput;
457
+ return __generator(this, function (_a) {
458
+ switch (_a.label) {
459
+ case 0:
460
+ task = __assign(__assign({}, defaultTask), { possibleActions: [
461
+ {
462
+ action: 'Delete',
463
+ label: 'Delete',
464
+ commentRequired: true
465
+ },
466
+ {
467
+ action: 'Cancel',
468
+ label: 'Cancel',
469
+ commentRequired: false
470
+ }
471
+ ] });
472
+ user = setUp({ task: task }).user;
473
+ return [4 /*yield*/, user.click(screen.getByTestId('task-actions'))];
474
+ case 1:
475
+ _a.sent();
476
+ return [4 /*yield*/, user.click(screen.getByText(task.possibleActions[0].label))];
477
+ case 2:
478
+ _a.sent();
479
+ expect(runTaskAction).not.toHaveBeenCalled();
480
+ dialog = screen.getAllByRole('presentation')[1];
481
+ expect(within(dialog).getByText('Please provide a comment for your action')).toBeInTheDocument();
482
+ expect(within(dialog).getByText('Type a comment')).toBeInTheDocument();
483
+ expect(within(dialog).getByText('Cancel')).toBeInTheDocument();
484
+ expect(within(dialog).getByText('Done')).toBeInTheDocument();
485
+ comment = 'comment';
486
+ commentInput = screen.getAllByRole('textbox')[0];
487
+ return [4 /*yield*/, user.click(commentInput)];
488
+ case 3:
489
+ _a.sent();
490
+ return [4 /*yield*/, user.paste(comment)];
491
+ case 4:
492
+ _a.sent();
493
+ return [4 /*yield*/, user.click(within(screen.getAllByRole('presentation')[1]).getByText('Done'))];
494
+ case 5:
495
+ _a.sent();
496
+ expect(runTaskAction).toHaveBeenCalledWith({
497
+ workflowPath: workflowPath,
498
+ environment: workflowEnvironmentUrl,
499
+ tenant: tenant.id,
500
+ taskId: defaultTask.taskId,
501
+ action: defaultTask.possibleActions[0].action,
502
+ processInstanceComment: comment
503
+ });
504
+ return [2 /*return*/];
505
+ }
506
+ });
507
+ }); });
508
+ it('should not show comment dialog when user types comment and run action', function () { return __awaiter(void 0, void 0, void 0, function () {
509
+ var task, user, comment, commentInput;
510
+ var _a;
511
+ return __generator(this, function (_b) {
512
+ switch (_b.label) {
513
+ case 0:
514
+ task = __assign(__assign({}, defaultTask), { possibleActions: [
515
+ {
516
+ action: 'Delete',
517
+ label: 'Delete',
518
+ commentRequired: true
519
+ },
520
+ {
521
+ action: 'Cancel',
522
+ label: 'Cancel',
523
+ commentRequired: false
524
+ }
525
+ ] });
526
+ user = setUp({ task: task }).user;
527
+ return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
528
+ case 1:
529
+ _b.sent();
530
+ comment = 'comment';
531
+ commentInput = screen.getByPlaceholderText('Write a comment');
532
+ return [4 /*yield*/, user.click(commentInput)];
533
+ case 2:
534
+ _b.sent();
535
+ return [4 /*yield*/, user.paste(comment)];
536
+ case 3:
537
+ _b.sent();
538
+ return [4 /*yield*/, user.click(screen.getByRole('button', { name: (_a = task.preferredAction) === null || _a === void 0 ? void 0 : _a.label }))];
539
+ case 4:
540
+ _b.sent();
541
+ return [4 /*yield*/, user.click(screen.getByTestId("reltio-profile-select-mode-".concat(task.possibleActions[0].label)))];
542
+ case 5:
543
+ _b.sent();
544
+ expect(screen.queryByText('Please provide a comment for your action')).not.toBeInTheDocument();
545
+ expect(runTaskAction).toHaveBeenCalledWith({
546
+ workflowPath: workflowPath,
547
+ environment: workflowEnvironmentUrl,
548
+ tenant: tenant.id,
549
+ taskId: defaultTask.taskId,
550
+ action: defaultTask.possibleActions[0].action,
551
+ processInstanceComment: comment
552
+ });
553
+ return [2 /*return*/];
554
+ }
555
+ });
556
+ }); });
557
+ });
454
558
  });
@@ -46,25 +46,32 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  }
47
47
  };
48
48
  import React from 'react';
49
- import { render, screen } from '@testing-library/react';
49
+ import { render, screen, within } from '@testing-library/react';
50
50
  import userEvent from '@testing-library/user-event';
51
- import { ActivityFilter } from '@reltio/mdm-sdk';
51
+ import { ActivityFilter, runTaskAction } from '@reltio/mdm-sdk';
52
52
  import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
53
53
  import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
54
54
  import { MdmModuleProvider } from '../../../../../contexts/MdmModuleContext';
55
55
  import { CommentDialogProvider } from '../../../../../contexts/CommentDialogContext';
56
56
  import { PotentialMatchTaskCard } from './PotentialMatchTaskCard';
57
+ jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { runTaskAction: jest.fn() })); });
57
58
  describe('PotentialMatchTaskCard tests', function () {
59
+ var tenant = { id: 't1', name: 't1' };
60
+ var workflowPath = 'workflowPath';
61
+ var workflowEnvironmentUrl = 'workflowEnvironmentUrl';
58
62
  var mdmValues = {
59
63
  metadata: { entityTypes: [], relationTypes: [] },
60
64
  entity: { uri: 'entities/uri1', type: 'configuration/entityTypes/HCO' },
61
- tenant: { id: 't1', name: 't1' },
65
+ tenant: tenant,
66
+ workflowPath: workflowPath,
67
+ workflowEnvironmentUrl: workflowEnvironmentUrl,
68
+ user: { username: 'egorshkov' },
62
69
  dtssPath: 'path',
63
70
  dataTenants: [],
64
71
  activityFilter: ActivityFilter.ACTIVE_ONLY
65
72
  };
66
73
  var relatedEntityUri = 'entities/6hj8baQ';
67
- var task = {
74
+ var defaultTask = {
68
75
  assignee: 'egorshkov',
69
76
  objectURIs: [relatedEntityUri, 'entities/1RdgehCi'],
70
77
  createdBy: 'egorshkov',
@@ -98,7 +105,7 @@ describe('PotentialMatchTaskCard tests', function () {
98
105
  uri: 'entities/6hj8baQ'
99
106
  }
100
107
  };
101
- var defaultProps = { task: task, match: match, entitiesMap: entitiesMap };
108
+ var defaultProps = { task: defaultTask, match: match, entitiesMap: entitiesMap };
102
109
  var setUp = function (props) {
103
110
  if (props === void 0) { props = {}; }
104
111
  var user = userEvent.setup();
@@ -110,6 +117,9 @@ describe('PotentialMatchTaskCard tests', function () {
110
117
  };
111
118
  return __assign({ user: user }, render(React.createElement(PotentialMatchTaskCard, __assign({}, defaultProps, props)), { wrapper: Providers }));
112
119
  };
120
+ beforeAll(function () {
121
+ runTaskAction.mockResolvedValue(null);
122
+ });
113
123
  afterEach(function () {
114
124
  jest.clearAllMocks();
115
125
  });
@@ -158,4 +168,60 @@ describe('PotentialMatchTaskCard tests', function () {
158
168
  }
159
169
  });
160
170
  }); });
171
+ describe('Required comments', function () {
172
+ it('should show comment dialog when user runs action and comment is required', function () { return __awaiter(void 0, void 0, void 0, function () {
173
+ var task, user, dialog, comment, commentInput;
174
+ return __generator(this, function (_a) {
175
+ switch (_a.label) {
176
+ case 0:
177
+ task = __assign(__assign({}, defaultTask), { isOpen: true, possibleActions: [
178
+ {
179
+ action: 'Approve',
180
+ label: 'Approve',
181
+ commentRequired: true
182
+ },
183
+ {
184
+ action: 'Reject',
185
+ label: 'Reject',
186
+ commentRequired: false
187
+ }
188
+ ] });
189
+ user = setUp({ task: task }).user;
190
+ return [4 /*yield*/, user.click(screen.getByTestId('task-actions'))];
191
+ case 1:
192
+ _a.sent();
193
+ return [4 /*yield*/, user.click(screen.getByText(task.possibleActions[0].label))];
194
+ case 2:
195
+ _a.sent();
196
+ expect(runTaskAction).not.toHaveBeenCalled();
197
+ dialog = screen.getAllByRole('presentation')[1];
198
+ expect(within(dialog).getByText('Please provide a comment for your action')).toBeInTheDocument();
199
+ expect(within(dialog).getByText('Type a comment')).toBeInTheDocument();
200
+ expect(within(dialog).getByText('Cancel')).toBeInTheDocument();
201
+ expect(within(dialog).getByText('Done')).toBeInTheDocument();
202
+ comment = 'Some comment';
203
+ commentInput = screen.getAllByRole('textbox')[0];
204
+ return [4 /*yield*/, user.click(commentInput)];
205
+ case 3:
206
+ _a.sent();
207
+ return [4 /*yield*/, user.paste(comment)];
208
+ case 4:
209
+ _a.sent();
210
+ return [4 /*yield*/, user.click(within(dialog).getByText('Done'))];
211
+ case 5:
212
+ _a.sent();
213
+ expect(screen.queryByText('Please provide a comment for your action')).not.toBeInTheDocument();
214
+ expect(runTaskAction).toHaveBeenCalledWith({
215
+ workflowPath: workflowPath,
216
+ environment: workflowEnvironmentUrl,
217
+ tenant: tenant.id,
218
+ taskId: task.taskId,
219
+ action: task.possibleActions[0].action,
220
+ processInstanceComment: comment
221
+ });
222
+ return [2 /*return*/];
223
+ }
224
+ });
225
+ }); });
226
+ });
161
227
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.2189",
3
+ "version": "1.4.2190",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",