Skip to content

Commit

Permalink
fix added test scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeniyKiyashko committed Nov 10, 2024
1 parent b5721fd commit e89c8ea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
17 changes: 12 additions & 5 deletions packages/devextreme/js/__internal/ui/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
TypingStartEvent as MessageBoxTypingStartEvent,
} from './messagebox';
import MessageBox from './messagebox';
import type { Change, Properties as MessageListProperties } from './messagelist';
import type { Change, MessageTemplate, Properties as MessageListProperties } from './messagelist';
import MessageList from './messagelist';

const CHAT_CLASS = 'dx-chat';
Expand Down Expand Up @@ -138,7 +138,6 @@ class Chat extends Widget<Properties> {
showAvatar = false,
showUserName = false,
showMessageTimestamp = false,
messageTemplate,
dayHeaderFormat,
messageTimestampFormat,
typingUsers = [],
Expand All @@ -151,6 +150,7 @@ class Chat extends Widget<Properties> {
const options: MessageListProperties = {
items,
currentUserId,
messageTemplate: this._getMessageTemplate(),
showDayHeaders,
showAvatar,
showUserName,
Expand All @@ -161,8 +161,13 @@ class Chat extends Widget<Properties> {
isLoading,
};

return options;
}

_getMessageTemplate(): MessageTemplate {
const { messageTemplate } = this.option();
if (messageTemplate) {
options.messageTemplate = (message, $container): void => {
return (message, $container): void => {
const template = this._getTemplateByOption('messageTemplate');

template.render({
Expand All @@ -175,7 +180,7 @@ class Chat extends Widget<Properties> {
};
}

return options;
return null;
}

_renderAlertList(): void {
Expand Down Expand Up @@ -341,12 +346,14 @@ class Chat extends Widget<Properties> {
case 'showMessageTimestamp':
this._messageList.option(name, !!value);
break;
case 'messageTemplate':
case 'dayHeaderFormat':
case 'messageTimestampFormat':
case 'typingUsers':
this._messageList.option(name, value);
break;
case 'messageTemplate':
this._messageList.option(name, this._getMessageTemplate());
break;
case 'reloadOnChange':
break;
default:
Expand Down
3 changes: 2 additions & 1 deletion packages/devextreme/js/__internal/ui/chat/messagegroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Widget from '@ts/core/widget/widget';
import Avatar from './avatar';
import type { Properties as MessageBubbleProperties } from './messagebubble';
import MessageBubble from './messagebubble';
import type { MessageTemplate } from './messagelist';

export const MESSAGE_DATA_KEY = 'dxMessageData';

Expand All @@ -32,7 +33,7 @@ export interface Properties extends WidgetOptions<MessageGroup> {
showAvatar: boolean;
showUserName: boolean;
showMessageTimestamp: boolean;
messageTemplate?: ((data: Message, messageBubbleContainer: Element) => void) | null;
messageTemplate?: MessageTemplate;
messageTimestampFormat?: Format;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/devextreme/js/__internal/ui/chat/messagelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const CHAT_LAST_MESSAGEGROUP_ALIGNMENT_END_CLASS = 'dx-chat-last-messagegroup-al
const SCROLLABLE_CONTAINER_CLASS = 'dx-scrollable-container';
export const MESSAGEGROUP_TIMEOUT = 5 * 1000 * 60;

export type MessageTemplate = ((data: Message, messageBubbleContainer: Element) => void) | null;

export interface Change {
type: 'insert' | 'update' | 'remove';
data?: DeepPartial<Message>;
Expand All @@ -59,7 +61,7 @@ export interface Properties extends WidgetOptions<MessageList> {
items: Message[];
currentUserId: number | string | undefined;
showDayHeaders: boolean;
messageTemplate?: ((data: Message, messageBubbleContainer: Element) => void) | null;
messageTemplate?: MessageTemplate;
dayHeaderFormat?: Format;
messageTimestampFormat?: Format;
typingUsers: User[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MessageBox, { TYPING_END_DELAY } from '__internal/ui/chat/messagebox';
import keyboardMock from '../../../helpers/keyboardMock.js';
import { DataSource } from 'data/data_source/data_source';
import CustomStore from 'data/custom_store';
import dataUtils from 'core/element_data';

import { isRenderer } from 'core/utils/type';

Expand Down Expand Up @@ -1157,7 +1158,7 @@ QUnit.module('Chat', () => {
assert.strictEqual(this.getBubbles().length, 3, 'message bubble count');
assert.strictEqual(this.getBubbles().eq(1).text(), newBubbleText, 'message bubble text was updated');

const messageData = data(this.getBubbles().eq(1).get(0), 'dxMessageData');
const messageData = dataUtils.data(this.getBubbles().eq(1).get(0), 'dxMessageData');

assert.deepEqual(messageData, { id: 2, text: newBubbleText }, 'message bubble data was updated');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ QUnit.module('MessageBubble', moduleConfig, () => {

assert.strictEqual(templateSpy.callCount, 1, 'template was rendered once');
assert.strictEqual(templateSpy.args[0][0], messageText, 'text argument is correct');
assert.strictEqual(templateSpy.args[0][1], this.$element.get(0), 'container element is correct');
assert.strictEqual($(templateSpy.args[0][1]).get(0), this.$element.get(0), 'container element is correct');
});

QUnit.test('default markup should be restored after resetting the template option at runtime', function(assert) {
Expand Down

0 comments on commit e89c8ea

Please sign in to comment.