Fix failing test on gr-plugin-action-context
Tap was replaced with click based on suggestions from polymer official doc.
Change-Id: Id9e9ae698da9cdae367924556b8162cd116b97a5
(cherry picked from commit 6cc4c8a9f8)
This commit is contained in:
@@ -33,16 +33,32 @@
|
||||
return this._listen(this.element, callback, {event});
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
element.fire('tap');
|
||||
MockInteractions.tap(element);
|
||||
flushAsynchronousOperations();
|
||||
assert.isFalse(tapStub.called);
|
||||
});
|
||||
|
||||
test('captureClick() cancels click()', () => {
|
||||
const tapStub = sandbox.stub();
|
||||
element.addEventListener('click', tapStub);
|
||||
instance.captureTap(() => false);
|
||||
MockInteractions.tap(element);
|
||||
flushAsynchronousOperations();
|
||||
assert.isFalse(tapStub.called);
|
||||
});
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user