Merge "Revert "Revert "Debounce autocomplete queries by default"""

This commit is contained in:
Logan Hanks
2018-03-28 19:49:04 +00:00
committed by Gerrit Code Review
7 changed files with 39 additions and 30 deletions

View File

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

View File

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

View File

@@ -61,12 +61,14 @@ 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', () => {
@@ -84,8 +86,8 @@ suite('gr-edit-controls tests', () => {
assert.isTrue(element._hideAllDialogs.called);
assert.isTrue(element.$.openDialog.disabled);
assert.isFalse(queryStub.called);
element.$.openDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
openAutoCcmplete.noDebounce = true;
openAutoCcmplete.text = 'src/test.cpp';
assert.isTrue(queryStub.called);
assert.isFalse(element.$.openDialog.disabled);
MockInteractions.tap(element.$.openDialog.$$('gr-button[primary]'));
@@ -100,8 +102,8 @@ suite('gr-edit-controls tests', () => {
MockInteractions.tap(element.$$('#open'));
return showDialogSpy.lastCall.returnValue.then(() => {
assert.isTrue(element.$.openDialog.disabled);
element.$.openDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
openAutoCcmplete.noDebounce = true;
openAutoCcmplete.text = 'src/test.cpp';
assert.isFalse(element.$.openDialog.disabled);
MockInteractions.tap(element.$.openDialog.$$('gr-button'));
for (const stub of navStubs) { assert.isFalse(stub.called); }
@@ -114,10 +116,13 @@ 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', () => {
@@ -126,8 +131,8 @@ suite('gr-edit-controls tests', () => {
return showDialogSpy.lastCall.returnValue.then(() => {
assert.isTrue(element.$.deleteDialog.disabled);
assert.isFalse(queryStub.called);
element.$.deleteDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
deleteAutocomplete.noDebounce = true;
deleteAutocomplete.text = 'src/test.cpp';
assert.isTrue(queryStub.called);
assert.isFalse(element.$.deleteDialog.disabled);
MockInteractions.tap(element.$.deleteDialog.$$('gr-button[primary]'));
@@ -149,8 +154,8 @@ suite('gr-edit-controls tests', () => {
return showDialogSpy.lastCall.returnValue.then(() => {
assert.isTrue(element.$.deleteDialog.disabled);
assert.isFalse(queryStub.called);
element.$.deleteDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
deleteAutocomplete.noDebounce = true;
deleteAutocomplete.text = 'src/test.cpp';
assert.isTrue(queryStub.called);
assert.isFalse(element.$.deleteDialog.disabled);
MockInteractions.tap(element.$.deleteDialog.$$('gr-button[primary]'));
@@ -183,10 +188,13 @@ 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', () => {
@@ -195,8 +203,8 @@ suite('gr-edit-controls tests', () => {
return showDialogSpy.lastCall.returnValue.then(() => {
assert.isTrue(element.$.renameDialog.disabled);
assert.isFalse(queryStub.called);
element.$.renameDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
renameAutocomplete.noDebounce = true;
renameAutocomplete.text = 'src/test.cpp';
assert.isTrue(queryStub.called);
assert.isTrue(element.$.renameDialog.disabled);
@@ -223,8 +231,8 @@ suite('gr-edit-controls tests', () => {
return showDialogSpy.lastCall.returnValue.then(() => {
assert.isTrue(element.$.renameDialog.disabled);
assert.isFalse(queryStub.called);
element.$.renameDialog.querySelector('gr-autocomplete').text =
'src/test.cpp';
renameAutocomplete.noDebounce = true;
renameAutocomplete.text = 'src/test.cpp';
assert.isTrue(queryStub.called);
assert.isTrue(element.$.renameDialog.disabled);

View File

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

View File

@@ -18,6 +18,7 @@
'use strict';
const TOKENIZE_REGEX = /(?:[^\s"]+|"[^"]*")+/g;
const DEBOUNCE_WAIT_MS = 200;
Polymer({
is: 'gr-autocomplete',
@@ -132,12 +133,11 @@
},
/**
* The number of milliseconds to use as the debounce wait time. If null,
* no debouncing is used.
* When true, querying for suggestions is not debounced w/r/t keypresses
*/
debounceWait: {
type: Number,
value: null,
noDebounce: {
type: Boolean,
value: false,
},
/** @type {?} */
@@ -167,7 +167,7 @@
observers: [
'_maybeOpenDropdown(_suggestions, _focused)',
'_updateSuggestions(text, threshold, debounceWait)',
'_updateSuggestions(text, threshold, noDebounce)',
],
attached() {
@@ -176,6 +176,7 @@
detached() {
this.unlisten(document.body, 'tap', '_handleBodyTap');
this.cancelDebouncer('update-suggestions');
},
get focusStart() {
@@ -219,7 +220,7 @@
_onInputFocus() {
this._focused = true;
this._updateSuggestions(this.text, this.threshold, this.debounceWait);
this._updateSuggestions(this.text, this.threshold, this.noDebounce);
this.$.input.classList.remove('warnUncommitted');
// Needed so that --paper-input-container-input updated style is applied.
this.updateStyles();
@@ -232,7 +233,7 @@
this.updateStyles();
},
_updateSuggestions(text, threshold, debounceWait) {
_updateSuggestions(text, threshold, noDebounce) {
if (this._disableSuggestions) { return; }
if (text === undefined || text.length < threshold) {
this._suggestions = [];
@@ -257,10 +258,10 @@
});
};
if (debounceWait) {
this.debounce('update-suggestions', update, debounceWait);
} else {
if (noDebounce) {
update();
} else {
this.debounce('update-suggestions', update, DEBOUNCE_WAIT_MS);
}
},

View File

@@ -28,7 +28,7 @@ limitations under the License.
<test-fixture id="basic">
<template>
<gr-autocomplete></gr-autocomplete>
<gr-autocomplete no-debounce></gr-autocomplete>
</template>
</test-fixture>
@@ -236,7 +236,7 @@ limitations under the License.
assert.isTrue(queryStub.called);
});
test('debounceWait debounces the query', () => {
test('noDebounce=false 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.debounceWait = 100;
element.noDebounce = false;
element.text = 'a';
assert.isFalse(queryStub.called);
assert.isTrue(debounceStub.called);
assert.equal(debounceStub.lastCall.args[2], 100);
assert.equal(debounceStub.lastCall.args[2], 200);
assert.isFunction(callback);
callback();
assert.isTrue(queryStub.called);