@@ -414,86 +414,109 @@ describe('Grid factory', function () {
414414  } ) ; 
415415
416416  describe ( 'follow source array' ,  function ( )  { 
417-     it ( 'should insert it on position 0' ,  function ( )  { 
418-       var  dataRows  =  [ { str :'abc' } ] ; 
419-       var  grid  =  new  Grid ( {  id : 1  } ) ; 
417+     var  dataRows ,  grid ; 
420418
421-       grid . modifyRows ( dataRows ) ; 
419+     beforeEach ( function ( )  { 
420+       dataRows  =  [ { str :'abc' } , { str :'cba' } , { str :'bac' } ] ; 
421+       grid  =  new  Grid ( {  id : 1  } ) ; 
422+       grid . options . enableRowHashing  =  false ; 
423+ 
424+       spyOn ( grid ,  'getRow' ) . and . callThrough ( ) ; 
422425
426+       grid . modifyRows ( dataRows ) ; 
427+     } ) ; 
423428
424-       expect ( grid . rows . length ) . toBe ( 1 ) ; 
429+     it ( 'should update the grid rows' ,  function ( )  { 
430+       expect ( grid . rows . length ) . toBe ( 3 ) ; 
425431      expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'abc' ) ; 
432+       expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'cba' ) ; 
433+       expect ( grid . rows [ 2 ] . entity . str ) . toBe ( 'bac' ) ; 
434+     } ) ; 
426435
436+     it ( 'should insert it on position 0' ,  function ( )  { 
427437      dataRows . splice ( 0 , 0 , { str :'cba' } ) ; 
428438      grid . modifyRows ( dataRows ) ; 
429439
430-       expect ( grid . rows . length ) . toBe ( 2 ) ; 
440+       expect ( grid . getRow ) . toHaveBeenCalled ( ) ; 
441+       expect ( grid . rows . length ) . toBe ( 4 ) ; 
431442      expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'cba' ) ; 
432443    } ) ; 
433444
434445    it ( 'should swap' ,  function ( )  { 
435-       var  dataRows  =  [ { str :'abc' } , { str :'cba' } ] ; 
436-       var  grid  =  new  Grid ( {  id : 1  } ) ; 
437- 
438-       grid . modifyRows ( dataRows ) ; 
439- 
440-       expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'abc' ) ; 
441-       expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'cba' ) ; 
442- 
443446      var  tmpRow  =  dataRows [ 0 ] ; 
447+ 
444448      dataRows [ 0 ]  =  dataRows [ 1 ] ; 
445449      dataRows [ 1 ]  =  tmpRow ; 
446450      grid . modifyRows ( dataRows ) ; 
447451
452+       expect ( grid . getRow ) . toHaveBeenCalled ( ) ; 
448453      expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'cba' ) ; 
449454      expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'abc' ) ; 
450455    } ) ; 
451456
452457    it ( 'should delete and insert new in the middle' ,  function ( )  { 
453-       var  dataRows  =  [ { str :'abc' } , { str :'cba' } , { str :'bac' } ] ; 
454-       var  grid  =  new  Grid ( {  id : 1  } ) ; 
455- 
456-       grid . modifyRows ( dataRows ) ; 
457- 
458-       expect ( grid . rows . length ) . toBe ( 3 ) ; 
459-       expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'abc' ) ; 
460-       expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'cba' ) ; 
461-       expect ( grid . rows [ 2 ] . entity . str ) . toBe ( 'bac' ) ; 
462- 
463458      dataRows [ 1 ]  =  { str :'xyz' } ; 
464459      grid . modifyRows ( dataRows ) ; 
465460
461+       expect ( grid . getRow ) . toHaveBeenCalled ( ) ; 
466462      expect ( grid . rows . length ) . toBe ( 3 ) ; 
467463      expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'abc' ) ; 
468464      expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'xyz' ) ; 
469465      expect ( grid . rows [ 2 ] . entity . str ) . toBe ( 'bac' ) ; 
470466    } ) ; 
467+   } ) ; 
468+ 
469+   describe ( 'when row hashing is enabled' ,  function ( )  { 
470+     var  dataRows ,  grid ; 
471+ 
472+     beforeEach ( function ( )  { 
473+       dataRows  =  [ { str :'abc' } , { str :'cba' } , { str :'bac' } ] ; 
474+       grid  =  new  Grid ( {  id : 1  } ) ; 
475+       grid . options . enableRowHashing  =  true ; 
476+ 
477+       spyOn ( grid ,  'getRow' ) . and . callThrough ( ) ; 
471478
472-     /* 
473-      * No longer trying to keep order of sort - we run rowsProcessors 
474-      * immediately after anyway, which will resort. 
475-      * 
476-     it('should keep the order of the sort', function() { 
477-       var dataRows = [{str:'abc'},{str:'cba'},{str:'bac'}]; 
478-       var grid = new Grid({ id: 1 }); 
479-       grid.options.columnDefs = [{name:'1',type:'string'}]; 
480-       grid.buildColumns(); 
481479      grid . modifyRows ( dataRows ) ; 
480+     } ) ; 
482481
482+     it ( 'should update the grid rows' ,  function ( )  { 
483483      expect ( grid . rows . length ) . toBe ( 3 ) ; 
484484      expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'abc' ) ; 
485485      expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'cba' ) ; 
486486      expect ( grid . rows [ 2 ] . entity . str ) . toBe ( 'bac' ) ; 
487+     } ) ; 
487488
488-       grid.sortColumn(grid.columns[0]); 
489- 
490-       dataRows.splice(0,0,{str:'xyz'}); 
489+     it ( 'should insert it on position 0' ,  function ( )  { 
490+       dataRows . splice ( 0 , 0 , { str :'cba' } ) ; 
491491      grid . modifyRows ( dataRows ) ; 
492+ 
493+       expect ( grid . getRow ) . not . toHaveBeenCalled ( ) ; 
492494      expect ( grid . rows . length ) . toBe ( 4 ) ; 
495+       expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'cba' ) ; 
496+     } ) ; 
497+ 
498+     it ( 'should swap' ,  function ( )  { 
499+       var  tmpRow  =  dataRows [ 0 ] ; 
500+ 
501+       dataRows [ 0 ]  =  dataRows [ 1 ] ; 
502+       dataRows [ 1 ]  =  tmpRow ; 
503+       grid . modifyRows ( dataRows ) ; 
504+ 
505+       expect ( grid . getRow ) . not . toHaveBeenCalled ( ) ; 
506+       expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'cba' ) ; 
507+       expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'abc' ) ; 
508+     } ) ; 
509+ 
510+     it ( 'should delete and insert new in the middle' ,  function ( )  { 
511+       dataRows [ 1 ]  =  { str :'xyz' } ; 
512+       grid . modifyRows ( dataRows ) ; 
513+ 
514+       expect ( grid . getRow ) . not . toHaveBeenCalled ( ) ; 
515+       expect ( grid . rows . length ) . toBe ( 3 ) ; 
493516      expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'abc' ) ; 
494-       expect(grid.rows[3].entity.str).toBe('xyz'); 
517+       expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'xyz' ) ; 
518+       expect ( grid . rows [ 2 ] . entity . str ) . toBe ( 'bac' ) ; 
495519    } ) ; 
496-     */ 
497520  } ) ; 
498521
499522  describe ( 'binding' ,  function ( )  { 
0 commit comments