@reltio/components 1.4.1906 → 1.4.1907

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 (97) hide show
  1. package/cjs/ActionsPanel/ActionsPanel.test.js +133 -49
  2. package/cjs/AttributeListItem/AttributeListItem.spec.js +147 -118
  3. package/cjs/AttributeSelector/AttributeSelector.specs.js +125 -193
  4. package/cjs/AttributesErrorsPanel/AttributesErrorsPanel.specs.js +128 -71
  5. package/cjs/AttributesErrorsPanel/components/Error/Error.specs.js +96 -90
  6. package/cjs/AttributesErrorsPanel/store.test-data.d.ts +22 -0
  7. package/cjs/AttributesErrorsPanel/store.test-data.js +29 -0
  8. package/cjs/AttributesFilterSelector/AttributesFilterSelector.test.js +127 -105
  9. package/cjs/AttributesFiltersButton/AttributesFiltersButton.test.js +218 -136
  10. package/cjs/AttributesValuesEditor/AttributesValuesEditor.test.js +92 -88
  11. package/cjs/AttributesView/AttributesView.test.js +67 -34
  12. package/cjs/AutoSizeList/AutoSizeList.test.js +81 -59
  13. package/cjs/{ActionsPanel/components/MenuItemRenderer/MenuItemRenderer.spec.js → AvatarWithFallback/AvatarWithFallback.test.js} +15 -31
  14. package/cjs/BarChart/BarChart.test.js +128 -65
  15. package/cjs/BasicAttributeSelector/BasicAttributeSelector.spec.js +27 -10
  16. package/cjs/BasicViewContent/BasicViewContent.test.js +7 -9
  17. package/cjs/BlobRenderer/BlobRenderer.test.js +28 -9
  18. package/cjs/BooleanRadioEditor/BooleanRadioEditor.test.js +89 -35
  19. package/cjs/BubbleChart/BubbleChart.test.js +111 -87
  20. package/cjs/CloudChart/CloudChart.test.js +95 -36
  21. package/cjs/CollaborationItem/CollaborationItem.test.js +67 -30
  22. package/cjs/CollaborationItem/components/Comment/Comment.test.js +221 -189
  23. package/cjs/CollaborationItem/components/CommentContent/CommentContent.test.js +46 -81
  24. package/cjs/CollaborationItem/components/RepliedComment/RepliedComment.test.js +194 -163
  25. package/cjs/CollaborationItem/components/SendMessageArea/SendMessageArea.test.js +307 -266
  26. package/cjs/CollapseButton/CollapseButton.test.js +74 -15
  27. package/cjs/CollapseRowButton/CollapseRowButton.test.js +82 -24
  28. package/cjs/ColorBar/ColorBar.test.js +13 -15
  29. package/cjs/ColumnsSettings/components/ColumnsSettingsPopup/ColumnsSettingsPopup.spec.js +207 -129
  30. package/cjs/CommentsContainer/CommentsContainer.test.js +282 -211
  31. package/cjs/CommentsContainer/components/CollaborationPopup/CollaborationPopup.test.js +183 -122
  32. package/cjs/ConfigureColumnsPopup/ConfigureColumnsPopup.test.js +42 -41
  33. package/cjs/ConfirmDeleteDialog/ConfirmDeleteDialog.test.js +77 -28
  34. package/cjs/ConfirmationDialog/ConfirmationDialog.test.js +85 -48
  35. package/cjs/ConnectionEditor/ConnectionEditor.test.js +299 -282
  36. package/esm/ActionsPanel/ActionsPanel.test.js +133 -49
  37. package/esm/AttributeListItem/AttributeListItem.spec.js +149 -97
  38. package/esm/AttributeSelector/AttributeSelector.specs.js +125 -193
  39. package/esm/AttributesErrorsPanel/AttributesErrorsPanel.specs.js +128 -71
  40. package/esm/AttributesErrorsPanel/components/Error/Error.specs.js +98 -72
  41. package/esm/AttributesErrorsPanel/store.test-data.d.ts +22 -0
  42. package/esm/AttributesErrorsPanel/store.test-data.js +26 -0
  43. package/esm/AttributesFilterSelector/AttributesFilterSelector.test.js +129 -84
  44. package/esm/AttributesFiltersButton/AttributesFiltersButton.test.js +218 -136
  45. package/esm/AttributesValuesEditor/AttributesValuesEditor.test.js +94 -67
  46. package/esm/AttributesView/AttributesView.test.js +67 -34
  47. package/esm/AutoSizeList/AutoSizeList.test.js +81 -59
  48. package/esm/{ActionsPanel/components/MenuItemRenderer/MenuItemRenderer.spec.js → AvatarWithFallback/AvatarWithFallback.test.js} +16 -32
  49. package/esm/BarChart/BarChart.test.js +128 -65
  50. package/esm/BasicAttributeSelector/BasicAttributeSelector.spec.js +27 -10
  51. package/esm/BasicViewContent/BasicViewContent.test.js +7 -9
  52. package/esm/BlobRenderer/BlobRenderer.test.js +28 -9
  53. package/esm/BooleanRadioEditor/BooleanRadioEditor.test.js +89 -35
  54. package/esm/BubbleChart/BubbleChart.test.js +111 -87
  55. package/esm/CloudChart/CloudChart.test.js +95 -36
  56. package/esm/CollaborationItem/CollaborationItem.test.js +67 -30
  57. package/esm/CollaborationItem/components/Comment/Comment.test.js +221 -189
  58. package/esm/CollaborationItem/components/CommentContent/CommentContent.test.js +46 -58
  59. package/esm/CollaborationItem/components/RepliedComment/RepliedComment.test.js +194 -163
  60. package/esm/CollaborationItem/components/SendMessageArea/SendMessageArea.test.js +307 -266
  61. package/esm/CollapseButton/CollapseButton.test.js +74 -15
  62. package/esm/CollapseRowButton/CollapseRowButton.test.js +82 -24
  63. package/esm/ColorBar/ColorBar.test.js +13 -15
  64. package/esm/ColumnsSettings/components/ColumnsSettingsPopup/ColumnsSettingsPopup.spec.js +207 -129
  65. package/esm/CommentsContainer/CommentsContainer.test.js +282 -211
  66. package/esm/CommentsContainer/components/CollaborationPopup/CollaborationPopup.test.js +182 -101
  67. package/esm/ConfigureColumnsPopup/ConfigureColumnsPopup.test.js +42 -41
  68. package/esm/ConfirmDeleteDialog/ConfirmDeleteDialog.test.js +77 -28
  69. package/esm/ConfirmationDialog/ConfirmationDialog.test.js +85 -48
  70. package/esm/ConnectionEditor/ConnectionEditor.test.js +300 -283
  71. package/package.json +1 -1
  72. package/cjs/AttributesErrorsPanel/components/ErrorsPanel/ErrorsPanel.specs.js +0 -100
  73. package/cjs/AttributesFiltersButton/components/ActionButtons/ActionButtons.test.d.ts +0 -1
  74. package/cjs/AttributesFiltersButton/components/ActionButtons/ActionButtons.test.js +0 -46
  75. package/cjs/AvatarWithFallback/AvatarWithFallback.specs.d.ts +0 -1
  76. package/cjs/AvatarWithFallback/AvatarWithFallback.specs.js +0 -27
  77. package/cjs/BooleanRadioEditor/components/BooleanEditor/BooleanEditor.test.d.ts +0 -1
  78. package/cjs/BooleanRadioEditor/components/BooleanEditor/BooleanEditor.test.js +0 -27
  79. package/cjs/CollaborationItem/components/Avatar/Avatar.test.d.ts +0 -1
  80. package/cjs/CollaborationItem/components/Avatar/Avatar.test.js +0 -15
  81. package/cjs/CollaborationItem/components/TextFieldWithMentions/TextFieldWithMentions.test.d.ts +0 -1
  82. package/cjs/CollaborationItem/components/TextFieldWithMentions/TextFieldWithMentions.test.js +0 -80
  83. package/esm/ActionsPanel/components/MenuItemRenderer/MenuItemRenderer.spec.d.ts +0 -1
  84. package/esm/AttributesErrorsPanel/components/ErrorsPanel/ErrorsPanel.specs.d.ts +0 -1
  85. package/esm/AttributesErrorsPanel/components/ErrorsPanel/ErrorsPanel.specs.js +0 -95
  86. package/esm/AttributesFiltersButton/components/ActionButtons/ActionButtons.test.d.ts +0 -1
  87. package/esm/AttributesFiltersButton/components/ActionButtons/ActionButtons.test.js +0 -41
  88. package/esm/AvatarWithFallback/AvatarWithFallback.specs.d.ts +0 -1
  89. package/esm/AvatarWithFallback/AvatarWithFallback.specs.js +0 -22
  90. package/esm/BooleanRadioEditor/components/BooleanEditor/BooleanEditor.test.d.ts +0 -1
  91. package/esm/BooleanRadioEditor/components/BooleanEditor/BooleanEditor.test.js +0 -22
  92. package/esm/CollaborationItem/components/Avatar/Avatar.test.d.ts +0 -1
  93. package/esm/CollaborationItem/components/Avatar/Avatar.test.js +0 -10
  94. package/esm/CollaborationItem/components/TextFieldWithMentions/TextFieldWithMentions.test.d.ts +0 -1
  95. package/esm/CollaborationItem/components/TextFieldWithMentions/TextFieldWithMentions.test.js +0 -55
  96. /package/cjs/{ActionsPanel/components/MenuItemRenderer/MenuItemRenderer.spec.d.ts → AvatarWithFallback/AvatarWithFallback.test.d.ts} +0 -0
  97. /package/{cjs/AttributesErrorsPanel/components/ErrorsPanel/ErrorsPanel.specs.d.ts → esm/AvatarWithFallback/AvatarWithFallback.test.d.ts} +0 -0
@@ -51,202 +51,262 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
53
  var react_1 = __importDefault(require("react"));
54
- var enzyme_1 = require("enzyme");
55
- var test_utils_1 = require("react-dom/test-utils");
54
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
56
55
  var MdmModuleContext_1 = require("../../../contexts/MdmModuleContext");
57
56
  var CollaborationContext_1 = require("../../../contexts/CollaborationContext");
58
- var TextFieldWithMentions_1 = require("../TextFieldWithMentions");
59
- var Avatar_1 = require("../Avatar");
60
57
  var SendMessageArea_1 = require("./SendMessageArea");
61
- var createProps = function (comment, extraProps) {
62
- if (extraProps === void 0) { extraProps = {}; }
63
- return __assign(__assign({ comment: comment, inputRef: react_1.default.createRef() }, extraProps), { objectType: 'objectType', uri: 'uri', relatedObjectUris: ['entities/13JKIKAz'], className: 'root' });
64
- };
65
- var createReply = jest.fn().mockReturnValue(new Promise(function (res) { return res(); }));
66
- var createComment = jest.fn().mockReturnValue(new Promise(function (res) { return res(); }));
67
- var editCommentWithResolve = jest.fn().mockReturnValue(new Promise(function (res) { return res(); }));
68
- var editReply = jest.fn().mockReturnValue(new Promise(function (res) { return res(); }));
69
- var defaultGetCommentState = jest.fn().mockImplementation(function () { return ({}); });
70
- var clearCommentState = jest.fn();
71
- var updateCommentState = jest.fn();
72
- var createCommentObject = function (_a) {
73
- var _b = _a === void 0 ? {} : _a, status = _b.status;
74
- return {
75
- commentId: 'commentId',
76
- status: status
58
+ var user_event_1 = __importDefault(require("@testing-library/user-event"));
59
+ var react_2 = require("@testing-library/react");
60
+ var ramda_1 = require("ramda");
61
+ describe('SendMessageArea tests', function () {
62
+ var mdmValues = {
63
+ user: {
64
+ username: 'egor.ivanov'
65
+ }
77
66
  };
78
- };
79
- var collaborationContextValue;
80
- var mockCollaborationContext = function (_a) {
81
- var _b = _a === void 0 ? {} : _a, _c = _b.sending, sending = _c === void 0 ? false : _c, _d = _b.editComment, editComment = _d === void 0 ? editCommentWithResolve : _d, _e = _b.getCommentState, getCommentState = _e === void 0 ? defaultGetCommentState : _e;
82
- collaborationContextValue = {
83
- createReply: createReply,
84
- createComment: createComment,
85
- editComment: editComment,
86
- editReply: editReply,
87
- getCommentState: getCommentState,
88
- clearCommentState: clearCommentState,
89
- updateCommentState: updateCommentState,
90
- sending: sending
67
+ var createCommentObject = function (commentObject) {
68
+ if (commentObject === void 0) { commentObject = {}; }
69
+ return __assign({ selfLink: 'selfLink', commentId: 'commentId', createdBy: 'created by user', createdTime: 1, modifiedTime: 2, deleted: false, visibility: 'visible', objectId: 'id1', objectType: mdm_sdk_1.CollaborationObjectTypes.ENTITY, permanentLink: 'permanentLink', content: 'commentContent', namedUsers: ['user1'], replies: [], relatedObjectUris: ['uri1'], status: 'open' }, commentObject);
70
+ };
71
+ var createCollaborationContext = function (props) {
72
+ if (props === void 0) { props = {}; }
73
+ return __assign({ comments: [], commentsMap: null, currentComment: null, getComment: ramda_1.identity, getComments: function () { return new Promise(ramda_1.identity); }, getCommentsCount: ramda_1.identity, resolveThread: ramda_1.identity, reOpenThread: ramda_1.identity, clearCurrentComment: ramda_1.identity, deleteComment: ramda_1.identity, sending: false, loading: false, pageToken: null, deleteReply: ramda_1.identity, createReply: function () { return new Promise(function (res) { return res(); }); }, createComment: function () { return new Promise(function (res) { return res(); }); }, editComment: function () { return new Promise(function (res) { return res(); }); }, editReply: function () { return new Promise(function (res) { return res(); }); }, getCommentState: function () { return ({}); }, clearCommentState: function () { }, updateCommentState: function () { } }, props);
74
+ };
75
+ var createProps = function (comment, extraProps) {
76
+ if (extraProps === void 0) { extraProps = {}; }
77
+ return __assign(__assign({ comment: comment, inputRef: react_1.default.createRef() }, extraProps), { objectType: mdm_sdk_1.CollaborationObjectTypes.ENTITY, uri: 'uri', relatedObjectUris: ['entities/13JKIKAz'], className: 'root' });
78
+ };
79
+ var setUp = function (_a) {
80
+ var props = _a.props, _b = _a.collaborationContextValue, collaborationContextValue = _b === void 0 ? createCollaborationContext() : _b;
81
+ var Providers = function (_a) {
82
+ var children = _a.children;
83
+ return (react_1.default.createElement(CollaborationContext_1.CollaborationContext.Provider, { value: collaborationContextValue },
84
+ react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues }, children)));
85
+ };
86
+ var user = user_event_1.default.setup();
87
+ return __assign({ user: user }, (0, react_2.render)(react_1.default.createElement(SendMessageArea_1.SendMessageArea, __assign({}, props)), { wrapper: Providers }));
91
88
  };
92
- };
93
- var user = {
94
- username: 'egor.ivanov'
95
- };
96
- var setUp = function (props) {
97
- return (0, enzyme_1.mount)(react_1.default.createElement(CollaborationContext_1.CollaborationContext.Provider, { value: collaborationContextValue },
98
- react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: { user: user } },
99
- react_1.default.createElement(SendMessageArea_1.SendMessageArea, __assign({}, props)))));
100
- };
101
- describe('SendMessageArea tests', function () {
102
- afterEach(function () {
103
- jest.clearAllMocks();
104
- });
105
89
  it('should render avatar correctly', function () {
106
- mockCollaborationContext();
107
- var component = setUp(createProps(createCommentObject({ status: 'open' })));
108
- expect(component.find(Avatar_1.Avatar)).toHaveLength(1);
109
- expect(component.find(Avatar_1.Avatar).prop('children')).toBe('egor.ivanov');
90
+ setUp({
91
+ props: createProps(createCommentObject({ status: 'open' }))
92
+ });
93
+ expect(react_2.screen.queryByText('EI')).toBeInTheDocument();
110
94
  });
111
95
  it('should render input correctly if status is "open"', function () {
112
- mockCollaborationContext();
113
- var component = setUp(createProps(createCommentObject({ status: 'open' })));
114
- expect(component.find(TextFieldWithMentions_1.TextFieldWithMentions)).toHaveLength(1);
115
- expect(component.find(TextFieldWithMentions_1.TextFieldWithMentions).prop('placeholder')).toBe('Reply...');
96
+ setUp({
97
+ props: createProps(createCommentObject({ status: 'open' }))
98
+ });
99
+ expect(react_2.screen.queryByPlaceholderText('Reply...')).toBeInTheDocument();
116
100
  });
117
101
  it('should render input correctly if status is "resolved"', function () {
118
- mockCollaborationContext();
119
- var component = setUp(createProps(createCommentObject({ status: 'resolved' })));
120
- expect(component.find(TextFieldWithMentions_1.TextFieldWithMentions)).toHaveLength(1);
121
- expect(component.find(TextFieldWithMentions_1.TextFieldWithMentions).prop('placeholder')).toBe('Adding a comment will re-open this');
102
+ setUp({
103
+ props: createProps(createCommentObject({ status: 'resolved' }))
104
+ });
105
+ expect(react_2.screen.queryByPlaceholderText('Adding a comment will re-open this')).toBeInTheDocument();
122
106
  });
123
107
  it('should render input correctly if status is undefined', function () {
124
- mockCollaborationContext();
125
- var component = setUp(createProps());
126
- expect(component.find(TextFieldWithMentions_1.TextFieldWithMentions)).toHaveLength(1);
127
- expect(component.find(TextFieldWithMentions_1.TextFieldWithMentions).prop('placeholder')).toBe('');
128
- });
129
- it('should render Reply button correctly if status is "open"', function () {
130
- mockCollaborationContext();
131
- var component = setUp(createProps(createCommentObject({ status: 'open' })));
132
- component.find(TextFieldWithMentions_1.TextFieldWithMentions).find('textarea').simulate('focus');
133
- var buttons = component.find('.buttons').last();
134
- expect(buttons.childAt(0).text()).toBe('Reply');
135
- });
136
- it('should render Reply button correctly if status is "resolved"', function () {
137
- mockCollaborationContext();
138
- var component = setUp(createProps(createCommentObject({ status: 'resolved' })));
139
- component.find(TextFieldWithMentions_1.TextFieldWithMentions).find('textarea').simulate('focus');
140
- var buttons = component.find('.buttons').last();
141
- expect(buttons.childAt(0).text()).toBe('Reply');
142
- });
143
- it('should render Comment button correctly if comment is undefined', function () {
144
- mockCollaborationContext();
145
- var component = setUp(createProps());
146
- component.find(TextFieldWithMentions_1.TextFieldWithMentions).find('textarea').simulate('focus');
147
- var buttons = component.find('.buttons').last();
148
- expect(buttons.childAt(0).text()).toBe('Comment');
108
+ setUp({
109
+ props: createProps()
110
+ });
111
+ expect(react_2.screen.getByRole('textbox')).toHaveAttribute('placeholder', '');
149
112
  });
113
+ it('should render Reply button correctly if status is "open"', function () { return __awaiter(void 0, void 0, void 0, function () {
114
+ var user;
115
+ return __generator(this, function (_a) {
116
+ switch (_a.label) {
117
+ case 0:
118
+ user = setUp({
119
+ props: createProps(createCommentObject({ status: 'open' }))
120
+ }).user;
121
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('textbox'))];
122
+ case 1:
123
+ _a.sent();
124
+ expect(react_2.screen.getByRole('button', { name: 'Reply' })).toBeInTheDocument();
125
+ return [2 /*return*/];
126
+ }
127
+ });
128
+ }); });
129
+ it('should render Reply button correctly if status is "resolved"', function () { return __awaiter(void 0, void 0, void 0, function () {
130
+ var user;
131
+ return __generator(this, function (_a) {
132
+ switch (_a.label) {
133
+ case 0:
134
+ user = setUp({
135
+ props: createProps(createCommentObject({ status: 'resolved' }))
136
+ }).user;
137
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('textbox'))];
138
+ case 1:
139
+ _a.sent();
140
+ expect(react_2.screen.getByRole('button', { name: 'Reply' })).toBeInTheDocument();
141
+ return [2 /*return*/];
142
+ }
143
+ });
144
+ }); });
145
+ it('should render Comment button correctly if comment is undefined', function () { return __awaiter(void 0, void 0, void 0, function () {
146
+ var user;
147
+ return __generator(this, function (_a) {
148
+ switch (_a.label) {
149
+ case 0:
150
+ user = setUp({
151
+ props: createProps()
152
+ }).user;
153
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('textbox'))];
154
+ case 1:
155
+ _a.sent();
156
+ expect(react_2.screen.getByRole('button', { name: 'Comment' })).toBeInTheDocument();
157
+ return [2 /*return*/];
158
+ }
159
+ });
160
+ }); });
150
161
  it('should render buttons if value is not empty string', function () {
151
162
  var getCommentState = jest.fn().mockImplementation(function () { return ({
152
163
  value: 'value',
153
164
  plainTextValue: 'value',
154
165
  mentions: []
155
166
  }); });
156
- mockCollaborationContext({ getCommentState: getCommentState });
157
- var component = setUp(createProps(createCommentObject({ status: 'open' })));
158
- expect(component.find('.buttons').length).toBeTruthy();
159
- });
160
- it('should render buttons if input is focused', function () {
161
- mockCollaborationContext();
162
- var component = setUp(createProps(createCommentObject({ status: 'open' })));
163
- expect(component.find('.buttons')).toHaveLength(0);
164
- component.find(TextFieldWithMentions_1.TextFieldWithMentions).find('textarea').simulate('focus');
165
- expect(component.find('.buttons').length).toBeTruthy();
166
- component.find(TextFieldWithMentions_1.TextFieldWithMentions).find('textarea').simulate('blur');
167
- expect(component.find('.buttons')).toHaveLength(0);
168
- });
169
- it('should disable Reply or Comment button if value is empty', function () {
170
- var getCommentState = jest.fn().mockImplementation(function () { return ({
171
- value: 'value',
172
- plainTextValue: 'value',
173
- mentions: []
174
- }); });
175
- mockCollaborationContext({ getCommentState: getCommentState });
176
- var component = setUp(createProps(createCommentObject({ status: 'open' })));
177
- component.find(TextFieldWithMentions_1.TextFieldWithMentions).find('textarea').simulate('focus');
178
- var buttons = component.find('.buttons').last();
179
- expect(buttons.childAt(0).prop('disabled')).toBe(false);
180
- });
181
- it('should disable Cancel button if loading is "true"', function () {
182
- mockCollaborationContext({ sending: true });
183
- var component = setUp(createProps(createCommentObject({ status: 'open' })));
184
- component.find(TextFieldWithMentions_1.TextFieldWithMentions).find('textarea').simulate('focus');
185
- var buttons = component.find('.buttons').last();
186
- expect(buttons.childAt(1).prop('disabled')).toBe(true);
167
+ setUp({
168
+ props: createProps(),
169
+ collaborationContextValue: createCollaborationContext({ getCommentState: getCommentState })
170
+ });
171
+ expect(react_2.screen.queryAllByRole('button')).toHaveLength(2);
187
172
  });
188
- it('should disable Reply or Comment button if loading is "true"', function () {
189
- mockCollaborationContext({ sending: true });
190
- var component = setUp(createProps(createCommentObject({ status: 'open' })));
191
- component.find(TextFieldWithMentions_1.TextFieldWithMentions).find('textarea').simulate('focus');
192
- var buttons = component.find('.buttons').last();
193
- expect(buttons.childAt(0).prop('disabled')).toBe(true);
173
+ it('should render buttons if input is focused', function () { return __awaiter(void 0, void 0, void 0, function () {
174
+ var user;
175
+ return __generator(this, function (_a) {
176
+ switch (_a.label) {
177
+ case 0:
178
+ user = setUp({
179
+ props: createProps(createCommentObject({ status: 'open' }))
180
+ }).user;
181
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('textbox'))];
182
+ case 1:
183
+ _a.sent();
184
+ expect(react_2.screen.queryAllByRole('button')).toHaveLength(2);
185
+ return [4 /*yield*/, user_event_1.default.tab()];
186
+ case 2:
187
+ _a.sent();
188
+ expect(react_2.screen.queryAllByRole('button')).toHaveLength(0);
189
+ return [2 /*return*/];
190
+ }
191
+ });
192
+ }); });
193
+ it('should disable Reply or Comment button if value is empty', function () { return __awaiter(void 0, void 0, void 0, function () {
194
+ var getCommentState, user;
195
+ return __generator(this, function (_a) {
196
+ switch (_a.label) {
197
+ case 0:
198
+ getCommentState = jest.fn().mockImplementation(function () { return ({
199
+ value: '',
200
+ plainTextValue: '',
201
+ mentions: []
202
+ }); });
203
+ user = setUp({
204
+ props: createProps(createCommentObject({ status: 'open' })),
205
+ collaborationContextValue: createCollaborationContext({ getCommentState: getCommentState })
206
+ }).user;
207
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('textbox'))];
208
+ case 1:
209
+ _a.sent();
210
+ expect(react_2.screen.queryByRole('button', { name: 'Reply' })).toBeDisabled();
211
+ return [2 /*return*/];
212
+ }
213
+ });
214
+ }); });
215
+ it('should disable Cancel button if sending is "true"', function () { return __awaiter(void 0, void 0, void 0, function () {
216
+ return __generator(this, function (_a) {
217
+ setUp({
218
+ props: createProps(createCommentObject({ status: 'open' })),
219
+ collaborationContextValue: createCollaborationContext({ sending: true })
220
+ });
221
+ react_2.fireEvent.focus(react_2.screen.getByRole('textbox'));
222
+ expect(react_2.screen.queryByRole('button', { name: 'Cancel' })).toBeDisabled();
223
+ return [2 /*return*/];
224
+ });
225
+ }); });
226
+ it('should disable Reply or Comment button if sending is "true"', function () {
227
+ setUp({
228
+ props: createProps(createCommentObject({ status: 'open' })),
229
+ collaborationContextValue: createCollaborationContext({ sending: true })
230
+ });
231
+ react_2.fireEvent.focus(react_2.screen.getByRole('textbox'));
232
+ expect(react_2.screen.queryByRole('button', { name: 'Reply' })).toBeDisabled();
194
233
  });
195
234
  it('should pass correct default value to TextFieldWithMentions if isEditingComment equals true', function () {
196
- mockCollaborationContext();
197
235
  var comment = {
198
236
  content: 'Hello +denis',
199
- namedUsers: ['denis'],
200
- commentId: 'commentId',
201
- status: 'open'
237
+ namedUsers: ['denis']
202
238
  };
203
- var component = setUp(createProps(comment, { isEditingComment: true }));
204
- expect(component.find(TextFieldWithMentions_1.TextFieldWithMentions).prop('value')).toBe('Hello @[denis](denis)');
239
+ setUp({
240
+ props: createProps(createCommentObject(comment), { isEditingComment: true })
241
+ });
242
+ expect(react_2.screen.getByPlaceholderText('Reply...')).toHaveTextContent('Hello +denis');
205
243
  });
206
244
  it('should pass correct default value to TextFieldWithMentions if isEditingReply equals true', function () {
207
- mockCollaborationContext();
208
245
  var reply = {
209
246
  content: 'Hello +ainsteisha',
210
247
  namedUsers: ['ainsteisha'],
211
248
  replyId: 'replyId'
212
249
  };
213
- var component = setUp(createProps(createCommentObject(), { isEditingReply: true, reply: reply }));
214
- expect(component.find(TextFieldWithMentions_1.TextFieldWithMentions).prop('value')).toBe('Hello @[ainsteisha](ainsteisha)');
250
+ setUp({
251
+ props: createProps(createCommentObject(), { isEditingReply: true, reply: reply })
252
+ });
253
+ expect(react_2.screen.getByPlaceholderText('Reply...')).toHaveTextContent('Hello +ainsteisha');
215
254
  });
216
255
  it('should pass correct default value to TextFieldWithMentions if isEditingReply and isEditingComment equals false', function () {
217
- mockCollaborationContext();
218
- var component = setUp(createProps(createCommentObject()));
219
- expect(component.find(TextFieldWithMentions_1.TextFieldWithMentions).prop('value')).toBe('');
220
- });
221
- it('handleChange handler should work correctly', function () {
222
- mockCollaborationContext();
223
- var component = setUp(createProps());
224
- var onChange = component.find(TextFieldWithMentions_1.TextFieldWithMentions).prop('onChange');
225
- var value = 'Hello @[+vyacheslav](vyacheslav)';
226
- var plainTextValue = 'Hello +vyacheslav';
227
- var mentions = ['vyacheslav'];
228
- (0, test_utils_1.act)(function () {
229
- onChange === null || onChange === void 0 ? void 0 : onChange(value, plainTextValue, mentions);
256
+ setUp({
257
+ props: createProps(createCommentObject())
230
258
  });
231
- expect(updateCommentState).toHaveBeenCalledWith('uri', 'comment/new', { value: value, plainTextValue: plainTextValue, mentions: mentions });
259
+ expect(react_2.screen.getByPlaceholderText('Reply...')).toHaveTextContent('');
232
260
  });
261
+ it('handleChange handler should work correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
262
+ var value, plainTextValue, mentions, getCommentState, updateCommentState, user;
263
+ return __generator(this, function (_a) {
264
+ switch (_a.label) {
265
+ case 0:
266
+ value = 'Hello @[vyacheslav](vyacheslav)';
267
+ plainTextValue = 'Hello +vyacheslav';
268
+ mentions = ['vyacheslav'];
269
+ getCommentState = jest.fn().mockImplementation(function () { return ({
270
+ value: value,
271
+ plainTextValue: plainTextValue,
272
+ mentions: mentions
273
+ }); });
274
+ updateCommentState = jest.fn();
275
+ user = setUp({
276
+ props: createProps(),
277
+ collaborationContextValue: createCollaborationContext({ getCommentState: getCommentState, updateCommentState: updateCommentState })
278
+ }).user;
279
+ return [4 /*yield*/, user.type(react_2.screen.getByRole('textbox'), ' ')];
280
+ case 1:
281
+ _a.sent();
282
+ expect(updateCommentState).toHaveBeenCalledWith('uri', 'comment/new', {
283
+ value: "".concat(value, " "),
284
+ plainTextValue: "".concat(plainTextValue, " "),
285
+ mentions: mentions
286
+ });
287
+ return [2 /*return*/];
288
+ }
289
+ });
290
+ }); });
233
291
  it('handleSubmit handler should work correctly if comment exists and last status is "open"', function () { return __awaiter(void 0, void 0, void 0, function () {
234
- var getCommentState, component, buttons, preventDefault;
292
+ var getCommentState, clearCommentState, createReply, user;
235
293
  return __generator(this, function (_a) {
236
294
  switch (_a.label) {
237
295
  case 0:
238
296
  getCommentState = jest.fn().mockImplementation(function () { return ({
239
- value: 'Hello @[+vyacheslav](vyacheslav)',
297
+ value: 'Hello @[vyacheslav](vyacheslav)',
240
298
  plainTextValue: 'Hello +vyacheslav',
241
299
  mentions: ['vyacheslav']
242
300
  }); });
243
- mockCollaborationContext({ getCommentState: getCommentState });
244
- component = setUp(createProps(createCommentObject({ status: 'open' })));
245
- buttons = component.find('.buttons').last();
246
- buttons.childAt(0).find('button').simulate('click');
247
- preventDefault = jest.fn();
248
- component.find('.form').simulate('submit', { preventDefault: preventDefault });
249
- expect(preventDefault).toHaveBeenCalled();
301
+ clearCommentState = jest.fn();
302
+ createReply = jest.fn().mockReturnValue(new Promise(function (res) { return res(); }));
303
+ user = setUp({
304
+ props: createProps(createCommentObject({ status: 'open' })),
305
+ collaborationContextValue: createCollaborationContext({ getCommentState: getCommentState, createReply: createReply, clearCommentState: clearCommentState })
306
+ }).user;
307
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('button', { name: 'Reply' }))];
308
+ case 1:
309
+ _a.sent();
250
310
  expect(createReply).toHaveBeenCalledWith({
251
311
  content: 'Hello +vyacheslav',
252
312
  namedUsers: ['vyacheslav'],
@@ -254,36 +314,30 @@ describe('SendMessageArea tests', function () {
254
314
  action: 'none',
255
315
  uri: 'uri'
256
316
  });
257
- return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
258
- return __generator(this, function (_a) {
259
- component.update();
260
- return [2 /*return*/];
261
- });
262
- }); })];
263
- case 1:
264
- _a.sent();
265
317
  expect(clearCommentState).toHaveBeenCalledWith('uri', 'comment/commentId/reply/new');
266
318
  return [2 /*return*/];
267
319
  }
268
320
  });
269
321
  }); });
270
322
  it('handleSubmit handler should work correctly if comment exists and last status is "resolved"', function () { return __awaiter(void 0, void 0, void 0, function () {
271
- var getCommentState, component, buttons, preventDefault;
323
+ var getCommentState, createReply, clearCommentState, user;
272
324
  return __generator(this, function (_a) {
273
325
  switch (_a.label) {
274
326
  case 0:
275
327
  getCommentState = jest.fn().mockImplementation(function () { return ({
276
- value: 'Hello @[+vyacheslav](vyacheslav)',
328
+ value: 'Hello @[vyacheslav](vyacheslav)',
277
329
  plainTextValue: 'Hello +vyacheslav',
278
330
  mentions: ['vyacheslav']
279
331
  }); });
280
- mockCollaborationContext({ getCommentState: getCommentState });
281
- component = setUp(createProps(createCommentObject({ status: 'resolved' })));
282
- buttons = component.find('.buttons').last();
283
- buttons.childAt(0).find('button').simulate('click');
284
- preventDefault = jest.fn();
285
- component.find('.form').simulate('submit', { preventDefault: preventDefault });
286
- expect(preventDefault).toHaveBeenCalled();
332
+ createReply = jest.fn().mockReturnValue(new Promise(function (res) { return res(); }));
333
+ clearCommentState = jest.fn();
334
+ user = setUp({
335
+ props: createProps(createCommentObject({ status: 'resolved' })),
336
+ collaborationContextValue: createCollaborationContext({ getCommentState: getCommentState, createReply: createReply, clearCommentState: clearCommentState })
337
+ }).user;
338
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('button', { name: 'Reply' }))];
339
+ case 1:
340
+ _a.sent();
287
341
  expect(createReply).toHaveBeenCalledWith({
288
342
  content: 'Hello +vyacheslav',
289
343
  namedUsers: ['vyacheslav'],
@@ -291,99 +345,86 @@ describe('SendMessageArea tests', function () {
291
345
  action: 'reopen',
292
346
  uri: 'uri'
293
347
  });
294
- return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
295
- return __generator(this, function (_a) {
296
- component.update();
297
- return [2 /*return*/];
298
- });
299
- }); })];
300
- case 1:
301
- _a.sent();
302
348
  expect(clearCommentState).toHaveBeenCalledWith('uri', 'comment/commentId/reply/new');
303
349
  return [2 /*return*/];
304
350
  }
305
351
  });
306
352
  }); });
307
353
  it('handleSubmit handler should work correctly if comment does not exist', function () { return __awaiter(void 0, void 0, void 0, function () {
308
- var getCommentState, component, buttons, preventDefault;
354
+ var getCommentState, clearCommentState, createComment, user;
309
355
  return __generator(this, function (_a) {
310
356
  switch (_a.label) {
311
357
  case 0:
312
358
  getCommentState = jest.fn().mockImplementation(function () { return ({
313
- value: 'Hello @[+vyacheslav](vyacheslav)',
359
+ value: 'Hello @[vyacheslav](vyacheslav)',
314
360
  plainTextValue: 'Hello +vyacheslav',
315
361
  mentions: ['vyacheslav']
316
362
  }); });
317
- mockCollaborationContext({ getCommentState: getCommentState });
318
- component = setUp(createProps());
319
- buttons = component.find('.buttons').last();
320
- buttons.childAt(0).find('button').simulate('click');
321
- preventDefault = jest.fn();
322
- component.find('.form').simulate('submit', { preventDefault: preventDefault });
323
- expect(preventDefault).toHaveBeenCalled();
363
+ clearCommentState = jest.fn();
364
+ createComment = jest.fn().mockReturnValue(new Promise(function (res) { return res(); }));
365
+ user = setUp({
366
+ props: createProps(),
367
+ collaborationContextValue: createCollaborationContext({ getCommentState: getCommentState, createComment: createComment, clearCommentState: clearCommentState })
368
+ }).user;
369
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('button', { name: 'Comment' }))];
370
+ case 1:
371
+ _a.sent();
324
372
  expect(createComment).toHaveBeenCalledWith({
325
373
  content: 'Hello +vyacheslav',
326
374
  namedUsers: ['vyacheslav'],
327
- objectType: 'objectType',
375
+ objectType: 'entity',
328
376
  uri: 'uri',
329
377
  relatedObjectUris: ['entities/13JKIKAz']
330
378
  });
331
- return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
332
- return __generator(this, function (_a) {
333
- component.update();
334
- return [2 /*return*/];
335
- });
336
- }); })];
379
+ expect(clearCommentState).toHaveBeenCalledWith('uri', 'comment/new');
380
+ return [2 /*return*/];
381
+ }
382
+ });
383
+ }); });
384
+ it('should render Edit button if isEditingComment prop is true', function () { return __awaiter(void 0, void 0, void 0, function () {
385
+ var user;
386
+ return __generator(this, function (_a) {
387
+ switch (_a.label) {
388
+ case 0:
389
+ user = setUp({
390
+ props: createProps(createCommentObject({ status: 'resolved' }), { isEditingComment: true })
391
+ }).user;
392
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('textbox'))];
337
393
  case 1:
338
394
  _a.sent();
339
- expect(clearCommentState).toHaveBeenCalledWith('uri', 'comment/new');
395
+ expect(react_2.screen.queryByRole('button', { name: 'Edit' })).toBeInTheDocument();
340
396
  return [2 /*return*/];
341
397
  }
342
398
  });
343
399
  }); });
344
- it('should render Edit button if isEditingComment prop is true', function () {
345
- mockCollaborationContext();
346
- var component = setUp(createProps(createCommentObject({ status: 'resolved' }), { isEditingComment: true }));
347
- component.find(TextFieldWithMentions_1.TextFieldWithMentions).find('textarea').simulate('focus');
348
- var buttons = component.find('.buttons').last();
349
- expect(buttons.childAt(0).text()).toBe('Edit');
350
- });
351
400
  it('submitting should work correctly if comment is editing', function () { return __awaiter(void 0, void 0, void 0, function () {
352
- var onCancel, comment, component, buttons, preventDefault;
401
+ var onCancel, editComment, clearCommentState, comment, user;
353
402
  return __generator(this, function (_a) {
354
403
  switch (_a.label) {
355
404
  case 0:
356
- mockCollaborationContext();
357
405
  onCancel = jest.fn();
406
+ editComment = jest.fn().mockReturnValue(new Promise(function (res) { return res(); }));
407
+ clearCommentState = jest.fn();
358
408
  comment = {
359
409
  content: 'Hello +denis',
360
- namedUsers: ['denis'],
361
- commentId: 'commentId',
362
- status: 'open'
410
+ namedUsers: ['denis']
363
411
  };
364
- component = setUp(createProps(comment, { isEditingComment: true, onCancel: onCancel }));
365
- buttons = component.find('.buttons').last();
366
- buttons.childAt(0).find('button').simulate('click');
367
- preventDefault = jest.fn();
368
- component.find('.form').simulate('submit', { preventDefault: preventDefault });
369
- expect(preventDefault).toHaveBeenCalled();
370
- expect(editCommentWithResolve).toHaveBeenCalledWith({
412
+ user = setUp({
413
+ props: createProps(createCommentObject(comment), { isEditingComment: true, onCancel: onCancel }),
414
+ collaborationContextValue: createCollaborationContext({ editComment: editComment, clearCommentState: clearCommentState })
415
+ }).user;
416
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('button', { name: 'Edit' }))];
417
+ case 1:
418
+ _a.sent();
419
+ expect(editComment).toHaveBeenCalledWith({
371
420
  content: 'Hello +denis',
372
421
  namedUsers: ['denis'],
373
422
  commentId: 'commentId',
374
423
  uri: 'uri',
375
424
  relatedObjectUris: ['entities/13JKIKAz'],
376
- replies: undefined,
377
- objectType: 'objectType'
425
+ replies: [],
426
+ objectType: 'entity'
378
427
  });
379
- return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
380
- return __generator(this, function (_a) {
381
- component.update();
382
- return [2 /*return*/];
383
- });
384
- }); })];
385
- case 1:
386
- _a.sent();
387
428
  expect(clearCommentState).toHaveBeenCalledWith('uri', 'comment/commentId');
388
429
  expect(onCancel).toHaveBeenCalledTimes(1);
389
430
  return [2 /*return*/];
@@ -391,41 +432,35 @@ describe('SendMessageArea tests', function () {
391
432
  });
392
433
  }); });
393
434
  it('submitting should work correctly if reply is editing', function () { return __awaiter(void 0, void 0, void 0, function () {
394
- var onCancel, reply, component, buttons, preventDefault;
435
+ var onCancel, editReply, clearCommentState, reply, user;
395
436
  return __generator(this, function (_a) {
396
437
  switch (_a.label) {
397
438
  case 0:
398
- mockCollaborationContext();
399
439
  onCancel = jest.fn();
440
+ editReply = jest.fn().mockReturnValue(new Promise(function (res) { return res(); }));
441
+ clearCommentState = jest.fn();
400
442
  reply = {
401
443
  content: 'Hello +ainsteisha',
402
444
  namedUsers: ['ainsteisha'],
403
445
  replyId: 'replyId'
404
446
  };
405
- component = setUp(createProps(createCommentObject({ status: 'open' }), {
406
- isEditingReply: true,
407
- onCancel: onCancel,
408
- reply: reply
409
- }));
410
- buttons = component.find('.buttons').last();
411
- buttons.childAt(0).find('button').simulate('click');
412
- preventDefault = jest.fn();
413
- component.find('.form').simulate('submit', { preventDefault: preventDefault });
414
- expect(preventDefault).toHaveBeenCalled();
447
+ user = setUp({
448
+ props: createProps(createCommentObject(), {
449
+ isEditingReply: true,
450
+ onCancel: onCancel,
451
+ reply: reply
452
+ }),
453
+ collaborationContextValue: createCollaborationContext({ editReply: editReply, clearCommentState: clearCommentState })
454
+ }).user;
455
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('button', { name: 'Edit' }))];
456
+ case 1:
457
+ _a.sent();
415
458
  expect(editReply).toHaveBeenCalledWith({
416
459
  content: reply.content,
417
460
  namedUsers: reply.namedUsers,
418
461
  commentId: 'commentId',
419
462
  replyId: reply.replyId
420
463
  });
421
- return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
422
- return __generator(this, function (_a) {
423
- component.update();
424
- return [2 /*return*/];
425
- });
426
- }); })];
427
- case 1:
428
- _a.sent();
429
464
  expect(clearCommentState).toHaveBeenCalledWith('uri', 'comment/commentId/reply/replyId');
430
465
  expect(onCancel).toHaveBeenCalledTimes(1);
431
466
  return [2 /*return*/];
@@ -433,30 +468,28 @@ describe('SendMessageArea tests', function () {
433
468
  });
434
469
  }); });
435
470
  it('if received error after send request, do not need to clear text input', function () { return __awaiter(void 0, void 0, void 0, function () {
436
- var editCommentWithReject, getCommentState, onCancel, component, buttons, preventDefault;
471
+ var editCommentWithReject, clearCommentState, getCommentState, onCancel, user;
437
472
  return __generator(this, function (_a) {
438
473
  switch (_a.label) {
439
474
  case 0:
440
475
  editCommentWithReject = jest.fn().mockRejectedValue('error');
476
+ clearCommentState = jest.fn();
441
477
  getCommentState = jest.fn().mockImplementation(function () { return ({
442
478
  value: 'Hello @[+vyacheslav](vyacheslav)',
443
479
  plainTextValue: 'Hello +vyacheslav',
444
480
  mentions: ['vyacheslav']
445
481
  }); });
446
- mockCollaborationContext({ sending: false, editComment: editCommentWithReject, getCommentState: getCommentState });
447
482
  onCancel = jest.fn();
448
- component = setUp(createProps(createCommentObject({ status: 'open' }), { isEditingComment: true, onCancel: onCancel }));
449
- buttons = component.find('.buttons').last();
450
- buttons.childAt(0).find('button').simulate('click');
451
- preventDefault = jest.fn();
452
- component.find('.form').simulate('submit', { preventDefault: preventDefault });
453
- expect(preventDefault).toHaveBeenCalled();
454
- return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
455
- return __generator(this, function (_a) {
456
- component.update();
457
- return [2 /*return*/];
458
- });
459
- }); })];
483
+ user = setUp({
484
+ props: createProps(createCommentObject(), { isEditingComment: true, onCancel: onCancel }),
485
+ collaborationContextValue: createCollaborationContext({
486
+ sending: false,
487
+ editComment: editCommentWithReject,
488
+ getCommentState: getCommentState,
489
+ clearCommentState: clearCommentState
490
+ })
491
+ }).user;
492
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('button', { name: 'Edit' }))];
460
493
  case 1:
461
494
  _a.sent();
462
495
  expect(clearCommentState).not.toHaveBeenCalled();
@@ -465,13 +498,21 @@ describe('SendMessageArea tests', function () {
465
498
  }
466
499
  });
467
500
  }); });
468
- it('should call onCancel if click cancel button', function () {
469
- mockCollaborationContext();
470
- var onCancel = jest.fn();
471
- var component = setUp(createProps(createCommentObject({ status: 'open' }), { isEditingComment: true, onCancel: onCancel }));
472
- component.find(TextFieldWithMentions_1.TextFieldWithMentions).find('textarea').simulate('focus');
473
- var buttons = component.find('.buttons').last();
474
- buttons.childAt(1).find('button').simulate('click');
475
- expect(onCancel).toHaveBeenCalledTimes(1);
476
- });
501
+ it('should call onCancel if click cancel button', function () { return __awaiter(void 0, void 0, void 0, function () {
502
+ var onCancel, user;
503
+ return __generator(this, function (_a) {
504
+ switch (_a.label) {
505
+ case 0:
506
+ onCancel = jest.fn();
507
+ user = setUp({
508
+ props: createProps(createCommentObject(), { isEditingComment: true, onCancel: onCancel })
509
+ }).user;
510
+ return [4 /*yield*/, user.click(react_2.screen.getByRole('button', { name: 'Cancel' }))];
511
+ case 1:
512
+ _a.sent();
513
+ expect(onCancel).toHaveBeenCalledTimes(1);
514
+ return [2 /*return*/];
515
+ }
516
+ });
517
+ }); });
477
518
  });