Skip to content

Commit

Permalink
refactor(ddeditor): Minimize the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marker dao ® committed Dec 13, 2024
1 parent 8bc608c commit 7894ae7
Showing 1 changed file with 17 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<div>').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) {
$('<div>').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 = $('<div>').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) {
Expand Down

0 comments on commit 7894ae7

Please sign in to comment.