@@ -5,39 +5,56 @@ describe('ui.grid.selection uiGridSelectionDirective', function() {
5
5
gridCtrl ,
6
6
$compile ,
7
7
$rootScope ,
8
+ $timeout ,
8
9
uiGridConstants ;
9
10
10
- beforeEach ( module ( 'ui.grid.selection' ) ) ;
11
+ /*
12
+ NOTES
13
+ - We have to flush $timeout because the header calculations are done post-$timeout, as that's when the header has been fully rendered.
14
+ - We have to actually attach the grid element to the document body, otherwise it will not have a rendered height.
15
+ */
16
+ function compileUiGridSelectionDirective ( parentScope ) {
17
+ var elm = angular . element ( '<div style="width: 300px; height: 500px" ui-grid="options" ui-grid-selection></div>' ) ;
18
+
19
+ document . body . appendChild ( elm [ 0 ] ) ;
20
+ $compile ( elm ) ( parentScope ) ;
21
+ $timeout . flush ( ) ;
22
+ parentScope . $digest ( ) ;
11
23
12
- beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _uiGridConstants_ ) {
13
- $compile = _$compile_ ;
14
- $rootScope = _$rootScope_ ;
15
- uiGridConstants = _uiGridConstants_ ;
24
+ return elm ;
25
+ }
16
26
17
- parentScope = $rootScope . $new ( ) ;
27
+ beforeEach ( function ( ) {
28
+ module ( 'ui.grid.selection' ) ;
18
29
19
- parentScope . options = {
20
- columnDefs : [ { field : 'id' } ]
21
- } ;
30
+ inject ( function ( _$compile_ , _$rootScope_ , _$timeout_ , _uiGridConstants_ ) {
31
+ $compile = _$compile_ ;
32
+ $rootScope = _$rootScope_ ;
33
+ $timeout = _$timeout_ ;
34
+ uiGridConstants = _uiGridConstants_ ;
35
+ } ) ;
22
36
23
- parentScope . options . isRowSelectable = function ( gridRow ) {
24
- return gridRow . entity . id % 2 === 0 ;
37
+ parentScope = $rootScope . $new ( ) ;
38
+ parentScope . options = {
39
+ columnDefs : [ { field : 'id' } ] ,
40
+ data : [ ] ,
41
+ isRowSelectable : function ( gridRow ) {
42
+ return gridRow . entity . id % 2 === 0 ;
43
+ }
25
44
} ;
26
45
27
- parentScope . options . data = [ ] ;
28
46
for ( var i = 0 ; i < 10 ; i ++ ) {
29
47
parentScope . options . data . push ( { id : i } ) ;
30
48
}
31
49
32
- var tpl = '<div ui-grid="options" ui-grid-selection options="options"></div>' ;
33
- elm = $compile ( tpl ) ( parentScope ) ;
34
-
35
- parentScope . $digest ( ) ;
50
+ elm = compileUiGridSelectionDirective ( parentScope ) ;
36
51
scope = elm . scope ( ) ;
37
-
38
52
gridCtrl = elm . controller ( 'uiGrid' ) ;
53
+ } ) ;
39
54
40
- } ) ) ;
55
+ it ( 'should add the row header selection buttons' , function ( ) {
56
+ expect ( $ ( elm ) . find ( '.ui-grid-header .ui-grid-selection-row-header-buttons' ) . length ) . toEqual ( 1 ) ;
57
+ } ) ;
41
58
42
59
it ( 'should set the "enableSelection" field of the row using the function specified in "isRowSelectable"' , function ( ) {
43
60
for ( var i = 0 ; i < gridCtrl . grid . rows . length ; i ++ ) {
@@ -56,25 +73,10 @@ describe('ui.grid.selection uiGridSelectionDirective', function() {
56
73
} ) ;
57
74
58
75
describe ( 'with filtering turned on' , function ( ) {
59
- var elm , $timeout ;
60
-
61
- /*
62
- NOTES
63
- - We have to flush $timeout because the header calculations are done post-$timeout, as that's when the header has been fully rendered.
64
- - We have to actually attach the grid element to the document body, otherwise it will not have a rendered height.
65
- */
66
-
67
- beforeEach ( inject ( function ( _$timeout_ ) {
68
- $timeout = _$timeout_ ;
69
-
76
+ beforeEach ( function ( ) {
70
77
parentScope . options . enableFiltering = true ;
71
-
72
- elm = angular . element ( '<div style="width: 300px; height: 500px" ui-grid="options" ui-grid-selection></div>' ) ;
73
- document . body . appendChild ( elm [ 0 ] ) ;
74
- $compile ( elm ) ( parentScope ) ;
75
- $timeout . flush ( ) ;
76
- parentScope . $digest ( ) ;
77
- } ) ) ;
78
+ elm = compileUiGridSelectionDirective ( parentScope ) ;
79
+ } ) ;
78
80
79
81
afterEach ( function ( ) {
80
82
$ ( elm ) . remove ( ) ;
@@ -95,4 +97,30 @@ describe('ui.grid.selection uiGridSelectionDirective', function() {
95
97
expect ( noFilteringHeight < filteringHeight ) . toBe ( true ) ;
96
98
} ) ;
97
99
} ) ;
100
+
101
+ describe ( 'when row header selection is turned off' , function ( ) {
102
+ beforeEach ( function ( ) {
103
+ parentScope . options . enableRowHeaderSelection = false ;
104
+ elm = compileUiGridSelectionDirective ( parentScope ) ;
105
+ } ) ;
106
+
107
+ it ( 'should not add the row header selection buttons' , function ( ) {
108
+ expect ( $ ( elm ) . find ( '.ui-grid-header .ui-grid-selection-row-header-buttons' ) . length ) . toEqual ( 0 ) ;
109
+ } ) ;
110
+ } ) ;
111
+
112
+ describe ( 'when isRowSelectable is not defined' , function ( ) {
113
+ beforeEach ( function ( ) {
114
+ delete parentScope . options . isRowSelectable ;
115
+ elm = compileUiGridSelectionDirective ( parentScope ) ;
116
+ gridCtrl = elm . controller ( 'uiGrid' ) ;
117
+ } ) ;
118
+
119
+ it ( 'should not define enableSelection' , function ( ) {
120
+ for ( var i = 0 ; i < gridCtrl . grid . rows . length ; i ++ ) {
121
+ var currentRow = gridCtrl . grid . rows [ i ] ;
122
+ expect ( currentRow . enableSelection ) . toBeUndefined ( ) ;
123
+ }
124
+ } ) ;
125
+ } ) ;
98
126
} ) ;
0 commit comments