@@ -370,40 +370,100 @@ describe('ngClick (touch)', function() {
370
370
} ) ) ;
371
371
372
372
373
- it ( 'should not cancel clicks that come long after' , inject ( function ( $rootScope , $compile ) {
374
- element1 = $compile ( '<div ng-click="count = count + 1"></div>' ) ( $rootScope ) ;
373
+ describe ( 'when clicking on a label immediately following a touch event' , function ( ) {
374
+ var touch = function ( element , x , y ) {
375
+ time = 10 ;
376
+ browserTrigger ( element , 'touchstart' , {
377
+ keys : [ ] ,
378
+ x : x ,
379
+ y : y
380
+ } ) ;
375
381
376
- $rootScope . count = 0 ;
382
+ time = 50 ;
383
+ browserTrigger ( element , 'touchend' , {
384
+ keys : [ ] ,
385
+ x : x ,
386
+ y : y
387
+ } ) ;
388
+ } ;
377
389
378
- $rootScope . $digest ( ) ;
390
+ var click = function ( element , x , y ) {
391
+ browserTrigger ( element , 'click' , {
392
+ keys : [ ] ,
393
+ x : x ,
394
+ y : y
395
+ } ) ;
396
+ } ;
379
397
380
- expect ( $rootScope . count ) . toBe ( 0 ) ;
398
+ var $rootScope ;
399
+ var container , otherElement , input , label ;
400
+ beforeEach ( inject ( function ( _$rootScope_ , $compile , $rootElement ) {
401
+ $rootScope = _$rootScope_ ;
402
+ var container = $compile ( '<div><div ng-click="count = count + 1"></div>' +
403
+ '<input id="input1" type="radio" ng-model="selection" value="radio1">' +
404
+ '<label for="input1">Input1</label></div>' ) ( $rootScope ) ;
405
+ $rootElement . append ( container ) ;
406
+ otherElement = container . children ( ) [ 0 ] ;
407
+ input = container . children ( ) [ 1 ] ;
408
+ label = container . children ( ) [ 2 ] ;
381
409
382
- time = 10 ;
383
- browserTrigger ( element1 , 'touchstart' , {
384
- keys : [ ] ,
385
- x : 10 ,
386
- y : 10
410
+ $rootScope . selection = 'initial' ;
411
+
412
+ $rootScope . $digest ( ) ;
413
+ } ) ) ;
414
+
415
+
416
+ afterEach ( function ( ) {
417
+ dealoc ( label ) ;
418
+ dealoc ( input ) ;
419
+ dealoc ( otherElement ) ;
420
+ dealoc ( container ) ;
387
421
} ) ;
388
422
389
- time = 50 ;
390
- browserTrigger ( element1 , 'touchend' , {
391
- keys : [ ] ,
392
- x : 10 ,
393
- y : 10
423
+
424
+ it ( 'should not cancel input clicks with (0,0) coordinates' , function ( ) {
425
+ touch ( otherElement , 100 , 100 ) ;
426
+
427
+ time = 500 ;
428
+ click ( label , 10 , 10 ) ;
429
+ click ( input , 0 , 0 ) ;
430
+
431
+ expect ( $rootScope . selection ) . toBe ( 'radio1' ) ;
394
432
} ) ;
395
433
396
- expect ( $rootScope . count ) . toBe ( 1 ) ;
397
434
398
- time = 2700 ;
399
- browserTrigger ( element1 , 'click' , {
400
- keys : [ ] ,
401
- x : 10 ,
402
- y : 10
435
+ it ( 'should not cancel input clicks with negative coordinates' , function ( ) {
436
+ touch ( otherElement , 100 , 100 ) ;
437
+
438
+ time = 500 ;
439
+ click ( label , 10 , 10 ) ;
440
+ click ( input , - 1 , - 1 ) ;
441
+
442
+ expect ( $rootScope . selection ) . toBe ( 'radio1' ) ;
403
443
} ) ;
404
444
405
- expect ( $rootScope . count ) . toBe ( 2 ) ;
406
- } ) ) ;
445
+
446
+ it ( 'should not cancel input clicks with positive coordinates identical to label click' , function ( ) {
447
+ touch ( otherElement , 100 , 100 ) ;
448
+
449
+ time = 500 ;
450
+ click ( label , 10 , 10 ) ;
451
+ click ( input , 10 , 10 ) ;
452
+
453
+ expect ( $rootScope . selection ) . toBe ( 'radio1' ) ;
454
+ } ) ;
455
+
456
+
457
+ it ( 'should cancel input clicks with positive coordinates different than label click' , function ( ) {
458
+ touch ( otherElement , 100 , 100 ) ;
459
+
460
+ time = 500 ;
461
+ click ( label , 10 , 10 ) ;
462
+ click ( input , 11 , 11 ) ;
463
+
464
+ expect ( $rootScope . selection ) . toBe ( 'initial' ) ;
465
+ } ) ;
466
+ } ) ;
407
467
} ) ;
408
468
409
469
0 commit comments