diff options
author | David Pursehouse <dpursehouse@collab.net> | 2019-10-24 23:30:11 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-10-24 23:30:11 +0000 |
commit | d485e2ec88c4b3a259b19e910a1985e628631050 (patch) | |
tree | d0e52016a2f5da088cfd722c0e2b81eee36c0f7c | |
parent | 69e4a0a79efb20f8dfb3fb6c2d9a59e4cc55793f (diff) | |
parent | 25a05e51d39f8195ff116957a4044221c733ee8a (diff) |
Merge "Fix failing test on gr-plugin-action-context" into stable-3.1
3 files changed, 51 insertions, 11 deletions
diff --git a/polygerrit-ui/app/elements/plugins/gr-event-helper/gr-event-helper.js b/polygerrit-ui/app/elements/plugins/gr-event-helper/gr-event-helper.js index 414abad6f6..9da9c86e02 100644 --- a/polygerrit-ui/app/elements/plugins/gr-event-helper/gr-event-helper.js +++ b/polygerrit-ui/app/elements/plugins/gr-event-helper/gr-event-helper.js @@ -34,16 +34,32 @@ }; /** + * Alias of onClick + * @see onClick + */ + GrEventHelper.prototype.onTap = function(callback) { + return this._listen(this.element, callback); + }; + + /** * Add a callback to element click or touch. * The callback may return false to prevent event bubbling. * @param {function(Event):boolean} callback * @return {function()} Unsubscribe function. */ - GrEventHelper.prototype.onTap = function(callback) { + GrEventHelper.prototype.onClick = function(callback) { return this._listen(this.element, callback); }; /** + * Alias of captureClick + * @see captureClick + */ + GrEventHelper.prototype.captureTap = function(callback) { + return this._listen(this.element.parentElement, callback, {capture: true}); + }; + + /** * Add a callback to element click or touch ahead of normal flow. * Callback is installed on parent during capture phase. * https://www.w3.org/TR/DOM-Level-3-Events/#event-flow @@ -51,13 +67,13 @@ * @param {function(Event):boolean} callback * @return {function()} Unsubscribe function. */ - GrEventHelper.prototype.captureTap = function(callback) { + GrEventHelper.prototype.captureClick = function(callback) { return this._listen(this.element.parentElement, callback, {capture: true}); }; GrEventHelper.prototype._listen = function(container, callback, opt_options) { const capture = opt_options && opt_options.capture; - const event = opt_options && opt_options.event || 'tap'; + const event = opt_options && opt_options.event || 'click'; const handler = e => { if (e.path.indexOf(this.element) !== -1) { let mayContinue = true; diff --git a/polygerrit-ui/app/elements/plugins/gr-event-helper/gr-event-helper_test.html b/polygerrit-ui/app/elements/plugins/gr-event-helper/gr-event-helper_test.html index 896238fa4c..d33a88c5d4 100644 --- a/polygerrit-ui/app/elements/plugins/gr-event-helper/gr-event-helper_test.html +++ b/polygerrit-ui/app/elements/plugins/gr-event-helper/gr-event-helper_test.html @@ -74,14 +74,23 @@ limitations under the License. instance.onTap(() => { done(); }); - element.fire('tap'); + MockInteractions.tap(element); }); test('onTap() cancel', () => { const tapStub = sandbox.stub(); - element.parentElement.addEventListener('tap', tapStub); + Polymer.Gestures.addListener(element.parentElement, 'tap', tapStub); instance.onTap(() => false); - element.fire('tap'); + MockInteractions.tap(element); + flushAsynchronousOperations(); + assert.isFalse(tapStub.called); + }); + + test('onClick() cancel', () => { + const tapStub = sandbox.stub(); + element.parentElement.addEventListener('click', tapStub); + instance.onTap(() => false); + MockInteractions.tap(element); flushAsynchronousOperations(); assert.isFalse(tapStub.called); }); @@ -90,14 +99,30 @@ limitations under the License. instance.captureTap(() => { done(); }); - element.fire('tap'); + MockInteractions.tap(element); + }); + + test('captureClick()', done => { + instance.captureClick(() => { + done(); + }); + MockInteractions.tap(element); }); test('captureTap() cancels tap()', () => { const tapStub = sandbox.stub(); - element.addEventListener('tap', tapStub); + Polymer.Gestures.addListener(element.parentElement, 'tap', tapStub); + instance.captureTap(() => false); + MockInteractions.tap(element); + flushAsynchronousOperations(); + assert.isFalse(tapStub.called); + }); + + test('captureClick() cancels click()', () => { + const tapStub = sandbox.stub(); + element.addEventListener('click', tapStub); instance.captureTap(() => false); - element.fire('tap'); + MockInteractions.tap(element); flushAsynchronousOperations(); assert.isFalse(tapStub.called); }); diff --git a/polygerrit-ui/app/test/index.html b/polygerrit-ui/app/test/index.html index 20964bfd46..a1c3ae60f6 100644 --- a/polygerrit-ui/app/test/index.html +++ b/polygerrit-ui/app/test/index.html @@ -187,8 +187,7 @@ limitations under the License. 'shared/gr-js-api-interface/gr-api-utils_test.html', 'shared/gr-js-api-interface/gr-js-api-interface_test.html', 'shared/gr-js-api-interface/gr-gerrit_test.html', - // TODO: uncomment file & fix tests. - // 'shared/gr-js-api-interface/gr-plugin-action-context_test.html', + 'shared/gr-js-api-interface/gr-plugin-action-context_test.html', 'shared/gr-js-api-interface/gr-plugin-endpoints_test.html', 'shared/gr-js-api-interface/gr-plugin-rest-api_test.html', 'shared/gr-fixed-panel/gr-fixed-panel_test.html', |