Skip to content

Commit 29d55be

Browse files
author
marker dao ®
committed
feat(chat tests): Raise the tests
1 parent abd7539 commit 29d55be

4 files changed

Lines changed: 41 additions & 20 deletions

File tree

packages/devextreme/js/__internal/ui/chat/message_box/chat_text_area.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { normalizeKeyName } from '@js/common/core/events/utils/index';
12
import messageLocalization from '@js/common/core/localization/message';
23
import devices from '@js/core/devices';
34
import type { DefaultOptionsRule } from '@js/core/options/utils';
45
import type { dxElementWrapper } from '@js/core/renderer';
56
import $ from '@js/core/renderer';
67
import { getOuterHeight } from '@js/core/utils/size';
7-
import type { NativeEventInfo } from '@js/events';
8+
import type { DxEvent, NativeEventInfo } from '@js/events';
89
import type {
910
ClickEvent,
1011
InitializedEvent,
@@ -72,19 +73,30 @@ class ChatTextArea extends TextArea<Properties> {
7273
_supportedKeys(): SupportedKeys {
7374
return {
7475
...super._supportedKeys(),
75-
enter: (e): void => {
76-
if (!e?.shiftKey && this._isValuableTextEntered() && !isMobile()) {
76+
enter: (e: DxEvent<KeyboardEvent>): void => {
77+
if (this._shouldSendMessageOnEnter(e)) {
7778
e.preventDefault();
78-
this._processSendButtonActivation({
79-
component: this,
80-
element: this.element(),
81-
event: e,
82-
});
8379
}
8480
},
8581
};
8682
}
8783

84+
_enterKeyHandlerUp(e: DxEvent<KeyboardEvent>): void {
85+
super._enterKeyHandlerUp(e);
86+
87+
if (normalizeKeyName(e) !== 'enter') {
88+
return;
89+
}
90+
91+
if (this._shouldSendMessageOnEnter(e)) {
92+
this._processSendButtonActivation({
93+
component: this,
94+
element: this.element(),
95+
event: e,
96+
});
97+
}
98+
}
99+
88100
_init(): void {
89101
super._init();
90102

@@ -217,6 +229,10 @@ class ChatTextArea extends TextArea<Properties> {
217229
this._toggleButtonDisableState(true);
218230
}
219231

232+
_shouldSendMessageOnEnter(e: DxEvent<KeyboardEvent>): boolean {
233+
return !e?.shiftKey && this._isValuableTextEntered() && !isMobile();
234+
}
235+
220236
_optionChanged(args: OptionChanged<Properties>): void {
221237
const { name, value } = args;
222238

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { POPUP_CLASS } from '__internal/ui/popup/m_popup';
3838
import { BUTTON_CLASS } from '__internal/ui/button/button';
3939
import { shouldSkipOnMobile } from '../../../helpers/device.js';
4040
import MessageBubble from '__internal/ui/chat/messagebubble';
41+
import ChatTextArea from '__internal/ui/chat/message_box/chat_text_area';
4142

4243
const CHAT_MESSAGEGROUP_CLASS = 'dx-chat-messagegroup';
4344
const CHAT_MESSAGELIST_CLASS = 'dx-chat-messagelist';
@@ -96,9 +97,10 @@ const moduleConfig = {
9697
this.instance = new Chat($('#component'), options);
9798
this.$element = $(this.instance.$element());
9899
this.$textArea = this.$element.find(`.${CHAT_MESSAGEBOX_TEXTAREA_CLASS}`);
99-
this.textArea = this.$textArea.dxTextArea('instance');
100+
this.textArea = ChatTextArea.getInstance(this.$textArea);
100101
this.$input = this.$element.find(`.${TEXTEDITOR_INPUT_CLASS}`);
101-
this.$sendButton = this.$element.find(`.${BUTTON_CLASS}`).at(-1);
102+
const $buttons = this.$element.find(`.${BUTTON_CLASS}`);
103+
this.$sendButton = $($buttons[$buttons.length - 1]);
102104
};
103105

104106
this.reinit = (options) => {

packages/devextreme/testing/tests/DevExpress.ui.widgets/chatParts/messageBox.markup.tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import $ from 'jquery';
22

33
import MessageBox, {
44
CHAT_MESSAGEBOX_CLASS,
5-
CHAT_MESSAGEBOX_INPUT_CONTAINER_CLASS,
5+
CHAT_MESSAGEBOX_TEXTAREA_CONTAINER_CLASS,
66
CHAT_MESSAGEBOX_TEXTAREA_CLASS,
77
} from '__internal/ui/chat/message_box/message_box';
88

@@ -36,7 +36,7 @@ QUnit.module('MessageBox', moduleConfig, () => {
3636
const $messageBoxContent = this.$element.children();
3737

3838
assert.strictEqual($messageBoxContent.length, 1, 'message box content has one elements');
39-
assert.strictEqual($messageBoxContent.eq(0).hasClass(CHAT_MESSAGEBOX_INPUT_CONTAINER_CLASS), true, 'message box contains input container');
39+
assert.strictEqual($messageBoxContent.eq(0).hasClass(CHAT_MESSAGEBOX_TEXTAREA_CONTAINER_CLASS), true, 'message box contains input container');
4040
});
4141

4242
QUnit.test(`textarea field should have ${CHAT_MESSAGEBOX_TEXTAREA_CLASS} class`, function(assert) {

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import MessageBox, {
77
TYPING_END_DELAY,
88
CHAT_MESSAGEBOX_TEXTAREA_CLASS,
99
} from '__internal/ui/chat/message_box/message_box';
10-
import TextArea from '__internal/ui/m_text_area';
10+
import ChatTextArea from '__internal/ui/chat/message_box/chat_text_area';
1111
import Button from 'ui/button';
1212
import EditingPreview, {
1313
CHAT_EDITING_PREVIEW_CLASS,
@@ -28,11 +28,13 @@ const moduleConfig = {
2828
this.$element = $(this.instance.$element());
2929

3030
this.$textArea = this.$element.find(`.${CHAT_MESSAGEBOX_TEXTAREA_CLASS}`);
31-
this.textArea = TextArea.getInstance(this.$textArea);
31+
this.textArea = ChatTextArea.getInstance(this.$textArea);
3232

3333
this.$input = this.$element.find(`.${TEXTEDITOR_INPUT_CLASS}`);
3434

35-
this.$sendButton = this.$element.find(`.${BUTTON_CLASS}`).at(-1);
35+
const $buttons = this.$element.find(`.${BUTTON_CLASS}`);
36+
this.$sendButton = $($buttons[$buttons.length - 1]);
37+
3638
this.sendButton = Button.getInstance(this.$sendButton);
3739

3840
this.getEditingPreview = () => this.$element.find(`.${CHAT_EDITING_PREVIEW_CLASS}`);
@@ -60,18 +62,19 @@ QUnit.module('MessageBox', moduleConfig, () => {
6062

6163
QUnit.test('send button should be initialized with the corresponding configuration', function(assert) {
6264
const expectedOptions = {
63-
icon: 'sendfilled',
65+
icon: 'arrowright',
6466
type: 'default',
65-
stylingMode: 'text',
67+
stylingMode: 'contained',
6668
disabled: true,
69+
type: 'default',
6770
};
6871

6972
Object.entries(expectedOptions).forEach(([key, value]) => {
70-
assert.deepEqual(value, this.sendButton.option(key), `${key} value is correct`);
73+
assert.deepEqual(this.sendButton.option(key), value, `${key} value is correct`);
7174
});
7275
});
7376

74-
QUnit.test('TextArea should be initialized with the corresponding configuration', function(assert) {
77+
QUnit.test('ChatTextArea should be initialized with the corresponding configuration', function(assert) {
7578
const expectedOptions = {
7679
stylingMode: 'outlined',
7780
placeholder: 'Type a message',
@@ -80,7 +83,7 @@ QUnit.module('MessageBox', moduleConfig, () => {
8083
valueChangeEvent: 'input'
8184
};
8285

83-
const textArea = TextArea.getInstance(this.$textArea);
86+
const textArea = ChatTextArea.getInstance(this.$textArea);
8487

8588
Object.entries(expectedOptions).forEach(([key, value]) => {
8689
assert.deepEqual(value, textArea.option(key), `textarea ${key} value is correct`);

0 commit comments

Comments
 (0)