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