diff options
Diffstat (limited to 'polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html')
-rw-r--r-- | polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html | 48 |
1 files changed, 36 insertions, 12 deletions
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 bcf3011e96..1a76f98260 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 @@ -1,5 +1,6 @@ <!DOCTYPE html> <!-- +@license Copyright (C) 2016 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,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> @@ -45,7 +46,7 @@ limitations under the License. sandbox.restore(); }); - test('renders', done => { + test('renders', () => { let promise; const queryStub = sandbox.spy(input => { return promise = Promise.resolve([ @@ -65,18 +66,17 @@ limitations under the License. assert.isTrue(queryStub.called); element._focused = true; - promise.then(() => { + return promise.then(() => { assert.isFalse(element.$.suggestions.isHidden); const suggestions = Polymer.dom(element.$.suggestions.root).querySelectorAll('li'); assert.equal(suggestions.length, 5); for (let i = 0; i < 5; i++) { - assert.equal(suggestions[i].textContent, 'blah ' + i); + assert.equal(suggestions[i].innerText.trim(), 'blah ' + i); } assert.notEqual(element.$.suggestions.$.cursor.index, -1); - done(); }); }); @@ -235,6 +235,24 @@ limitations under the License. assert.isTrue(queryStub.called); }); + test('noDebounce=false debounces the query', () => { + const queryStub = sandbox.spy(() => { + return Promise.resolve([]); + }); + let callback; + const debounceStub = sandbox.stub(element, 'debounce', + (name, cb) => { callback = cb; }); + element.query = queryStub; + element.noDebounce = false; + element.text = 'a'; + assert.isFalse(queryStub.called); + assert.isTrue(debounceStub.called); + assert.equal(debounceStub.lastCall.args[2], 200); + assert.isFunction(callback); + callback(); + assert.isTrue(queryStub.called); + }); + test('_computeClass respects border property', () => { assert.equal(element._computeClass(), ''); assert.equal(element._computeClass(false), ''); @@ -242,9 +260,7 @@ limitations under the License. }); test('undefined or empty text results in no suggestions', () => { - sandbox.spy(element, '_updateSuggestions'); - element.text = undefined; - assert(element._updateSuggestions.calledOnce); + element._updateSuggestions(undefined, 0, null); assert.equal(element._suggestions.length, 0); }); @@ -479,6 +495,18 @@ limitations under the License. assert.isTrue(listener.called); }); + test('enter with modifier does not complete', () => { + const handleSpy = sandbox.spy(element, '_handleKeydown'); + const commitStub = sandbox.stub(element, '_handleInputCommit'); + MockInteractions.pressAndReleaseKeyOn( + element.$.input, 13, 'ctrl', 'enter'); + assert.isTrue(handleSpy.called); + assert.isFalse(commitStub.called); + MockInteractions.pressAndReleaseKeyOn( + element.$.input, 13, null, 'enter'); + assert.isTrue(commitStub.called); + }); + suite('warnUncommitted', () => { let inputClassList; setup(() => { @@ -490,12 +518,8 @@ limitations under the License. element.text = 'blah blah blah'; MockInteractions.blur(element.$.input); assert.isTrue(inputClassList.contains('warnUncommitted')); - assert.equal(getComputedStyle(element.$.input.inputElement).color, - 'rgb(255, 0, 0)'); MockInteractions.focus(element.$.input); assert.isFalse(inputClassList.contains('warnUncommitted')); - assert.notEqual(getComputedStyle(element.$.input.inputElement).color, - 'rgb(255, 0, 0)ed'); }); test('disabled', () => { |