Skip to content

Commit

Permalink
test(tap): Tests for ignoreTapInspect, recordCoordinates, isRecentTap
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Apr 7, 2014
1 parent 9d83b05 commit 79f6b25
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
50 changes: 50 additions & 0 deletions js/ext/angular/test/service/ionicTap.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
});

});
8 changes: 7 additions & 1 deletion js/utils/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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' ||
Expand Down

0 comments on commit 79f6b25

Please sign in to comment.