@@ -488,12 +488,24 @@ describe('$aria', function() {
488
488
489
489
it ( 'should a trigger click from the keyboard' , function ( ) {
490
490
scope . someAction = function ( ) { } ;
491
- compileInput ( '<div ng-click="someAction()" tabindex="0"></div>' ) ;
491
+
492
+ var elements = $compile ( '<section>' +
493
+ '<div class="div-click" ng-click="someAction(\'div\')" tabindex="0"></div>' +
494
+ '<ul><li ng-click="someAction( \'li\')" tabindex="0"></li></ul>' +
495
+ '</section>' ) ( scope ) ;
496
+
497
+ scope . $digest ( ) ;
498
+
492
499
clickFn = spyOn ( scope , 'someAction' ) ;
493
500
494
- element . triggerHandler ( { type : 'keypress' , keyCode : 32 } ) ;
501
+ var divElement = elements . find ( 'div' ) ;
502
+ var liElement = elements . find ( 'li' ) ;
503
+
504
+ divElement . triggerHandler ( { type : 'keypress' , keyCode : 32 } ) ;
505
+ liElement . triggerHandler ( { type : 'keypress' , keyCode : 32 } ) ;
495
506
496
- expect ( clickFn ) . toHaveBeenCalled ( ) ;
507
+ expect ( clickFn ) . toHaveBeenCalledWith ( 'div' ) ;
508
+ expect ( clickFn ) . toHaveBeenCalledWith ( 'li' ) ;
497
509
} ) ;
498
510
499
511
it ( 'should not override existing ng-keypress' , function ( ) {
@@ -526,6 +538,31 @@ describe('$aria', function() {
526
538
element . triggerHandler ( { type : 'keypress' , keyCode : 13 } ) ;
527
539
expect ( element . text ( ) ) . toBe ( 'keypress13' ) ;
528
540
} ) ;
541
+
542
+ it ( 'should not bind keypress to non-div elements' , function ( ) {
543
+ compileInput ( '<button ng-click="event = $event">{{event.type}}{{event.keyCode}}</button>' ) ;
544
+ expect ( element . text ( ) ) . toBe ( '' ) ;
545
+ element . triggerHandler ( { type : 'keypress' , keyCode : 13 } ) ;
546
+ expect ( element . text ( ) ) . toBe ( '' ) ;
547
+ } ) ;
548
+ } ) ;
549
+
550
+ describe ( 'actions for different configured elements' , function ( ) {
551
+ beforeEach ( configAriaProvider ( {
552
+ keypressNodeNames : [ 'DIV' ]
553
+ } ) ) ;
554
+ beforeEach ( injectScopeAndCompiler ) ;
555
+
556
+ it ( 'should not a trigger click' , function ( ) {
557
+ scope . someAction = function ( ) { } ;
558
+ var clickFn = spyOn ( scope , 'someAction' ) ;
559
+
560
+ element = $compile ( '<li ng-click="someAction()" tabindex="0"></li>' ) ( scope ) ;
561
+
562
+ element . triggerHandler ( { type : 'keypress' , keyCode : 32 } ) ;
563
+
564
+ expect ( clickFn ) . not . toHaveBeenCalled ( ) ;
565
+ } ) ;
529
566
} ) ;
530
567
531
568
describe ( 'actions when bindKeypress set to false' , function ( ) {
@@ -534,11 +571,11 @@ describe('$aria', function() {
534
571
} ) ) ;
535
572
beforeEach ( injectScopeAndCompiler ) ;
536
573
537
- it ( 'should not a trigger click from the keyboard ' , function ( ) {
574
+ it ( 'should not a trigger click' , function ( ) {
538
575
scope . someAction = function ( ) { } ;
539
576
var clickFn = spyOn ( scope , 'someAction' ) ;
540
577
541
- element = $compile ( '<div ng-click="someAction()" tabindex="0">> </div>' ) ( scope ) ;
578
+ element = $compile ( '<div ng-click="someAction()" tabindex="0"></div>' ) ( scope ) ;
542
579
543
580
element . triggerHandler ( { type : 'keypress' , keyCode : 32 } ) ;
544
581
0 commit comments