Skip to content

Commit 5b6f96f

Browse files
marker-daomarker dao ®
andauthored
Chat: Move init of errors into component level (T1325479) (#33071)
Co-authored-by: marker dao ® <youdontknow@marker-dao.eth>
1 parent 467c92a commit 5b6f96f

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ export const CHAT_TEXT_AREA_TOOLBAR = 'dx-chat-textarea-toolbar';
7878
const MAX_ATTACHMENTS_COUNT = 10;
7979
const INFORMER_DELAY = 10000;
8080

81-
const ERRORS = {
82-
// @ts-expect-error format params should be extended
83-
fileLimit: messageLocalization.format('dxChat-fileLimitReachedWarning', MAX_ATTACHMENTS_COUNT),
81+
const ERROR_MESSAGE_NAME = {
82+
fileLimit: 'dxChat-fileLimitReachedWarning',
8483
};
8584

8685
export const STT_INITIAL_STATE: ButtonState = {
@@ -532,7 +531,11 @@ class ChatTextArea extends TextArea<Properties> {
532531
};
533532

534533
_fileUploaderFileLimitReached(): void {
535-
this._showInformer(ERRORS.fileLimit);
534+
this._showInformer(messageLocalization.format(
535+
ERROR_MESSAGE_NAME.fileLimit,
536+
// @ts-expect-error format params should be extended
537+
MAX_ATTACHMENTS_COUNT,
538+
));
536539
this._updateInputHeight();
537540
}
538541

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import $ from 'jquery';
22
import keyboardMock from '../../../helpers/keyboardMock.js';
33
import { isRenderer } from 'core/utils/type';
44
import config from 'core/config';
5+
import messageLocalization from 'common/core/localization/message';
56

67
import ChatTextArea, {
78
CHAT_TEXT_AREA_ATTACH_BUTTON,
@@ -845,6 +846,50 @@ QUnit.module('ChatTextArea', moduleConfig, () => {
845846

846847
assert.strictEqual(this.sendButton.option('disabled'), true, 'send button is disabled after file removal');
847848
});
849+
850+
QUnit.module('Localization', {
851+
beforeEach: function() {
852+
this.defaultMessage = messageLocalization.format('dxChat-fileLimitReachedWarning');
853+
this.customMessage = 'Custom file limit message';
854+
},
855+
afterEach: function() {
856+
messageLocalization.load({ en: { 'dxChat-fileLimitReachedWarning': this.defaultMessage } });
857+
}
858+
}, () => {
859+
QUnit.test('informer should show custom localization message loaded before component initialization', function(assert) {
860+
messageLocalization.load({ en: { 'dxChat-fileLimitReachedWarning': this.customMessage } });
861+
862+
this.reinit({
863+
fileUploaderOptions: {
864+
uploadFile: () => {},
865+
}
866+
});
867+
868+
const fileUploader = this.getFileUploader();
869+
fileUploader.option('onFileLimitReached')();
870+
871+
const $informerText = this.$element.find(`.${INFORMER_TEXT_CLASS}`);
872+
873+
assert.strictEqual($informerText.text(), this.customMessage, 'custom localization message is shown');
874+
});
875+
876+
QUnit.test('informer should show custom localization message loaded after component initialization', function(assert) {
877+
this.reinit({
878+
fileUploaderOptions: {
879+
uploadFile: () => {},
880+
}
881+
});
882+
883+
messageLocalization.load({ en: { 'dxChat-fileLimitReachedWarning': this.customMessage } });
884+
885+
const fileUploader = this.getFileUploader();
886+
fileUploader.option('onFileLimitReached')();
887+
888+
const $informerText = this.$element.find(`.${INFORMER_TEXT_CLASS}`);
889+
890+
assert.strictEqual($informerText.text(), this.customMessage, 'custom localization message is shown after runtime load');
891+
});
892+
});
848893
});
849894

850895
QUnit.module('Integration with text option', () => {

0 commit comments

Comments
 (0)