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