@@ -210,29 +210,22 @@ describe('ui-grid-menu-button uiGridGridMenuService', function() {
210
210
211
211
menuItems = uiGridGridMenuService . getMenuItems ( $scope ) ;
212
212
213
- expect ( menuItems . length ) . toEqual ( 12 ,
214
- 'Should be 12 items, 2 from customItems, 2 from registered, 1 columns header, and 2x3 columns that allow hiding' ) ;
213
+ expect ( menuItems . length ) . toEqual ( 9 ,
214
+ 'Should be 9 items, 2 from customItems, 2 from registered, 1 columns header, and 3 columns that allow hiding' ) ;
215
215
expect ( menuItems [ 0 ] . title ) . toEqual ( 'x' , 'Menu item 0 should be from register' ) ;
216
216
expect ( menuItems [ 1 ] . title ) . toEqual ( 'y' , 'Menu item 1 should be from register' ) ;
217
217
expect ( menuItems [ 2 ] . title ) . toEqual ( 'z' , 'Menu item 2 should be from customItem' ) ;
218
218
expect ( menuItems [ 3 ] . title ) . toEqual ( 'a' , 'Menu item 3 should be from customItem' ) ;
219
219
220
- //expect( menuItems[4].title ).toEqual('Columns:', 'Menu item 4 should be header');
221
220
expect ( menuItems [ 4 ] . title ) . toEqual ( 'Clear all filters' , 'Menu item 4 Clear all filters' ) ;
222
221
expect ( menuItems [ 5 ] . title ) . toEqual ( 'Columns:' , 'Menu item 5 should be header' ) ;
223
222
expect ( menuItems [ 6 ] . title . toLowerCase ( ) ) . toEqual ( 'fn_col1' , 'Menu item 5 should be col1' ) ;
224
- expect ( menuItems [ 7 ] . title . toLowerCase ( ) ) . toEqual ( 'fn_col1' , 'Menu item 6 should be col1' ) ;
225
- expect ( menuItems [ 8 ] . title . toLowerCase ( ) ) . toEqual ( 'fn_col3' , 'Menu item 7 should be col3' ) ;
226
- expect ( menuItems [ 9 ] . title . toLowerCase ( ) ) . toEqual ( 'fn_col3' , 'Menu item 8 should be col3' ) ;
227
- expect ( menuItems [ 10 ] . title . toLowerCase ( ) ) . toEqual ( 'fn_col4' , 'Menu item 9 should be col4' ) ;
228
- expect ( menuItems [ 11 ] . title . toLowerCase ( ) ) . toEqual ( 'fn_col4' , 'Menu item 10 should be col4' ) ;
223
+ expect ( menuItems [ 7 ] . title . toLowerCase ( ) ) . toEqual ( 'fn_col3' , 'Menu item 6 should be col3' ) ;
224
+ expect ( menuItems [ 8 ] . title . toLowerCase ( ) ) . toEqual ( 'fn_col4' , 'Menu item 7 should be col4' ) ;
229
225
230
226
expect ( menuItems [ 6 ] . context . gridCol ) . toEqual ( grid . columns [ 0 ] , 'column hide/show menus should have gridCol' ) ;
231
- expect ( menuItems [ 7 ] . context . gridCol ) . toEqual ( grid . columns [ 0 ] , 'column hide/show menus should have gridCol' ) ;
232
- expect ( menuItems [ 8 ] . context . gridCol ) . toEqual ( grid . columns [ 2 ] , 'column hide/show menus should have gridCol' ) ;
233
- expect ( menuItems [ 9 ] . context . gridCol ) . toEqual ( grid . columns [ 2 ] , 'column hide/show menus should have gridCol' ) ;
234
- expect ( menuItems [ 10 ] . context . gridCol ) . toEqual ( grid . columns [ 3 ] , 'column hide/show menus should have gridCol' ) ;
235
- expect ( menuItems [ 11 ] . context . gridCol ) . toEqual ( grid . columns [ 3 ] , 'column hide/show menus should have gridCol' ) ;
227
+ expect ( menuItems [ 7 ] . context . gridCol ) . toEqual ( grid . columns [ 2 ] , 'column hide/show menus should have gridCol' ) ;
228
+ expect ( menuItems [ 8 ] . context . gridCol ) . toEqual ( grid . columns [ 3 ] , 'column hide/show menus should have gridCol' ) ;
236
229
} ) ;
237
230
238
231
it ( 'gridMenuTitleFilter returns a promise' , function ( ) {
@@ -247,34 +240,26 @@ describe('ui-grid-menu-button uiGridGridMenuService', function() {
247
240
248
241
menuItems = uiGridGridMenuService . getMenuItems ( $scope ) ;
249
242
250
- expect ( menuItems . length ) . toEqual ( 10 , 'Should be 10 items, 1 columns header, 2x4 columns that allow hiding and clear all filters' ) ;
243
+ expect ( menuItems . length ) . toEqual ( 6 , 'Should be 6 items, 1 columns header, 4 columns that allow hiding and clear all filters' ) ;
251
244
expect ( menuItems [ 0 ] . title ) . toEqual ( 'Clear all filters' , 'Menu item 0 should be Clear all filters' ) ;
252
245
expect ( menuItems [ 1 ] . title ) . toEqual ( 'Columns:' , 'Menu item 1 should be header' ) ;
253
246
expect ( menuItems [ 2 ] . title ) . toEqual ( '' , 'Promise not resolved' ) ;
254
247
expect ( menuItems [ 3 ] . title ) . toEqual ( '' , 'Promise not resolved' ) ;
255
248
expect ( menuItems [ 4 ] . title ) . toEqual ( '' , 'Promise not resolved' ) ;
256
249
expect ( menuItems [ 5 ] . title ) . toEqual ( '' , 'Promise not resolved' ) ;
257
- expect ( menuItems [ 6 ] . title ) . toEqual ( '' , 'Promise not resolved' ) ;
258
- expect ( menuItems [ 7 ] . title ) . toEqual ( '' , 'Promise not resolved' ) ;
259
- expect ( menuItems [ 8 ] . title ) . toEqual ( '' , 'Promise not resolved' ) ;
260
- expect ( menuItems [ 9 ] . title ) . toEqual ( '' , 'Promise not resolved' ) ;
261
250
262
251
promises . forEach ( function ( promise , index ) {
263
252
promise . resolve ( 'resolve_' + index ) ;
264
253
} ) ;
265
254
$scope . $digest ( ) ;
266
255
267
- expect ( menuItems . length ) . toEqual ( 10 , 'Should be 10 items, 1 columns header, 2x4 columns that allow hiding and Clean all filters' ) ;
256
+ expect ( menuItems . length ) . toEqual ( 6 , 'Should be 10 items, 1 columns header, 4 columns that allow hiding and Clean all filters' ) ;
268
257
expect ( menuItems [ 0 ] . title ) . toEqual ( 'Clear all filters' , 'Menu item 0 should be Clear all filters' ) ;
269
258
expect ( menuItems [ 1 ] . title ) . toEqual ( 'Columns:' , 'Menu item 0 should be header' ) ;
270
259
expect ( menuItems [ 2 ] . title ) . toEqual ( 'resolve_0' , 'Promise now resolved' ) ;
271
260
expect ( menuItems [ 3 ] . title ) . toEqual ( 'resolve_1' , 'Promise now resolved' ) ;
272
261
expect ( menuItems [ 4 ] . title ) . toEqual ( 'resolve_2' , 'Promise now resolved' ) ;
273
262
expect ( menuItems [ 5 ] . title ) . toEqual ( 'resolve_3' , 'Promise now resolved' ) ;
274
- expect ( menuItems [ 6 ] . title ) . toEqual ( 'resolve_4' , 'Promise now resolved' ) ;
275
- expect ( menuItems [ 7 ] . title ) . toEqual ( 'resolve_5' , 'Promise now resolved' ) ;
276
- expect ( menuItems [ 8 ] . title ) . toEqual ( 'resolve_6' , 'Promise now resolved' ) ;
277
- expect ( menuItems [ 9 ] . title ) . toEqual ( 'resolve_7' , 'Promise now resolved' ) ;
278
263
} ) ;
279
264
} ) ;
280
265
@@ -284,13 +269,15 @@ describe('ui-grid-menu-button uiGridGridMenuService', function() {
284
269
beforeEach ( function ( ) {
285
270
event = jasmine . createSpyObj ( 'event' , [ 'stopPropagation' ] ) ;
286
271
grid . options . columnDefs = [
287
- { name : 'col1' } ,
288
- { field : 'col2' } ,
272
+ { name : 'col1' , visible : true } ,
273
+ { field : 'col2' , visible : false } ,
289
274
{ name : 'col3' } ,
290
275
{ field : 'col4' }
291
276
] ;
292
277
uiGridGridMenuService . initialize ( $scope , grid ) ;
293
- spyOn ( uiGridGridMenuService , 'toggleColumnVisibility' ) . and . callThrough ( ) ;
278
+ spyOn ( uiGridGridMenuService , 'toggleColumnVisibility' ) . and . callFake ( function ( gridCol ) {
279
+ gridCol . colDef . visible = ! gridCol . colDef . visible ;
280
+ } ) ;
294
281
} ) ;
295
282
afterEach ( function ( ) {
296
283
event . stopPropagation . calls . reset ( ) ;
@@ -303,18 +290,35 @@ describe('ui-grid-menu-button uiGridGridMenuService', function() {
303
290
} ) ;
304
291
it ( 'calls toggleColumnVisibility and stopPropagation when hide menu item is clicked' , function ( ) {
305
292
showHideColumns = uiGridGridMenuService . showHideColumns ( $scope ) ;
293
+ showHideColumns [ 1 ] . context . gridCol . colDef . visible = false ;
306
294
showHideColumns [ 1 ] . action ( event ) ;
307
295
308
296
expect ( event . stopPropagation ) . toHaveBeenCalled ( ) ;
309
297
expect ( uiGridGridMenuService . toggleColumnVisibility ) . toHaveBeenCalled ( ) ;
310
298
} ) ;
299
+ it ( 'toggles the icon to ok when hide menu item is clicked' , function ( ) {
300
+ showHideColumns = uiGridGridMenuService . showHideColumns ( $scope ) ;
301
+ event . target = { firstChild : { } } ;
302
+ showHideColumns [ 1 ] . context . gridCol . colDef . visible = false ;
303
+ showHideColumns [ 1 ] . action ( event ) ;
304
+
305
+ expect ( event . target . firstChild . className ) . toEqual ( 'ui-grid-icon-ok' ) ;
306
+ } ) ;
311
307
it ( 'calls toggleColumnVisibility and stopPropagation when show menu item is clicked' , function ( ) {
312
308
showHideColumns = uiGridGridMenuService . showHideColumns ( $scope ) ;
313
- showHideColumns [ 2 ] . action ( event ) ;
309
+ showHideColumns [ 1 ] . action ( event ) ;
314
310
315
311
expect ( event . stopPropagation ) . toHaveBeenCalled ( ) ;
316
312
expect ( uiGridGridMenuService . toggleColumnVisibility ) . toHaveBeenCalled ( ) ;
317
313
} ) ;
314
+ it ( 'toggles the icon to cancel when show menu item is clicked' , function ( ) {
315
+ showHideColumns = uiGridGridMenuService . showHideColumns ( $scope ) ;
316
+ event . target = { firstChild : { } } ;
317
+ showHideColumns [ 1 ] . context . gridCol . colDef . visible = true ;
318
+ showHideColumns [ 1 ] . action ( event ) ;
319
+
320
+ expect ( event . target . firstChild . className ) . toEqual ( 'ui-grid-icon-cancel' ) ;
321
+ } ) ;
318
322
} ) ;
319
323
320
324
describe ( 'setMenuItemTitle: ' , function ( ) {
0 commit comments