1
1
describe ( 'ui-grid-column-menu uiGridColumnMenuService' , function ( ) {
2
2
'use strict' ;
3
3
4
- var uiGridColumnMenuService , gridClassFactory , gridUtil , grid , $rootScope , $scope ;
5
-
6
- beforeEach ( function ( ) {
7
- module ( 'ui.grid' ) ;
8
-
9
- inject ( function ( _uiGridColumnMenuService_ , _gridClassFactory_ , _gridUtil_ , _$rootScope_ ) {
10
- uiGridColumnMenuService = _uiGridColumnMenuService_ ;
11
- gridClassFactory = _gridClassFactory_ ;
12
- gridUtil = _gridUtil_ ;
13
- $rootScope = _$rootScope_ ;
14
- } ) ;
15
- } ) ;
4
+ var $rootScope ,
5
+ $scope ,
6
+ grid ,
7
+ gridClassFactory ,
8
+ gridUtil ,
9
+ uiGridColumnMenuService ,
10
+ uiGridConstants ;
11
+
12
+ beforeEach ( function ( ) {
13
+ module ( 'ui.grid' ) ;
14
+
15
+ inject ( function ( _$rootScope_ , _gridClassFactory_ , _gridUtil_ , _uiGridColumnMenuService_ , _uiGridConstants_ ) {
16
+ $rootScope = _$rootScope_ ;
17
+ gridClassFactory = _gridClassFactory_ ;
18
+ gridUtil = _gridUtil_ ;
19
+ uiGridColumnMenuService = _uiGridColumnMenuService_ ;
20
+ uiGridConstants = _uiGridConstants_ ;
21
+ } ) ;
22
+ } ) ;
16
23
17
24
describe ( 'uiGridColumnMenuService' , function ( ) {
18
25
beforeEach ( function ( ) {
@@ -550,11 +557,14 @@ describe('ui-grid-column-menu uiGridColumnMenuService', function() {
550
557
551
558
$ ( 'body' ) . append ( uiGrid ) ;
552
559
$ ( '.ui-grid-column-menu-button' ) . click ( ) ;
560
+
561
+ spyOn ( uiGridColumnMenuService , 'repositionMenu' ) . and . callFake ( angular . noop ) ;
553
562
} ) ;
554
563
afterEach ( function ( ) {
555
564
$scope . $destroy ( ) ;
556
565
uiGrid . remove ( ) ;
557
566
} ) ;
567
+
558
568
it ( 'should raise the sortChanged event when unsort is clicked' , function ( ) {
559
569
$ ( $ ( '.ui-grid-menu-item' ) [ 2 ] ) . click ( ) ;
560
570
$timeout . flush ( ) ;
@@ -568,5 +578,75 @@ describe('ui-grid-column-menu uiGridColumnMenuService', function() {
568
578
expect ( columnVisibilityChanged ) . toHaveBeenCalled ( ) ;
569
579
} ) ;
570
580
581
+ describe ( 'uiGridMenu keydown handlers' , function ( ) {
582
+ beforeEach ( function ( ) {
583
+ $timeout . flush ( ) ;
584
+ } ) ;
585
+
586
+ it ( 'should add keydown handler to ui-grid-menu' , function ( ) {
587
+ var menu = $ ( '.ui-grid-menu-items' ) [ 0 ] ;
588
+
589
+ expect ( menu . onkeydown ) . not . toBe ( null ) ;
590
+ } ) ;
591
+ it ( 'should add keydown handlers to first and last visible menu-items' , function ( ) {
592
+ var items = $ ( '.ui-grid-menu-item' ) ;
593
+
594
+ for ( var i = 0 ; i < items . length ; i ++ ) {
595
+ if ( i === 0 || i === items . length - 1 ) {
596
+ expect ( items [ i ] . onkeydown ) . not . toBe ( null ) ;
597
+ } else {
598
+ expect ( items [ i ] . onkeydown ) . toBe ( null ) ;
599
+ }
600
+ }
601
+ } ) ;
602
+ describe ( 'menu keydown handler' , function ( ) {
603
+ it ( 'should close menu when escape key is pressed' , function ( ) {
604
+ var menu = $ ( '.ui-grid-menu-items' ) ,
605
+ event = jQuery . Event ( 'keydown' , { keyCode : uiGridConstants . keymap . ESC } ) ;
606
+
607
+ expect ( menu [ 0 ] . onkeydown ) . not . toBe ( null ) ;
608
+ menu . trigger ( event ) ;
609
+ $timeout . flush ( ) ;
610
+ expect ( menu [ 0 ] . onkeydown ) . toBe ( null ) ;
611
+ } ) ;
612
+ } ) ;
613
+ describe ( 'menu-item keydown handler' , function ( ) {
614
+ it ( 'should focus on last visible item when shift tab is pressed on first visible item' , function ( ) {
615
+ var event = jQuery . Event ( 'keydown' , { keyCode : uiGridConstants . keymap . TAB , shiftKey : true } ) ,
616
+ items = $ ( '.ui-grid-menu-item' ) ;
617
+
618
+ spyOn ( items [ items . length - 1 ] , 'focus' ) ;
619
+ items [ 0 ] . onkeydown ( event ) ;
620
+ expect ( items [ items . length - 1 ] . focus ) . toHaveBeenCalled ( ) ;
621
+ } ) ;
622
+ it ( 'should focus on first visible item when tab is pressed on last visible item' , function ( ) {
623
+ var event = jQuery . Event ( 'keydown' , { keyCode : uiGridConstants . keymap . TAB , shiftKey : false } ) ,
624
+ items = $ ( '.ui-grid-menu-item' ) ;
625
+
626
+ spyOn ( items [ 0 ] , 'focus' ) ;
627
+ items [ items . length - 1 ] . onkeydown ( event ) ;
628
+ expect ( items [ 0 ] . focus ) . toHaveBeenCalled ( ) ;
629
+ } ) ;
630
+ } ) ;
631
+ describe ( 'closing ui-grid-column-menu' , function ( ) {
632
+ it ( 'should remove keydown handlers from menu-items' , function ( ) {
633
+ var menu = $ ( '.ui-grid-menu-items' ) ,
634
+ items = $ ( '.ui-grid-menu-item' ) ,
635
+ event = jQuery . Event ( 'keydown' , { keyCode : uiGridConstants . keymap . ESC } ) ;
636
+
637
+ expect ( menu [ 0 ] . onkeydown ) . not . toBe ( null ) ;
638
+ expect ( items [ 0 ] . onkeydown ) . not . toBe ( null ) ;
639
+ expect ( items [ items . length - 1 ] . onkeydown ) . not . toBe ( null ) ;
640
+
641
+ menu . trigger ( event ) ;
642
+ $timeout . flush ( ) ;
643
+
644
+ expect ( menu [ 0 ] . onkeydown ) . toBe ( null ) ;
645
+ angular . forEach ( $ ( '.ui-grid-menu-item' ) , function ( item ) {
646
+ expect ( item . onkeydown ) . toBe ( null ) ;
647
+ } ) ;
648
+ } ) ;
649
+ } ) ;
650
+ } ) ;
571
651
} ) ;
572
652
} ) ;
0 commit comments