Merge "Fix text undefined error"

This commit is contained in:
Andrew Bonventre 2016-08-17 19:37:32 +00:00 committed by Gerrit Code Review
commit 0ca37dc55b
3 changed files with 11 additions and 2 deletions

View File

@ -55,7 +55,8 @@ limitations under the License.
bind-value="{{text}}" bind-value="{{text}}"
placeholder="[[placeholder]]" placeholder="[[placeholder]]"
on-keydown="_handleInputKeydown" on-keydown="_handleInputKeydown"
on-focus="_updateSuggestions" /> on-focus="_updateSuggestions"
autocomplete="off" />
<div <div
id="suggestions" id="suggestions"
hidden$="[[_computeSuggestionsHidden(_suggestions)]]"> hidden$="[[_computeSuggestionsHidden(_suggestions)]]">

View File

@ -64,6 +64,7 @@
text: { text: {
type: String, type: String,
value: '',
observer: '_updateSuggestions', observer: '_updateSuggestions',
notify: true, notify: true,
}, },
@ -131,7 +132,7 @@
}, },
_updateSuggestions: function() { _updateSuggestions: function() {
if (this._disableSuggestions) { return; } if (!this.text || this._disableSuggestions) { return; }
if (this.text.length < this.threshold) { if (this.text.length < this.threshold) {
this._suggestions = []; this._suggestions = [];
this.value = null; this.value = null;

View File

@ -215,6 +215,13 @@ limitations under the License.
assert.equal(element._computeClass(true), 'borderless'); assert.equal(element._computeClass(true), 'borderless');
}); });
test('undefined or empty text results in no suggestions', function() {
sinon.spy(element, '_updateSuggestions');
element.text = undefined;
assert(element._updateSuggestions.calledOnce);
assert.equal(element._suggestions.length, 0);
});
test('multi completes only the last part of the query', function(done) { test('multi completes only the last part of the query', function(done) {
var promise; var promise;
var queryStub = sinon.stub() var queryStub = sinon.stub()