From 4f8b6b557c0f0c10bef9f7eb9ca7c627796b4165 Mon Sep 17 00:00:00 2001 From: Nikki Gonzales <38495263+nikkithelegendarypokemonster@users.noreply.github.com> Date: Mon, 27 May 2024 11:45:43 +0800 Subject: [PATCH] DateBox: Rearrange attaching mouseEvents before rendering masks (#27418) Co-authored-by: EugeniyKiyashko --- .../js/ui/text_box/ui.text_editor.mask.js | 2 +- .../datebox.tests.js | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/devextreme/js/ui/text_box/ui.text_editor.mask.js b/packages/devextreme/js/ui/text_box/ui.text_editor.mask.js index 7afed38dff0b..3b27e5ac9bdd 100644 --- a/packages/devextreme/js/ui/text_box/ui.text_editor.mask.js +++ b/packages/devextreme/js/ui/text_box/ui.text_editor.mask.js @@ -161,10 +161,10 @@ const TextEditorMask = TextEditorBase.inherit({ }, _render() { + this._attachMouseWheelEventHandlers(); this._renderMask(); this.callBase(); this._attachDropEventHandler(); - this._attachMouseWheelEventHandlers(); }, _renderHiddenElement: function() { diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.tests.js index 13546ed8027a..409605afbd1b 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.tests.js @@ -2082,6 +2082,46 @@ QUnit.module('datebox and calendar integration', () => { instance.option('calendarOptions.visible', true); assert.strictEqual($(instance.content()).parent().find('.dx-button-today').length, 1); }); + + QUnit.test('change year via scroll should log proper year in on value change event (T1229926)', function(assert) { + if(devices.real().deviceType !== 'desktop') { + assert.ok(true, 'device is not desktop'); + return; + } + + const valueChangedHandle = sinon.spy(); + const date = new Date(); + const currentYear = date.getFullYear(); + const datebox = $('#dateBox').dxDateBox({ + type: 'date', + value: date, + displayFormat: 'M/dd/yyyy', + valueChangeEvent: 'dxmousewheel', + useMaskBehavior: true, + onValueChanged: valueChangedHandle + }).dxDateBox('instance'); + + const $input = $(datebox.element()).find(`.${TEXTEDITOR_INPUT_CLASS}`); + const pointer = pointerMock($input); + const keyboard = keyboardMock($input, true); + + keyboard.caret({ start: 12, end: 15 }); + + $input.trigger('dxclick'); + + pointer.wheel(1); + + let changedValue = valueChangedHandle.getCall(0).args[0]; + assert.strictEqual(valueChangedHandle.callCount, 1, 'handler has been called once'); + assert.deepEqual(new Date(changedValue.value).getFullYear(), currentYear + 1, 'value year is correct'); assert.deepEqual(new Date(changedValue.previousValue).getFullYear(), currentYear, 'previous value year is correct'); + + pointer.wheel(1); + + changedValue = valueChangedHandle.getCall(1).args[0]; + assert.strictEqual(valueChangedHandle.callCount, 2, 'handler has been called twice'); + assert.deepEqual(new Date(changedValue.value).getFullYear(), currentYear + 2, 'value year is correct'); + assert.deepEqual(new Date(changedValue.previousValue).getFullYear(), currentYear + 1, 'previous value year is correct'); + }); }); QUnit.module('datebox w/ calendar', {