Skip to content

Commit

Permalink
feat(chat): Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marker dao ® committed Sep 6, 2024
1 parent 8633d3b commit 03ab72f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
14 changes: 8 additions & 6 deletions packages/devextreme/js/__internal/ui/chat/chat_message_box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ class MessageBox extends DOMComponent<MessageBox, Properties> {
.addClass(CHAT_MESSAGE_BOX_TEXTAREA_CLASS)
.appendTo(this.element());

const onInput = ({ component }): void => {
const { text } = component.option();
const isButtonDisabled = !text;

this._toggleButtonDisableState(isButtonDisabled);
};

this._textArea = this._createComponent($textArea, TextArea, {
activeStateEnabled,
focusStateEnabled,
hoverStateEnabled,
onInput: ({ component }): void => {
const { text } = component.option();
const isButtonDisabled = !text;

this._toggleButtonDisableState(isButtonDisabled);
},
onInput,
});
}

Expand Down
5 changes: 3 additions & 2 deletions packages/devextreme/playground/jquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ <h1 style="position: fixed; left: 0; top: 0; clip: rect(1px, 1px, 1px, 1px);">Te
<div id="button"></div>
<script>
$(function() {
$("#button").dxChat({
height: 600,
$("#button").dxButton({
text: 'Click me!',
onClick: function() { alert("clicked"); }
});
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ QUnit.module('MessageBox', moduleConfig, () => {

assert.strictEqual(this.$input.val(), emptyValue);
});

QUnit.test('send button should not be disabled after entering any character into the textarea', function(assert) {
keyboardMock(this.$input)
.focus()
.type('i');

const button = Button.getInstance(this.$sendButton);
const { disabled } = button.option();

assert.strictEqual(disabled, false);
});

QUnit.test('send button should be disabled after entering any character into the textarea and click on the button', function(assert) {
keyboardMock(this.$input)
.focus()
.type('i');

this.$sendButton.trigger('dxclick');

const button = Button.getInstance(this.$sendButton);
const { disabled } = button.option();

assert.strictEqual(disabled, true);
});
});

QUnit.module('onMessageSend event', () => {
Expand Down

0 comments on commit 03ab72f

Please sign in to comment.