Skip to content

Commit d841c6e

Browse files
authored
Chat - group content and bubble elements should be attached to DOM before template render (T1304688)
1 parent 7fe8733 commit d841c6e

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

packages/devextreme/js/__internal/ui/chat/messagegroup.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,10 @@ class MessageGroup extends Widget<Properties> {
112112

113113
_renderMessageBubble(message: Message): void {
114114
const $bubble = $('<div>')
115-
.data(MESSAGE_DATA_KEY, message);
115+
.data(MESSAGE_DATA_KEY, message)
116+
.appendTo(this._$messageBubbleContainer);
116117

117118
this._createComponent($bubble, MessageBubble, this._getMessageBubbleOptions(message));
118-
119-
this._$messageBubbleContainer.append($bubble);
120119
}
121120

122121
_getMessageBubbleOptions(message: Message): MessageBubbleProperties {
@@ -136,13 +135,13 @@ class MessageGroup extends Widget<Properties> {
136135
}
137136

138137
_renderMessageBubbles(items: Message[]): void {
139-
this._$messageBubbleContainer = $('<div>').addClass(CHAT_MESSAGEGROUP_CONTENT_CLASS);
138+
this._$messageBubbleContainer = $('<div>')
139+
.addClass(CHAT_MESSAGEGROUP_CONTENT_CLASS)
140+
.appendTo(this.element());
140141

141142
items.forEach((message) => {
142143
this._renderMessageBubble(message);
143144
});
144-
145-
this._$messageBubbleContainer.appendTo(this.element());
146145
}
147146

148147
_renderMessageGroupInformation(message: Message): void {

packages/devextreme/testing/tests/DevExpress.ui.widgets/chatParts/messageGroup.tests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import dateLocalization from 'common/core/localization/date';
77
const AVATAR_CLASS = 'dx-avatar';
88
const CHAT_MESSAGEGROUP_TIME_CLASS = 'dx-chat-messagegroup-time';
99
const CHAT_MESSAGEBUBBLE_CLASS = 'dx-chat-messagebubble';
10+
const CHAT_MESSAGEGROUP_CONTENT_CLASS = 'dx-chat-messagegroup-content';
1011
const CHAT_MESSAGEGROUP_AUTHOR_NAME_CLASS = 'dx-chat-messagegroup-author-name';
1112

1213
const getStringTime = (time) => {
@@ -305,6 +306,21 @@ QUnit.module('MessageGroup', moduleConfig, () => {
305306
assert.strictEqual(messageTemplate.callCount, 1, 'messageTemplate function was called on bubble template render');
306307
assert.deepEqual(messageTemplate.lastCall.args[0], message, 'messageTemplate function was called with correct data');
307308
});
309+
310+
QUnit.test('Group content and bubble elements should be attached to DOM before template is rendrered (T1304688)', function(assert) {
311+
assert.expect(2);
312+
313+
this.reinit({
314+
items: [{ text: 'some text' }],
315+
messageTemplate: () => {
316+
const $groupContent = this.$element.find(`.${CHAT_MESSAGEGROUP_CONTENT_CLASS}`);
317+
const $bubble = this.$element.find(`.${CHAT_MESSAGEBUBBLE_CLASS}`);
318+
319+
assert.strictEqual($groupContent.length, 1, 'group content element exists');
320+
assert.strictEqual($bubble.length, 1, 'bubble element exists');
321+
},
322+
});
323+
});
308324
});
309325
});
310326

0 commit comments

Comments
 (0)