Skip to content

Commit 2e8ec68

Browse files
marker-daomarker dao ®
andauthored
Chat: Move init of errors into component level (T1325479) (#33072)
Co-authored-by: marker dao ® <youdontknow@marker-dao.eth>
1 parent 0ad4d78 commit 2e8ec68

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
@@ -33,9 +33,8 @@ export const CHAT_TEXT_AREA_TOOLBAR = 'dx-chat-textarea-toolbar';
3333
const MAX_ATTACHMENTS_COUNT = 10;
3434
const INFORMER_DELAY = 10000;
3535

36-
const ERRORS = {
37-
// @ts-expect-error format params should be extended
38-
fileLimit: messageLocalization.format('dxChat-fileLimitReachedWarning', MAX_ATTACHMENTS_COUNT),
36+
const ERROR_MESSAGE_NAME = {
37+
fileLimit: 'dxChat-fileLimitReachedWarning',
3938
};
4039

4140
const isMobile = (): boolean => devices.current().deviceType !== 'desktop';
@@ -391,7 +390,11 @@ class ChatTextArea extends TextArea<Properties> {
391390
};
392391

393392
_fileUploaderFileLimitReached(): void {
394-
this._showInformer(ERRORS.fileLimit);
393+
this._showInformer(messageLocalization.format(
394+
ERROR_MESSAGE_NAME.fileLimit,
395+
// @ts-expect-error format params should be extended
396+
MAX_ATTACHMENTS_COUNT,
397+
));
395398
this._updateInputHeight();
396399
}
397400

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, { CHAT_TEXT_AREA_ATTACH_BUTTON, DEFAULT_ALLOWED_FILE_EXTENSIONS } from '__internal/ui/chat/message_box/chat_text_area';
78
import Button from 'ui/button';
@@ -814,6 +815,50 @@ QUnit.module('ChatTextArea', moduleConfig, () => {
814815

815816
assert.strictEqual(this.sendButton.option('disabled'), true, 'send button is disabled after file removal');
816817
});
818+
819+
QUnit.module('Localization', {
820+
beforeEach: function() {
821+
this.defaultMessage = messageLocalization.format('dxChat-fileLimitReachedWarning');
822+
this.customMessage = 'Custom file limit message';
823+
},
824+
afterEach: function() {
825+
messageLocalization.load({ en: { 'dxChat-fileLimitReachedWarning': this.defaultMessage } });
826+
}
827+
}, () => {
828+
QUnit.test('informer should show custom localization message loaded before component initialization', function(assert) {
829+
messageLocalization.load({ en: { 'dxChat-fileLimitReachedWarning': this.customMessage } });
830+
831+
this.reinit({
832+
fileUploaderOptions: {
833+
uploadFile: () => {},
834+
}
835+
});
836+
837+
const fileUploader = this.getFileUploader();
838+
fileUploader.option('onFileLimitReached')();
839+
840+
const $informerText = this.$element.find(`.${INFORMER_TEXT_CLASS}`);
841+
842+
assert.strictEqual($informerText.text(), this.customMessage, 'custom localization message is shown');
843+
});
844+
845+
QUnit.test('informer should show custom localization message loaded after component initialization', function(assert) {
846+
this.reinit({
847+
fileUploaderOptions: {
848+
uploadFile: () => {},
849+
}
850+
});
851+
852+
messageLocalization.load({ en: { 'dxChat-fileLimitReachedWarning': this.customMessage } });
853+
854+
const fileUploader = this.getFileUploader();
855+
fileUploader.option('onFileLimitReached')();
856+
857+
const $informerText = this.$element.find(`.${INFORMER_TEXT_CLASS}`);
858+
859+
assert.strictEqual($informerText.text(), this.customMessage, 'custom localization message is shown after runtime load');
860+
});
861+
});
817862
});
818863

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

0 commit comments

Comments
 (0)