Merge "Revert "Debounce autocomplete queries by default""

This commit is contained in:
Wyatt Allen 2018-03-26 17:43:05 +00:00 committed by Gerrit Code Review
commit 8ccfd72452
7 changed files with 26 additions and 35 deletions

View File

@ -105,7 +105,6 @@ limitations under the License.
<gr-autocomplete
id="parentInput"
query="[[_query]]"
no-debounce
text="{{_inputText}}"
on-tap="_handleEnterChangeNumberTap"
on-commit="_handleBaseSelected"

View File

@ -166,7 +166,6 @@ limitations under the License.
test('input text change triggers function', () => {
sandbox.spy(element, '_getRecentChanges');
element.$.parentInput.noDebounce = true;
element._inputText = '1';
assert.isTrue(element._getRecentChanges.calledOnce);
element._inputText = '12';

View File

@ -48,6 +48,7 @@ limitations under the License.
id="searchInput"
text="{{_inputVal}}"
query="[[query]]"
debounce-wait="200"
on-commit="_handleInputCommit"
allow-non-suggested-values
multi

View File

@ -61,14 +61,12 @@ suite('gr-edit-controls tests', () => {
suite('edit button CUJ', () => {
let navStubs;
let openAutoCcmplete;
setup(() => {
navStubs = [
sandbox.stub(Gerrit.Nav, 'getEditUrlForDiff'),
sandbox.stub(Gerrit.Nav, 'navigateToRelativeUrl'),
];
openAutoCcmplete = element.$.openDialog.querySelector('gr-autocomplete');
});
test('_isValidPath', () => {
@ -86,8 +84,8 @@ suite('gr-edit-controls tests', () => {
assert.isTrue(element._hideAllDialogs.called);
assert.isTrue(element.$.openDialog.disabled);
assert.isFalse(queryStub.called);
openAutoCcmplete.noDebounce = true;
openAutoCcmplete.text = 'src/test.cpp';
element.$.openDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
assert.isTrue(queryStub.called);
assert.isFalse(element.$.openDialog.disabled);
MockInteractions.tap(element.$.openDialog.$$('gr-button[primary]'));
@ -102,8 +100,8 @@ suite('gr-edit-controls tests', () => {
MockInteractions.tap(element.$$('#open'));
return showDialogSpy.lastCall.returnValue.then(() => {
assert.isTrue(element.$.openDialog.disabled);
openAutoCcmplete.noDebounce = true;
openAutoCcmplete.text = 'src/test.cpp';
element.$.openDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
assert.isFalse(element.$.openDialog.disabled);
MockInteractions.tap(element.$.openDialog.$$('gr-button'));
for (const stub of navStubs) { assert.isFalse(stub.called); }
@ -116,13 +114,10 @@ suite('gr-edit-controls tests', () => {
suite('delete button CUJ', () => {
let navStub;
let deleteStub;
let deleteAutocomplete;
setup(() => {
navStub = sandbox.stub(Gerrit.Nav, 'navigateToChange');
deleteStub = sandbox.stub(element.$.restAPI, 'deleteFileInChangeEdit');
deleteAutocomplete =
element.$.deleteDialog.querySelector('gr-autocomplete');
});
test('delete', () => {
@ -131,8 +126,8 @@ suite('gr-edit-controls tests', () => {
return showDialogSpy.lastCall.returnValue.then(() => {
assert.isTrue(element.$.deleteDialog.disabled);
assert.isFalse(queryStub.called);
deleteAutocomplete.noDebounce = true;
deleteAutocomplete.text = 'src/test.cpp';
element.$.deleteDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
assert.isTrue(queryStub.called);
assert.isFalse(element.$.deleteDialog.disabled);
MockInteractions.tap(element.$.deleteDialog.$$('gr-button[primary]'));
@ -154,8 +149,8 @@ suite('gr-edit-controls tests', () => {
return showDialogSpy.lastCall.returnValue.then(() => {
assert.isTrue(element.$.deleteDialog.disabled);
assert.isFalse(queryStub.called);
deleteAutocomplete.noDebounce = true;
deleteAutocomplete.text = 'src/test.cpp';
element.$.deleteDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
assert.isTrue(queryStub.called);
assert.isFalse(element.$.deleteDialog.disabled);
MockInteractions.tap(element.$.deleteDialog.$$('gr-button[primary]'));
@ -188,13 +183,10 @@ suite('gr-edit-controls tests', () => {
suite('rename button CUJ', () => {
let navStub;
let renameStub;
let renameAutocomplete;
setup(() => {
navStub = sandbox.stub(Gerrit.Nav, 'navigateToChange');
renameStub = sandbox.stub(element.$.restAPI, 'renameFileInChangeEdit');
renameAutocomplete =
element.$.renameDialog.querySelector('gr-autocomplete');
});
test('rename', () => {
@ -203,8 +195,8 @@ suite('gr-edit-controls tests', () => {
return showDialogSpy.lastCall.returnValue.then(() => {
assert.isTrue(element.$.renameDialog.disabled);
assert.isFalse(queryStub.called);
renameAutocomplete.noDebounce = true;
renameAutocomplete.text = 'src/test.cpp';
element.$.renameDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
assert.isTrue(queryStub.called);
assert.isTrue(element.$.renameDialog.disabled);
@ -231,8 +223,8 @@ suite('gr-edit-controls tests', () => {
return showDialogSpy.lastCall.returnValue.then(() => {
assert.isTrue(element.$.renameDialog.disabled);
assert.isFalse(queryStub.called);
renameAutocomplete.noDebounce = true;
renameAutocomplete.text = 'src/test.cpp';
element.$.renameDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
assert.isTrue(queryStub.called);
assert.isTrue(element.$.renameDialog.disabled);

View File

@ -96,6 +96,7 @@ limitations under the License.
<th>
<gr-autocomplete
id="newProject"
debounce-wait="200"
query="[[_query]]"
threshold="1"
placeholder="Project"></gr-autocomplete>

View File

@ -18,7 +18,6 @@
'use strict';
const TOKENIZE_REGEX = /(?:[^\s"]+|"[^"]*")+/g;
const DEBOUNCE_WAIT_MS = 200;
Polymer({
is: 'gr-autocomplete',
@ -134,11 +133,12 @@
},
/**
* When true, querying for suggestions is not debounced w/r/t keypresses
* The number of milliseconds to use as the debounce wait time. If null,
* no debouncing is used.
*/
noDebounce: {
type: Boolean,
value: false,
debounceWait: {
type: Number,
value: null,
},
/** @type {?} */
@ -176,7 +176,6 @@
detached() {
this.unlisten(document.body, 'tap', '_handleBodyTap');
this.cancelDebouncer('update-suggestions');
},
get focusStart() {
@ -259,10 +258,10 @@
});
};
if (this.noDebounce) {
update();
if (this.debounceWait) {
this.debounce('update-suggestions', update, this.debounceWait);
} else {
this.debounce('update-suggestions', update, DEBOUNCE_WAIT_MS);
update();
}
},

View File

@ -28,7 +28,7 @@ limitations under the License.
<test-fixture id="basic">
<template>
<gr-autocomplete no-debounce></gr-autocomplete>
<gr-autocomplete></gr-autocomplete>
</template>
</test-fixture>
@ -236,7 +236,7 @@ limitations under the License.
assert.isTrue(queryStub.called);
});
test('noDebounce=false debounces the query', () => {
test('debounceWait debounces the query', () => {
const queryStub = sandbox.spy(() => {
return Promise.resolve([]);
});
@ -244,11 +244,11 @@ limitations under the License.
const debounceStub = sandbox.stub(element, 'debounce',
(name, cb) => { callback = cb; });
element.query = queryStub;
element.noDebounce = false;
element.debounceWait = 100;
element.text = 'a';
assert.isFalse(queryStub.called);
assert.isTrue(debounceStub.called);
assert.equal(debounceStub.lastCall.args[2], 200);
assert.equal(debounceStub.lastCall.args[2], 100);
assert.isFunction(callback);
callback();
assert.isTrue(queryStub.called);