|
1 | 1 | import $ from 'jquery'; |
2 | 2 |
|
| 3 | +import Button from 'ui/button'; |
3 | 4 | import Chat from 'ui/chat'; |
4 | 5 | import MessageList, { |
5 | 6 | CHAT_MESSAGELIST_CONTEXT_MENU_CLASS |
6 | 7 | } from '__internal/ui/chat/messagelist'; |
7 | 8 | import ContextMenu, { |
8 | 9 | DX_MENU_ITEM_CLASS, |
9 | 10 | } from '__internal/ui/context_menu/context_menu'; |
| 11 | +import FileUploader, { |
| 12 | + FILEUPLOADER_CLASS, |
| 13 | +} from '__internal/ui/file_uploader/file_uploader'; |
10 | 14 | import { |
11 | 15 | FOCUSED_STATE_CLASS, |
12 | 16 | WIDGET_CLASS, |
@@ -38,7 +42,10 @@ import { BUTTON_CLASS } from '__internal/ui/button/button'; |
38 | 42 | import { CHAT_FILE_CLASS } from '__internal/ui/chat/file_view/file'; |
39 | 43 |
|
40 | 44 | import MessageBubble from '__internal/ui/chat/messagebubble'; |
41 | | -import ChatTextArea, { CHAT_TEXTAREA_CLASS } from '__internal/ui/chat/message_box/chat_text_area'; |
| 45 | +import ChatTextArea, { |
| 46 | + CHAT_TEXTAREA_CLASS, |
| 47 | + CHAT_TEXT_AREA_ATTACH_BUTTON, |
| 48 | +} from '__internal/ui/chat/message_box/chat_text_area'; |
42 | 49 |
|
43 | 50 | const CHAT_MESSAGEGROUP_CLASS = 'dx-chat-messagegroup'; |
44 | 51 | const CHAT_MESSAGELIST_CLASS = 'dx-chat-messagelist'; |
@@ -123,6 +130,8 @@ const moduleConfig = { |
123 | 130 | this.getEditingPreview = () => this.$element.find(`.${CHAT_EDITING_PREVIEW_CLASS}`); |
124 | 131 | this.getCancelEditingButton = () => this.$element.find(`.${CHAT_EDITING_PREVIEW_CANCEL_BUTTON_CLASS}`); |
125 | 132 | this.getMessageListEmptyView = () => this.$element.find(`.${CHAT_MESSAGELIST_EMPTY_VIEW_CLASS}`); |
| 133 | + this.getFileUploader = () => FileUploader.getInstance(this.$element.find(`.${FILEUPLOADER_CLASS}`)); |
| 134 | + this.getAttachButton = () => Button.getInstance(this.$element.find(`.${CHAT_TEXT_AREA_ATTACH_BUTTON}`)); |
126 | 135 |
|
127 | 136 | init(); |
128 | 137 | }, |
@@ -1227,6 +1236,95 @@ QUnit.module('Chat', () => { |
1227 | 1236 | assert.strictEqual(this.textArea.option('value'), 'b', 'input contains editing message text'); |
1228 | 1237 | assert.strictEqual(this.$textArea.hasClass(FOCUSED_STATE_CLASS), true, 'input is focused'); |
1229 | 1238 | }); |
| 1239 | + |
| 1240 | + QUnit.testInActiveWindow('attach button should be hidden after editing is started', function(assert) { |
| 1241 | + this.reinit({ |
| 1242 | + items: [{ text: 'f', author: userSecond }], |
| 1243 | + focusStateEnabled: true, |
| 1244 | + user: userSecond, |
| 1245 | + editing: { |
| 1246 | + allowUpdating: true |
| 1247 | + }, |
| 1248 | + fileUploaderOptions: {}, |
| 1249 | + }); |
| 1250 | + const attachButton = this.getAttachButton(); |
| 1251 | + assert.strictEqual(attachButton.option('visible'), true, 'attach button is visible'); |
| 1252 | + |
| 1253 | + const $bubbles = this.getBubbles(); |
| 1254 | + $bubbles.eq(0).trigger('dxcontextmenu'); |
| 1255 | + |
| 1256 | + const $editButton = this.getContextMenuItems().eq(0); |
| 1257 | + $editButton.trigger('dxclick'); |
| 1258 | + |
| 1259 | + assert.strictEqual(attachButton.option('visible'), false, 'attach button is hidden'); |
| 1260 | + }); |
| 1261 | + |
| 1262 | + QUnit.testInActiveWindow('attach button should be visible after editing is done', function(assert) { |
| 1263 | + this.reinit({ |
| 1264 | + items: [{ text: 'f', author: userSecond }], |
| 1265 | + focusStateEnabled: true, |
| 1266 | + user: userSecond, |
| 1267 | + editing: { |
| 1268 | + allowUpdating: true |
| 1269 | + }, |
| 1270 | + fileUploaderOptions: {}, |
| 1271 | + }); |
| 1272 | + const $bubbles = this.getBubbles(); |
| 1273 | + $bubbles.eq(0).trigger('dxcontextmenu'); |
| 1274 | + |
| 1275 | + const $editButton = this.getContextMenuItems().eq(0); |
| 1276 | + $editButton.trigger('dxclick'); |
| 1277 | + this.$sendButton.trigger('dxclick'); |
| 1278 | + |
| 1279 | + const attachButton = this.getAttachButton(); |
| 1280 | + |
| 1281 | + assert.strictEqual(attachButton.option('visible'), true, 'attach button is visible'); |
| 1282 | + }); |
| 1283 | + |
| 1284 | + QUnit.testInActiveWindow('attach button should be visible after editing is canceled', function(assert) { |
| 1285 | + this.reinit({ |
| 1286 | + items: [{ text: 'f', author: userSecond }], |
| 1287 | + focusStateEnabled: true, |
| 1288 | + user: userSecond, |
| 1289 | + editing: { |
| 1290 | + allowUpdating: true |
| 1291 | + }, |
| 1292 | + fileUploaderOptions: {}, |
| 1293 | + }); |
| 1294 | + const $bubbles = this.getBubbles(); |
| 1295 | + $bubbles.eq(0).trigger('dxcontextmenu'); |
| 1296 | + |
| 1297 | + const $editButton = this.getContextMenuItems().eq(0); |
| 1298 | + $editButton.trigger('dxclick'); |
| 1299 | + this.getCancelEditingButton().trigger('dxclick'); |
| 1300 | + |
| 1301 | + const attachButton = this.getAttachButton(); |
| 1302 | + |
| 1303 | + assert.strictEqual(attachButton.option('visible'), true, 'attach button is visible'); |
| 1304 | + }); |
| 1305 | + |
| 1306 | + QUnit.testInActiveWindow('fileUploader should reset value after message editing is started', function(assert) { |
| 1307 | + this.reinit({ |
| 1308 | + items: [{ text: 'f', author: userSecond }], |
| 1309 | + focusStateEnabled: true, |
| 1310 | + user: userSecond, |
| 1311 | + editing: { |
| 1312 | + allowUpdating: true |
| 1313 | + }, |
| 1314 | + fileUploaderOptions: {}, |
| 1315 | + }); |
| 1316 | + |
| 1317 | + const fileUploader = this.getFileUploader(); |
| 1318 | + fileUploader.option('value', [{ name: 'fakefile.png', size: 123 }]); |
| 1319 | + |
| 1320 | + const $bubbles = this.getBubbles(); |
| 1321 | + $bubbles.eq(0).trigger('dxcontextmenu'); |
| 1322 | + |
| 1323 | + const $editButton = this.getContextMenuItems().eq(0); |
| 1324 | + $editButton.trigger('dxclick'); |
| 1325 | + |
| 1326 | + assert.deepEqual(fileUploader.option('value'), []); |
| 1327 | + }); |
1230 | 1328 | }); |
1231 | 1329 |
|
1232 | 1330 | QUnit.module('Events', () => { |
|
0 commit comments