Skip to content

Commit

Permalink
Autocomplete: dataSource should load new items only when searchTimeou…
Browse files Browse the repository at this point in the history
…t is up (T880996) (#12820)
  • Loading branch information
ksercs authored Apr 23, 2020
1 parent a20e6f1 commit 74ec000
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions js/ui/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const noop = require('../core/utils/common').noop;
const registerComponent = require('../core/component_registrator');
const extend = require('../core/utils/extend').extend;
const DropDownList = require('./drop_down_editor/ui.drop_down_list');
const Deferred = require('../core/utils/deferred').Deferred;

const AUTOCOMPLETE_CLASS = 'dx-autocomplete';
const AUTOCOMPLETE_POPUP_WRAPPER_CLASS = 'dx-autocomplete-popup-wrapper';
Expand Down Expand Up @@ -151,6 +152,12 @@ const Autocomplete = DropDownList.inherit({
this.close();
},

_loadItem: function(value, cache) {
const selectedItem = this._getItemFromPlain(value, cache);

return new Deferred().resolve(selectedItem).promise();
},

_dataSourceOptions: function() {
return {
paginate: true,
Expand Down
36 changes: 36 additions & 0 deletions testing/tests/DevExpress.ui.widgets.editors/autocomplete.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,42 @@ QUnit.module('dxAutocomplete', {
}
});

QUnit.test('dataSource should load new items only when searchTimeout is up (T880996)', function(assert) {
const keyboard = this.keyboard;
const data = [{
ID: 1,
Name: 'Item 11'
}, {
ID: 2,
Name: 'Item 12'
}, {
ID: 3,
Name: 'Item 22'
}];
const loadMock = sinon.stub().returns(data);

this.element.dxAutocomplete({
dataSource: {
load: loadMock
},
searchTimeout: 500,
valueExpr: 'Name'
});

assert.strictEqual(loadMock.callCount, 1, 'dataSource load is called on init');

keyboard
.type('Item')
.change();


this.clock.tick(499);
assert.strictEqual(loadMock.callCount, 1, 'dataSource load is not called after typing if timeout is not up');

this.clock.tick(1);
assert.strictEqual(loadMock.callCount, 2, 'dataSource is filtered when timeout is up');
});

QUnit.test('arrow_down/arrow_up/enter provide item navigation and selection', function(assert) {
if(devices.real().deviceType !== 'desktop') {
assert.ok(true, 'test does not actual for mobile devices');
Expand Down

0 comments on commit 74ec000

Please sign in to comment.