Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete: dataSource should load new items only when searchTimeout is up (T880996) #12820

Merged
merged 2 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
34 changes: 34 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,40 @@ 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();

assert.strictEqual(loadMock.callCount, 1, 'dataSource load is not called immediately after typing');

this.clock.tick(500);
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