Skip to content

Commit e3c59e9

Browse files
committed
test(tap): add some more tests for taps
1 parent cf68654 commit e3c59e9

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

js/ext/angular/test/service/ionicTap.unit.js

+36-12
Original file line numberDiff line numberDiff line change
@@ -176,31 +176,55 @@ describe('Ionic Tap', function() {
176176
expect(c).toEqual({x:0, y: 0});
177177
});
178178

179-
it('Should not fire a tap for disabled elements', function() {
179+
it('Should ignoreSimulateClick for disabled elements', function() {
180180
// Disabled elements should not be tapped
181181
var targetEle = document.createElement('input');
182182
targetEle.disabled = true;
183-
var event = {};
184-
ionic.tap.simulateClick(targetEle, event);
185-
expect(event.tapIgnored).toEqual(true);
183+
expect( ionic.tap.ignoreSimulateClick(targetEle) ).toEqual(true);
186184
});
187185

188-
it('Should not fire a tap for input[file] elements', function() {
186+
it('Should ignoreSimulateClick for input[file] elements', function() {
189187
// Reported that on Android input[file] does not open using the tap
190188
var targetEle = document.createElement('input');
191189
targetEle.type = 'file';
192-
var event = {};
193-
ionic.tap.simulateClick(targetEle, event);
194-
expect(event.tapIgnored).toEqual(true);
190+
expect( ionic.tap.ignoreSimulateClick(targetEle) ).toEqual(true);
195191
});
196192

197-
it('Should not fire a tap for input[range] elements', function() {
193+
it('Should ignoreSimulateClick for input[range] elements', function() {
198194
// Range and tap do not agree, probably because it doesn't have a delay to begin with
199195
var targetEle = document.createElement('input');
200196
targetEle.type = 'range';
201-
var event = {};
202-
ionic.tap.simulateClick(targetEle, event);
203-
expect(event.tapIgnored).toEqual(true);
197+
expect( ionic.tap.ignoreSimulateClick(targetEle) ).toEqual(true);
198+
});
199+
200+
it('Should not ignoreSimulateClick for common inputs', function() {
201+
var inputTypes = ['text', 'email', 'search', 'tel', 'number', 'date', 'month', 'password', null, undefined, ''];
202+
for(var x=0; x<inputTypes.length; x++) {
203+
var targetEle = document.createElement('input');
204+
targetEle.type = inputTypes[x];
205+
expect( ionic.tap.ignoreSimulateClick(targetEle) ).toEqual(false);
206+
}
207+
expect( ionic.tap.ignoreSimulateClick( document.createElement('div') ) ).toEqual(false);
208+
expect( ionic.tap.ignoreSimulateClick( document.createElement('textarea') ) ).toEqual(false);
209+
expect( ionic.tap.ignoreSimulateClick( document.createElement('select') ) ).toEqual(false);
210+
});
211+
212+
it('Should correctly check for tap elements', function() {
213+
expect(ionic.tap.isTapElement('A')).toEqual(true);
214+
expect(ionic.tap.isTapElement('INPUT')).toEqual(true);
215+
expect(ionic.tap.isTapElement('BUTTON')).toEqual(true);
216+
expect(ionic.tap.isTapElement('LABEL')).toEqual(true);
217+
expect(ionic.tap.isTapElement('TEXTAREA')).toEqual(true);
218+
expect(ionic.tap.isTapElement('SELECT')).toEqual(true);
219+
220+
expect(ionic.tap.isTapElement('DIV')).toEqual(false);
221+
expect(ionic.tap.isTapElement('SPAN')).toEqual(false);
222+
expect(ionic.tap.isTapElement('I')).toEqual(false);
223+
expect(ionic.tap.isTapElement('BODY')).toEqual(false);
224+
expect(ionic.tap.isTapElement('SECTION')).toEqual(false);
225+
expect(ionic.tap.isTapElement('ASIDE')).toEqual(false);
226+
expect(ionic.tap.isTapElement('LI')).toEqual(false);
227+
expect(ionic.tap.isTapElement('P')).toEqual(false);
204228
});
205229

206230
});

js/utils/tap.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// only climb up a max of 5 parents, anything more probably isn't beneficial
3535
if(!ele) break;
3636

37-
if( ele.tagName.match(/a|input|button|label|textarea|select/i) ) {
37+
if( ionic.tap.isTapElement(ele.tagName) ) {
3838
return ionic.tap.simulateClick(ele, e);
3939
}
4040
ele = ele.parentElement;
@@ -46,15 +46,21 @@
4646
ionic.tap.blurActive();
4747
},
4848

49+
isTapElement: function(tagName) {
50+
return tagName == 'A' ||
51+
tagName == 'INPUT' ||
52+
tagName == 'BUTTON' ||
53+
tagName == 'LABEL' ||
54+
tagName == 'TEXTAREA' ||
55+
tagName == 'SELECT';
56+
},
57+
4958
simulateClick: function(target, e) {
5059
// simulate a normal click by running the element's click method then focus on it
5160

5261
var ele = target.control || target;
5362

54-
if(ele.disabled || ele.type === 'file' || ele.type === 'range') {
55-
e.tapIgnored = true;
56-
return;
57-
}
63+
if( ionic.tap.ignoreSimulateClick(ele) ) return;
5864

5965
console.debug('simulateClick', e.type, ele.tagName, ele.className);
6066

@@ -91,6 +97,10 @@
9197

9298
},
9399

100+
ignoreSimulateClick: function(ele) {
101+
return ele.disabled || ele.type === 'file' || ele.type === 'range';
102+
},
103+
94104
preventGhostClick: function(e) {
95105

96106
console.debug((function(){

0 commit comments

Comments
 (0)