@@ -355,6 +355,7 @@ describe('ui.grid.saveState uiGridSaveStateService', function () {
355
355
var colVisChangeCount = 0 ;
356
356
var colFilterChangeCount = 0 ;
357
357
var colSortChangeCount = 0 ;
358
+ var onSortChangedHook = jasmine . createSpy ( 'onSortChangedHook' ) ;
358
359
359
360
grid . api . core . on . columnVisibilityChanged ( $scope , function ( column ) {
360
361
colVisChangeCount ++ ;
@@ -364,15 +365,13 @@ describe('ui.grid.saveState uiGridSaveStateService', function () {
364
365
colFilterChangeCount ++ ;
365
366
} ) ;
366
367
367
- grid . api . core . on . sortChanged ( $scope , function ( ) {
368
- colSortChangeCount ++ ;
369
- } ) ;
368
+ grid . api . core . on . sortChanged ( $scope , onSortChangedHook ) ;
370
369
371
370
uiGridSaveStateService . restoreColumns ( grid , [
372
371
{ name : 'col2' , visible : false , width : 90 , sort : [ { blah : 'blah' } ] , filters : [ { } ] } ,
373
372
{ name : 'col1' , visible : true , width : '*' , sort : [ ] , filters : [ { 'blah' : 'blah' } ] } ,
374
- { name : 'col4' , visible : false , width : 120 , sort : [ ] , filters : [ { } ] } ,
375
- { name : 'col3' , visible : true , width : 220 , sort : [ ] , filters : [ { } ] }
373
+ { name : 'col4' , visible : false , width : 120 , sort : { direction : 'asc' , priority : 1 } , filters : [ { } ] } ,
374
+ { name : 'col3' , visible : true , width : 220 , sort : { direction : 'asc' , priority : 0 } , filters : [ { } ] }
376
375
] ) ;
377
376
378
377
expect ( grid . getOnlyDataColumns ( ) [ 0 ] . name ) . toEqual ( 'col2' , 'column 0 name should be col2' ) ;
@@ -397,8 +396,8 @@ describe('ui.grid.saveState uiGridSaveStateService', function () {
397
396
398
397
expect ( grid . getOnlyDataColumns ( ) [ 0 ] . sort ) . toEqual ( [ { blah : 'blah' } ] ) ;
399
398
expect ( grid . getOnlyDataColumns ( ) [ 1 ] . sort ) . toEqual ( [ ] ) ;
400
- expect ( grid . getOnlyDataColumns ( ) [ 2 ] . sort ) . toEqual ( [ ] ) ;
401
- expect ( grid . getOnlyDataColumns ( ) [ 3 ] . sort ) . toEqual ( [ ] ) ;
399
+ expect ( grid . getOnlyDataColumns ( ) [ 2 ] . sort ) . toEqual ( { direction : 'asc' , priority : 1 } ) ;
400
+ expect ( grid . getOnlyDataColumns ( ) [ 3 ] . sort ) . toEqual ( { direction : 'asc' , priority : 0 } ) ;
402
401
403
402
expect ( grid . getOnlyDataColumns ( ) [ 0 ] . filters ) . toEqual ( [ { } ] ) ;
404
403
expect ( grid . getOnlyDataColumns ( ) [ 1 ] . filters ) . toEqual ( [ { blah : 'blah' } ] ) ;
@@ -407,7 +406,13 @@ describe('ui.grid.saveState uiGridSaveStateService', function () {
407
406
408
407
expect ( colVisChangeCount ) . toEqual ( 4 , '4 columns changed visibility' ) ;
409
408
expect ( colFilterChangeCount ) . toEqual ( 1 , '1 columns changed filter' ) ;
410
- expect ( colSortChangeCount ) . toEqual ( 4 , '4 columns changed sort' ) ;
409
+
410
+ expect ( onSortChangedHook . calls . length ) . toEqual ( 1 ) ;
411
+
412
+ expect ( onSortChangedHook ) . toHaveBeenCalledWith (
413
+ grid ,
414
+ [ grid . getOnlyDataColumns ( ) [ 3 ] , grid . getOnlyDataColumns ( ) [ 2 ] ]
415
+ ) ;
411
416
} ) ;
412
417
413
418
it ( 'restore columns, all options turned off' , function ( ) {
0 commit comments