@@ -26,8 +26,11 @@ describe('uib-dropdown', function() {
26
26
27
27
var triggerKeyDown = function ( element , keyCode ) {
28
28
var e = $ . Event ( 'keydown' ) ;
29
+ spyOn ( e , 'stopPropagation' ) ;
30
+ e . stopPropagation . and . callThrough ( ) ;
29
31
e . which = keyCode ;
30
32
element . trigger ( e ) ;
33
+ return e ;
31
34
} ;
32
35
33
36
describe ( 'basic' , function ( ) {
@@ -68,14 +71,15 @@ describe('uib-dropdown', function() {
68
71
it ( 'should close on escape key & focus toggle element' , function ( ) {
69
72
$document . find ( 'body' ) . append ( element ) ;
70
73
clickDropdownToggle ( ) ;
71
- triggerKeyDown ( $document , 27 ) ;
74
+ var event = triggerKeyDown ( element , 27 ) ;
72
75
expect ( element ) . not . toHaveClass ( dropdownConfig . openClass ) ;
73
76
expect ( element . find ( 'a' ) ) . toHaveFocus ( ) ;
77
+ expect ( event . stopPropagation ) . toHaveBeenCalled ( ) ;
74
78
} ) ;
75
79
76
80
it ( 'should not close on backspace key' , function ( ) {
77
81
clickDropdownToggle ( ) ;
78
- triggerKeyDown ( $document , 8 ) ;
82
+ triggerKeyDown ( element , 8 ) ;
79
83
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
80
84
} ) ;
81
85
@@ -470,7 +474,7 @@ describe('uib-dropdown', function() {
470
474
element = dropdown ( 'disabled' ) ;
471
475
$document . find ( 'body' ) . append ( element ) ;
472
476
clickDropdownToggle ( ) ;
473
- triggerKeyDown ( $document , 27 ) ;
477
+ triggerKeyDown ( element , 27 ) ;
474
478
expect ( element ) . not . toHaveClass ( dropdownConfig . openClass ) ;
475
479
expect ( element . find ( 'a' ) ) . toHaveFocus ( ) ;
476
480
} ) ;
@@ -524,7 +528,7 @@ describe('uib-dropdown', function() {
524
528
it ( 'should focus first list element when down arrow pressed' , function ( ) {
525
529
$document . find ( 'body' ) . append ( element ) ;
526
530
clickDropdownToggle ( ) ;
527
- triggerKeyDown ( $document , 40 ) ;
531
+ triggerKeyDown ( element , 40 ) ;
528
532
529
533
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
530
534
var optionEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
@@ -533,7 +537,7 @@ describe('uib-dropdown', function() {
533
537
534
538
it ( 'should not focus first list element when down arrow pressed if closed' , function ( ) {
535
539
$document . find ( 'body' ) . append ( element ) ;
536
- triggerKeyDown ( $document , 40 ) ;
540
+ triggerKeyDown ( element , 40 ) ;
537
541
538
542
expect ( element ) . not . toHaveClass ( dropdownConfig . openClass ) ;
539
543
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
@@ -543,8 +547,8 @@ describe('uib-dropdown', function() {
543
547
it ( 'should focus second list element when down arrow pressed twice' , function ( ) {
544
548
$document . find ( 'body' ) . append ( element ) ;
545
549
clickDropdownToggle ( ) ;
546
- triggerKeyDown ( $document , 40 ) ;
547
- triggerKeyDown ( $document , 40 ) ;
550
+ triggerKeyDown ( element , 40 ) ;
551
+ triggerKeyDown ( element , 40 ) ;
548
552
549
553
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
550
554
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 1 ) ;
@@ -556,15 +560,15 @@ describe('uib-dropdown', function() {
556
560
clickDropdownToggle ( ) ;
557
561
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
558
562
559
- triggerKeyDown ( $document , 38 ) ;
563
+ triggerKeyDown ( element , 38 ) ;
560
564
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
561
565
expect ( focusEl ) . not . toHaveFocus ( ) ;
562
566
} ) ;
563
567
564
568
it ( 'should focus last list element when up arrow pressed after dropdown toggled' , function ( ) {
565
569
$document . find ( 'body' ) . append ( element ) ;
566
570
clickDropdownToggle ( ) ;
567
- triggerKeyDown ( $document , 38 ) ;
571
+ triggerKeyDown ( element , 38 ) ;
568
572
569
573
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
570
574
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 1 ) ;
@@ -574,7 +578,7 @@ describe('uib-dropdown', function() {
574
578
it ( 'should not change focus when other keys are pressed' , function ( ) {
575
579
$document . find ( 'body' ) . append ( element ) ;
576
580
clickDropdownToggle ( ) ;
577
- triggerKeyDown ( $document , 37 ) ;
581
+ triggerKeyDown ( element , 37 ) ;
578
582
579
583
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
580
584
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) ;
@@ -585,10 +589,10 @@ describe('uib-dropdown', function() {
585
589
it ( 'should focus first list element when down arrow pressed 2x and up pressed 1x' , function ( ) {
586
590
$document . find ( 'body' ) . append ( element ) ;
587
591
clickDropdownToggle ( ) ;
588
- triggerKeyDown ( $document , 40 ) ;
589
- triggerKeyDown ( $document , 40 ) ;
592
+ triggerKeyDown ( element , 40 ) ;
593
+ triggerKeyDown ( element , 40 ) ;
590
594
591
- triggerKeyDown ( $document , 38 ) ;
595
+ triggerKeyDown ( element , 38 ) ;
592
596
593
597
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
594
598
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
@@ -598,14 +602,14 @@ describe('uib-dropdown', function() {
598
602
it ( 'should stay focused on final list element if down pressed at list end' , function ( ) {
599
603
$document . find ( 'body' ) . append ( element ) ;
600
604
clickDropdownToggle ( ) ;
601
- triggerKeyDown ( $document , 40 ) ;
602
- triggerKeyDown ( $document , 40 ) ;
605
+ triggerKeyDown ( element , 40 ) ;
606
+ triggerKeyDown ( element , 40 ) ;
603
607
604
608
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
605
609
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 1 ) ;
606
610
expect ( focusEl ) . toHaveFocus ( ) ;
607
611
608
- triggerKeyDown ( $document , 40 ) ;
612
+ triggerKeyDown ( element , 40 ) ;
609
613
expect ( focusEl ) . toHaveFocus ( ) ;
610
614
} ) ;
611
615
@@ -614,13 +618,13 @@ describe('uib-dropdown', function() {
614
618
$document . find ( 'body' ) . append ( element ) ;
615
619
clickDropdownToggle ( ) ;
616
620
617
- triggerKeyDown ( $document , 40 ) ;
621
+ triggerKeyDown ( element , 40 ) ;
618
622
619
623
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
620
624
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
621
625
expect ( focusEl ) . toHaveFocus ( ) ;
622
626
623
- triggerKeyDown ( $document , 27 ) ;
627
+ triggerKeyDown ( element , 27 ) ;
624
628
expect ( element ) . not . toHaveClass ( dropdownConfig . openClass ) ;
625
629
} ) ;
626
630
@@ -636,7 +640,7 @@ describe('uib-dropdown', function() {
636
640
it ( 'should focus first list element when down arrow pressed' , function ( ) {
637
641
clickDropdownToggle ( ) ;
638
642
639
- triggerKeyDown ( $document , 40 ) ;
643
+ triggerKeyDown ( element , 40 ) ;
640
644
641
645
var dropdownMenu = $document . find ( '#dropdown-menu' ) ;
642
646
@@ -647,8 +651,9 @@ describe('uib-dropdown', function() {
647
651
648
652
it ( 'should focus second list element when down arrow pressed twice' , function ( ) {
649
653
clickDropdownToggle ( ) ;
650
- triggerKeyDown ( $document , 40 ) ;
651
- triggerKeyDown ( $document , 40 ) ;
654
+ triggerKeyDown ( element , 40 ) ;
655
+ triggerKeyDown ( element , 40 ) ;
656
+ triggerKeyDown ( element , 40 ) ;
652
657
653
658
var dropdownMenu = $document . find ( '#dropdown-menu' ) ;
654
659
0 commit comments