test(tap): Tests for ignoreTapInspect, recordCoordinates, isRecentTap

This commit is contained in:
Adam Bradley
2014-04-07 11:07:31 -05:00
parent 9d83b05580
commit 79f6b251c3
2 changed files with 57 additions and 1 deletions

View File

@@ -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);
});
});

View File

@@ -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' ||