mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
test(tap): Tests for ignoreTapInspect, recordCoordinates, isRecentTap
This commit is contained in:
@@ -3,6 +3,12 @@ describe('Ionic Tap', function() {
|
||||
beforeEach(function() {
|
||||
window.console.debug = function(){};
|
||||
ionic.tap.reset();
|
||||
window._setTimeout = window.setTimeout;
|
||||
window.setTimeout = function(){};
|
||||
});
|
||||
|
||||
afterEach(function(){
|
||||
window.setTimeout = window._setTimeout;
|
||||
});
|
||||
|
||||
it('Should focus on an input if it hasnt scrolled', function() {
|
||||
@@ -240,4 +246,48 @@ describe('Ionic Tap', function() {
|
||||
expect( ele.hasSecondFocus ).toBeUndefined();
|
||||
});
|
||||
|
||||
it('Should recordCoordinates and isRecentTap', function() {
|
||||
var e = {
|
||||
clientX: 100,
|
||||
clientY: 100
|
||||
};
|
||||
expect( ionic.tap.isRecentTap(e) ).toBeUndefined();
|
||||
ionic.tap.recordCoordinates(e);
|
||||
expect( ionic.tap.isRecentTap(e) ).toBeDefined();
|
||||
});
|
||||
|
||||
it('Should ignoreTapInspect because of isRecentTap', function() {
|
||||
var e = {
|
||||
type: 'touchend',
|
||||
clientX: 100,
|
||||
clientY: 100
|
||||
};
|
||||
ionic.tap.recordCoordinates(e);
|
||||
expect( ionic.tap.ignoreTapInspect(e) ).toEqual(true);
|
||||
});
|
||||
|
||||
it('Should ignoreTapInspect because of hasTouchScrolled', function() {
|
||||
ionic.tap.setTouchStart({ clientX: 100, clientY: 100 });
|
||||
var e = {
|
||||
type: 'touchend',
|
||||
clientX: 200,
|
||||
clientY: 200
|
||||
};
|
||||
expect( ionic.tap.ignoreTapInspect(e) ).toEqual(true);
|
||||
});
|
||||
|
||||
it('Should ignoreTapInspect because of touchcancel event', function() {
|
||||
var e = {
|
||||
type: 'touchcancel'
|
||||
};
|
||||
expect( ionic.tap.ignoreTapInspect(e) ).toEqual(true);
|
||||
});
|
||||
|
||||
it('Should not ignoreTapInspect', function() {
|
||||
var e = {
|
||||
type: 'touchend'
|
||||
};
|
||||
expect( ionic.tap.ignoreTapInspect(e) ).toEqual(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
var e = orgEvent.gesture.srcEvent; // evaluate the actual source event, not the created event by gestures.js
|
||||
var ele = e.target; // get the target element that was actually tapped
|
||||
|
||||
if( ionic.tap.isRecentTap(e) || ionic.tap.hasTouchScrolled(e) || e.type === 'touchcancel') {
|
||||
if( ionic.tap.ignoreTapInspect(e) ) {
|
||||
// if a tap in the same area just happened,
|
||||
// or it was a touchcanel event, don't continue
|
||||
console.debug('tapInspect stopEvent', e.type, ele.tagName);
|
||||
@@ -47,6 +47,12 @@
|
||||
ionic.tap.blurActive();
|
||||
},
|
||||
|
||||
ignoreTapInspect: function(e) {
|
||||
return !!ionic.tap.isRecentTap(e) ||
|
||||
ionic.tap.hasTouchScrolled(e) ||
|
||||
e.type === 'touchcancel';
|
||||
},
|
||||
|
||||
isTapElement: function(tagName) {
|
||||
return tagName == 'A' ||
|
||||
tagName == 'INPUT' ||
|
||||
|
||||
Reference in New Issue
Block a user