@@ -2,21 +2,19 @@ describe('ui.grid.selection uiGridSelectionDirective', function() {
2
2
var parentScope ,
3
3
elm ,
4
4
scope ,
5
- gridCtrl ;
5
+ gridCtrl ,
6
+ $compile ,
7
+ $rootScope ,
8
+ uiGridConstants ;
6
9
7
10
beforeEach ( module ( 'ui.grid.selection' ) ) ;
8
11
9
- beforeEach ( function ( ) {
10
- var rootScope ;
12
+ beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _uiGridConstants_ ) {
13
+ $compile = _$compile_ ;
14
+ $rootScope = _$rootScope_ ;
15
+ uiGridConstants = _uiGridConstants_ ;
11
16
12
- inject ( [
13
- '$rootScope' ,
14
- function ( rootScopeInj ) {
15
- rootScope = rootScopeInj ;
16
- }
17
- ] ) ;
18
-
19
- parentScope = rootScope . $new ( ) ;
17
+ parentScope = $rootScope . $new ( ) ;
20
18
21
19
parentScope . options = {
22
20
columnDefs : [ { field : 'id' } ]
@@ -32,19 +30,14 @@ describe('ui.grid.selection uiGridSelectionDirective', function() {
32
30
}
33
31
34
32
var tpl = '<div ui-grid="options" ui-grid-selection options="options"></div>' ;
35
-
36
- inject ( [
37
- '$compile' ,
38
- function ( $compile ) {
39
- elm = $compile ( tpl ) ( parentScope ) ;
40
- } ] ) ;
33
+ elm = $compile ( tpl ) ( parentScope ) ;
41
34
42
35
parentScope . $digest ( ) ;
43
36
scope = elm . scope ( ) ;
44
37
45
38
gridCtrl = elm . controller ( 'uiGrid' ) ;
46
39
47
- } ) ;
40
+ } ) ) ;
48
41
49
42
it ( 'should set the "enableSelection" field of the row using the function specified in "isRowSelectable"' , function ( ) {
50
43
for ( var i = 0 ; i < gridCtrl . grid . rows . length ; i ++ ) {
@@ -61,4 +54,47 @@ describe('ui.grid.selection uiGridSelectionDirective', function() {
61
54
}
62
55
}
63
56
} ) ;
57
+
58
+ 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
+
70
+ 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
+
79
+ afterEach ( function ( ) {
80
+ $ ( elm ) . remove ( ) ;
81
+ } ) ;
82
+
83
+ it ( "doesn't prevent headers from shrinking when filtering gets turned off" , function ( ) {
84
+ // Header height with filtering on
85
+ var filteringHeight = $ ( elm ) . find ( '.ui-grid-header' ) . height ( ) ;
86
+
87
+ dump ( elm . controller ( 'uiGrid' ) . grid . api . core . notifyDataChange ) ;
88
+
89
+ parentScope . options . enableFiltering = false ;
90
+ elm . controller ( 'uiGrid' ) . grid . api . core . notifyDataChange ( uiGridConstants . dataChange . COLUMN ) ;
91
+ $timeout . flush ( ) ;
92
+ parentScope . $digest ( ) ;
93
+
94
+ var noFilteringHeight = $ ( elm ) . find ( '.ui-grid-header' ) . height ( ) ;
95
+
96
+ expect ( noFilteringHeight ) . not . toEqual ( filteringHeight ) ;
97
+ expect ( noFilteringHeight < filteringHeight ) . toBe ( true ) ;
98
+ } ) ;
99
+ } ) ;
64
100
} ) ;
0 commit comments