Skip to content

Commit 79f6b25

Browse files
committed
test(tap): Tests for ignoreTapInspect, recordCoordinates, isRecentTap
1 parent 9d83b05 commit 79f6b25

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

Diff for: js/ext/angular/test/service/ionicTap.unit.js

+50
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ describe('Ionic Tap', function() {
33
beforeEach(function() {
44
window.console.debug = function(){};
55
ionic.tap.reset();
6+
window._setTimeout = window.setTimeout;
7+
window.setTimeout = function(){};
8+
});
9+
10+
afterEach(function(){
11+
window.setTimeout = window._setTimeout;
612
});
713

814
it('Should focus on an input if it hasnt scrolled', function() {
@@ -240,4 +246,48 @@ describe('Ionic Tap', function() {
240246
expect( ele.hasSecondFocus ).toBeUndefined();
241247
});
242248

249+
it('Should recordCoordinates and isRecentTap', function() {
250+
var e = {
251+
clientX: 100,
252+
clientY: 100
253+
};
254+
expect( ionic.tap.isRecentTap(e) ).toBeUndefined();
255+
ionic.tap.recordCoordinates(e);
256+
expect( ionic.tap.isRecentTap(e) ).toBeDefined();
257+
});
258+
259+
it('Should ignoreTapInspect because of isRecentTap', function() {
260+
var e = {
261+
type: 'touchend',
262+
clientX: 100,
263+
clientY: 100
264+
};
265+
ionic.tap.recordCoordinates(e);
266+
expect( ionic.tap.ignoreTapInspect(e) ).toEqual(true);
267+
});
268+
269+
it('Should ignoreTapInspect because of hasTouchScrolled', function() {
270+
ionic.tap.setTouchStart({ clientX: 100, clientY: 100 });
271+
var e = {
272+
type: 'touchend',
273+
clientX: 200,
274+
clientY: 200
275+
};
276+
expect( ionic.tap.ignoreTapInspect(e) ).toEqual(true);
277+
});
278+
279+
it('Should ignoreTapInspect because of touchcancel event', function() {
280+
var e = {
281+
type: 'touchcancel'
282+
};
283+
expect( ionic.tap.ignoreTapInspect(e) ).toEqual(true);
284+
});
285+
286+
it('Should not ignoreTapInspect', function() {
287+
var e = {
288+
type: 'touchend'
289+
};
290+
expect( ionic.tap.ignoreTapInspect(e) ).toEqual(false);
291+
});
292+
243293
});

Diff for: js/utils/tap.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var e = orgEvent.gesture.srcEvent; // evaluate the actual source event, not the created event by gestures.js
2424
var ele = e.target; // get the target element that was actually tapped
2525

26-
if( ionic.tap.isRecentTap(e) || ionic.tap.hasTouchScrolled(e) || e.type === 'touchcancel') {
26+
if( ionic.tap.ignoreTapInspect(e) ) {
2727
// if a tap in the same area just happened,
2828
// or it was a touchcanel event, don't continue
2929
console.debug('tapInspect stopEvent', e.type, ele.tagName);
@@ -47,6 +47,12 @@
4747
ionic.tap.blurActive();
4848
},
4949

50+
ignoreTapInspect: function(e) {
51+
return !!ionic.tap.isRecentTap(e) ||
52+
ionic.tap.hasTouchScrolled(e) ||
53+
e.type === 'touchcancel';
54+
},
55+
5056
isTapElement: function(tagName) {
5157
return tagName == 'A' ||
5258
tagName == 'INPUT' ||

0 commit comments

Comments
 (0)