1
1
describe ( 'ui-grid-menu' , function ( ) {
2
- var $scope , $compile , menu , inner , recompile ;
2
+ var $scope , $compile , $controller , menu , inner , recompile , isolateScope ;
3
3
4
4
beforeEach ( module ( 'ui.grid' ) ) ;
5
5
6
- beforeEach ( inject ( function ( _$compile_ , $rootScope ) {
6
+ beforeEach ( inject ( function ( _$compile_ , $rootScope , _$controller_ ) {
7
7
$scope = $rootScope ;
8
8
$compile = _$compile_ ;
9
+ $controller = _$controller_ ;
9
10
10
11
$scope . foo = null ;
11
12
@@ -31,40 +32,79 @@ describe('ui-grid-menu', function() {
31
32
}
32
33
] ;
33
34
34
- // $scope.isShown = true;
35
-
36
35
recompile = function ( ) {
37
36
menu = angular . element ( '<div ui-grid-menu menu-items="items"></div>' ) ;
38
- $compile ( menu ) ( $scope ) ;
37
+ menu = $compile ( menu ) ( $scope ) ;
39
38
$scope . $digest ( ) ;
39
+ isolateScope = menu . isolateScope ( ) ;
40
40
} ;
41
41
42
42
recompile ( ) ;
43
43
} ) ) ;
44
44
45
45
describe ( 'basic show/hide' , function ( ) {
46
-
46
+
47
47
it ( 'should hide the menu by default' , function ( ) {
48
48
expect ( menu . find ( '.ui-grid-menu-inner' ) . length ) . toEqual ( 0 ) ;
49
49
} ) ;
50
-
50
+
51
51
// TODO(c0bra): Change to test hide-menu & show-menu events
52
52
// it('should be shown when the shown property is a true boolean', function () {
53
53
// $scope.isShown = true;
54
54
// $scope.$digest();
55
-
55
+
56
56
// expect(inner.hasClass('ng-hide')).toBe(false);
57
57
// });
58
-
58
+
59
59
// it('should be shown when the shown property is a function that returns true', function () {
60
60
// $scope.isShown = function() { return true; };
61
61
// $scope.$digest();
62
-
62
+
63
63
// expect(inner.hasClass('ng-hide')).toBe(false);
64
64
// });
65
-
66
-
65
+
66
+
67
+ } ) ;
68
+
69
+ describe ( 'dynamic height' , function ( ) {
70
+ it ( 'should set $scope.dynamicStyles to empty string if there is not uiGridCtrl' , function ( ) {
71
+ expect ( isolateScope . dynamicStyles ) . toEqual ( '' ) ;
72
+ } ) ;
73
+
74
+ it ( 'should set $scope.dynamicStyles to a style that limits the height of ui-grid-menu-mid' , function ( ) {
75
+ $scope . gridOptions = {
76
+ data : [ ]
77
+ } ;
78
+ compileWithGrid ( ) ;
79
+
80
+ $scope . $broadcast ( 'show-menu' ) ;
81
+
82
+ expect ( isolateScope . dynamicStyles ) . toBeDefined ( ) ;
83
+ expect ( isolateScope . dynamicStyles ) . toContain ( '.grid1234 .ui-grid-menu-mid { max-height: 370px; }' ) ;
84
+ } ) ;
85
+
86
+ function compileWithGrid ( ) {
87
+ var grid = angular . element ( '<div><div id="test-grid-menu" ui-grid-menu menu-items="items"></div></div>' ) ;
88
+ grid . data ( '$uiGridController' , $controller ( function ( $scope ) {
89
+ this . grid = {
90
+ gridHeight : 400 ,
91
+ id : '1234' ,
92
+ api : {
93
+ core : {
94
+ on : {
95
+ scrollBegin : angular . noop
96
+ }
97
+ }
98
+ }
99
+ } ;
100
+ } , { $scope : $scope . $new ( ) } ) ) ;
101
+ grid = $compile ( grid ) ( $scope ) ;
102
+ menu = grid . find ( '#test-grid-menu' ) ;
103
+ $scope . $digest ( ) ;
104
+ isolateScope = menu . isolateScope ( ) ;
105
+ }
67
106
} ) ;
107
+
68
108
describe ( 'actions with menu displayed' , function ( ) {
69
109
beforeEach ( function ( ) {
70
110
$scope . $broadcast ( 'show-menu' ) ;
@@ -74,35 +114,35 @@ describe('ui-grid-menu', function() {
74
114
75
115
it ( 'should create a list of menu items from the menuItems attribute' , function ( ) {
76
116
var items = menu . find ( '.ui-grid-menu-item' ) ;
77
-
117
+
78
118
expect ( items . length ) . toEqual ( $scope . items . length ) ;
79
119
} ) ;
80
-
120
+
81
121
it ( "should obey menu item's 'shown' property" , function ( ) {
82
122
$scope . items [ 0 ] . shown = function ( ) { return false ; } ;
83
123
recompile ( ) ;
84
-
124
+
85
125
$scope . $broadcast ( 'show-menu' ) ;
86
126
$scope . $digest ( ) ;
87
127
expect ( menu . find ( '.ui-grid-menu-inner' ) . length ) . toEqual ( 1 ) ;
88
-
128
+
89
129
var item = menu . find ( '.ui-grid-menu-item' ) . first ( ) ;
90
130
expect ( item . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
91
131
} ) ;
92
-
132
+
93
133
it ( "should run an item's action when it's clicked" , function ( ) {
94
134
var item = menu . find ( '.ui-grid-menu-item' ) . first ( ) ;
95
135
item . trigger ( 'click' ) ;
96
136
$scope . $digest ( ) ;
97
-
137
+
98
138
expect ( $scope . items [ 0 ] . action ) . toHaveBeenCalled ( ) ;
99
139
} ) ;
100
-
140
+
101
141
it ( "should run an item's action when it's clicked (part 2)" , function ( ) {
102
142
var item2 = menu . find ( '.ui-grid-menu-item:nth(1)' ) . first ( ) ;
103
143
item2 . trigger ( 'click' ) ;
104
144
$scope . $digest ( ) ;
105
-
145
+
106
146
expect ( $scope . foo ) . toEqual ( 'blah' ) ;
107
147
} ) ;
108
148
@@ -122,44 +162,44 @@ describe('ui-grid-menu', function() {
122
162
123
163
it ( 'should add the active class if the item is active' , function ( ) {
124
164
var item = menu . find ( '.ui-grid-menu-item:nth(0)' ) . first ( ) ;
125
-
165
+
126
166
expect ( item . hasClass ( 'ui-grid-menu-item-active' ) ) . toBe ( true , 'item gets active class' ) ;
127
167
} ) ;
128
168
129
169
it ( 'should add the active class if the active property is a function that returns true' , function ( ) {
130
170
var item = menu . find ( '.ui-grid-menu-item:nth(0)' ) . first ( ) ;
131
-
171
+
132
172
$scope . items [ 0 ] . active = function ( ) { return true ; } ;
133
173
$scope . $digest ( ) ;
134
-
174
+
135
175
expect ( item . hasClass ( 'ui-grid-menu-item-active' ) ) . toBe ( true ) ;
136
176
} ) ;
137
177
138
178
it ( 'should hide a menu item based on its shown property' , function ( ) {
139
179
var item = menu . find ( '.ui-grid-menu-item:nth(3)' ) . first ( ) ;
140
-
180
+
141
181
expect ( item . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
142
182
} ) ;
143
- /*
183
+ /*
144
184
PaulL: commented out as seems to be the cause of the intermittent unit test failures
145
- Will wait to see if they're genuinely gone, then work out why this test causes that
146
-
185
+ Will wait to see if they're genuinely gone, then work out why this test causes that
186
+
147
187
it("should throw an exception when an item's 'shown' property is not a function", function () {
148
188
$scope.items[0].shown = 'shown goobers';
149
-
189
+
150
190
expect(function() {
151
191
recompile();
152
192
}).toThrow();
153
193
});
154
-
194
+
155
195
it("should throw an exception when an item's 'active' property is not a function", function () {
156
196
$scope.items[0].active = 'active goobers';
157
-
197
+
158
198
expect(function() {
159
199
recompile();
160
200
}).toThrow();
161
201
});
162
- */
202
+ */
163
203
} ) ;
164
204
165
205
@@ -173,21 +213,21 @@ describe('ui-grid-menu', function() {
173
213
title : 'Blah 1'
174
214
}
175
215
] ;
176
-
216
+
177
217
menu = angular . element ( '<div ui-grid-menu menu-items="items"></div>' ) ;
178
218
$compile ( menu ) ( $scope ) ;
179
219
$scope . $digest ( ) ;
180
-
220
+
181
221
$scope . $broadcast ( 'show-menu' ) ;
182
222
$scope . $digest ( ) ;
183
-
223
+
184
224
inner = $ ( menu ) . find ( '.ui-grid-menu-inner' ) . first ( ) ;
185
225
expect ( inner . length ) . toEqual ( 1 ) ;
186
226
} ) ) ;
187
227
188
228
it ( "should display a menu item by default if no 'shown' property is passed" , function ( ) {
189
229
var item = menu . find ( '.ui-grid-menu-item' ) . first ( ) ;
190
-
230
+
191
231
expect ( item . hasClass ( 'ng-hide' ) ) . toBe ( false ) ;
192
232
} ) ;
193
233
} ) ;
0 commit comments