From 7894ae7f11962bb566873551ef637e5348c23f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marker=20dao=20=C2=AE?= Date: Fri, 13 Dec 2024 14:16:32 +0100 Subject: [PATCH] refactor(ddeditor): Minimize the tests --- .../dropDownEditor.tests.js | 71 +++++-------------- 1 file changed, 17 insertions(+), 54 deletions(-) diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownEditor.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownEditor.tests.js index 09f800cb8e6..0ed4ad99a61 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownEditor.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownEditor.tests.js @@ -457,64 +457,27 @@ QUnit.module('focus policy', () => { assert.ok($dropDownEditor.hasClass('dx-state-focused'), 'Widget is focused after click on clearButton'); }); - QUnit.test('editor should fire onFocusIn once, if fieldTemplate is used', function(assert) { - const onFocusInHandler = sinon.spy(); - - const $dropDownEditor = $('#dropDownEditorLazy').dxDropDownEditor({ - items: [ - { name: 'one', id: 1 }, - { name: 'two', id: 2 }, - { name: 'three', id: 3 }, - ], - displayExpr: 'name', - valueExpr: 'id', - value: 1, - onFocusIn: onFocusInHandler, - focusStateEnabled: true, - fieldTemplate(value) { - const $textBox = $('
').dxTextBox({ - text: value.name, - focusStateEnabled: true, - }); - - return $textBox; - }, - }); - - $dropDownEditor.find(`.${TEXT_EDITOR_INPUT_CLASS}`).focus(); - - assert.strictEqual(onFocusInHandler.callCount, 1, 'onFocusIn calls once'); - }); + [ + { eventName: 'onFocusIn', scenario: 'focus' }, + { eventName: 'onFocusOut', scenario: 'blur ' }, + ].forEach(({ eventName, scenario }) => { + QUnit.test(`${eventName} should be called only once on component ${scenario} when fieldTemplate is specified (T1238121)`, function(assert) { + const eventStub = sinon.stub(); - QUnit.test('editor should fire onFocusOut once, if fieldTemplate is used', function(assert) { - const onFocusOutHandler = sinon.spy(); + const dropDownEditor = $('#dropDownEditorLazy').dxDropDownEditor({ + [eventName]: eventStub, + fieldTemplate(_, container) { + $('
').dxTextBox({ + readOnly: true, + }).appendTo(container); + }, + }).dxDropDownEditor('instance'); - const $dropDownEditor = $('#dropDownEditorLazy').dxDropDownEditor({ - items: [ - { name: 'one', id: 1 }, - { name: 'two', id: 2 }, - { name: 'three', id: 3 }, - ], - displayExpr: 'name', - valueExpr: 'id', - value: 1, - onFocusOut: onFocusOutHandler, - focusStateEnabled: true, - fieldTemplate(value) { - const $textBox = $('
').dxTextBox({ - text: value.name, - focusStateEnabled: true, - }); + dropDownEditor.focus(); + dropDownEditor.blur(); - return $textBox; - }, + assert.strictEqual(eventStub.callCount, 1, `${eventName} called once`); }); - - const event = $.Event('focusout'); - - $dropDownEditor.find(`.${TEXT_EDITOR_INPUT_CLASS}`).trigger(event); - - assert.strictEqual(onFocusOutHandler.callCount, 1, 'onFocusOut calls once'); }); QUnit.testInActiveWindow('input is focused by click on dropDownButton', function(assert) {