From 79f6b251c363a7bbf0e45ee8c4a2a402ac3b4ad6 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 7 Apr 2014 11:07:31 -0500 Subject: [PATCH] test(tap): Tests for ignoreTapInspect, recordCoordinates, isRecentTap --- js/ext/angular/test/service/ionicTap.unit.js | 50 ++++++++++++++++++++ js/utils/tap.js | 8 +++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/js/ext/angular/test/service/ionicTap.unit.js b/js/ext/angular/test/service/ionicTap.unit.js index 9adb153b4c..5445b9a3ba 100644 --- a/js/ext/angular/test/service/ionicTap.unit.js +++ b/js/ext/angular/test/service/ionicTap.unit.js @@ -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); + }); + }); diff --git a/js/utils/tap.js b/js/utils/tap.js index a01285ad7c..ca970b6758 100644 --- a/js/utils/tap.js +++ b/js/utils/tap.js @@ -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' ||