diff --git a/polygerrit-ui/app/elements/change/gr-confirm-rebase-dialog/gr-confirm-rebase-dialog.html b/polygerrit-ui/app/elements/change/gr-confirm-rebase-dialog/gr-confirm-rebase-dialog.html index 8e179ccf20..5d69499687 100644 --- a/polygerrit-ui/app/elements/change/gr-confirm-rebase-dialog/gr-confirm-rebase-dialog.html +++ b/polygerrit-ui/app/elements/change/gr-confirm-rebase-dialog/gr-confirm-rebase-dialog.html @@ -105,6 +105,7 @@ limitations under the License. { 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); diff --git a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html index 169fd85ec0..fdd730d057 100644 --- a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html +++ b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html @@ -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 diff --git a/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls_test.html b/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls_test.html index 9d85d3795e..c67a2afdb8 100644 --- a/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls_test.html +++ b/polygerrit-ui/app/elements/edit/gr-edit-controls/gr-edit-controls_test.html @@ -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); diff --git a/polygerrit-ui/app/elements/settings/gr-watched-projects-editor/gr-watched-projects-editor.html b/polygerrit-ui/app/elements/settings/gr-watched-projects-editor/gr-watched-projects-editor.html index 0b8c33182a..558140f312 100644 --- a/polygerrit-ui/app/elements/settings/gr-watched-projects-editor/gr-watched-projects-editor.html +++ b/polygerrit-ui/app/elements/settings/gr-watched-projects-editor/gr-watched-projects-editor.html @@ -96,7 +96,6 @@ limitations under the License. diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js index 5cfd1c057d..1eaad4e995 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js @@ -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); } }, diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html index 7b1eed2928..872f79fe55 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html @@ -28,7 +28,7 @@ limitations under the License. @@ -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);