@@ -414,86 +414,109 @@ describe('Grid factory', function () {
414
414
} ) ;
415
415
416
416
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 ;
420
418
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 ( ) ;
422
425
426
+ grid . modifyRows ( dataRows ) ;
427
+ } ) ;
423
428
424
- expect ( grid . rows . length ) . toBe ( 1 ) ;
429
+ it ( 'should update the grid rows' , function ( ) {
430
+ expect ( grid . rows . length ) . toBe ( 3 ) ;
425
431
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
+ } ) ;
426
435
436
+ it ( 'should insert it on position 0' , function ( ) {
427
437
dataRows . splice ( 0 , 0 , { str :'cba' } ) ;
428
438
grid . modifyRows ( dataRows ) ;
429
439
430
- expect ( grid . rows . length ) . toBe ( 2 ) ;
440
+ expect ( grid . getRow ) . toHaveBeenCalled ( ) ;
441
+ expect ( grid . rows . length ) . toBe ( 4 ) ;
431
442
expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'cba' ) ;
432
443
} ) ;
433
444
434
445
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
-
443
446
var tmpRow = dataRows [ 0 ] ;
447
+
444
448
dataRows [ 0 ] = dataRows [ 1 ] ;
445
449
dataRows [ 1 ] = tmpRow ;
446
450
grid . modifyRows ( dataRows ) ;
447
451
452
+ expect ( grid . getRow ) . toHaveBeenCalled ( ) ;
448
453
expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'cba' ) ;
449
454
expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'abc' ) ;
450
455
} ) ;
451
456
452
457
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
-
463
458
dataRows [ 1 ] = { str :'xyz' } ;
464
459
grid . modifyRows ( dataRows ) ;
465
460
461
+ expect ( grid . getRow ) . toHaveBeenCalled ( ) ;
466
462
expect ( grid . rows . length ) . toBe ( 3 ) ;
467
463
expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'abc' ) ;
468
464
expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'xyz' ) ;
469
465
expect ( grid . rows [ 2 ] . entity . str ) . toBe ( 'bac' ) ;
470
466
} ) ;
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 ( ) ;
471
478
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();
481
479
grid . modifyRows ( dataRows ) ;
480
+ } ) ;
482
481
482
+ it ( 'should update the grid rows' , function ( ) {
483
483
expect ( grid . rows . length ) . toBe ( 3 ) ;
484
484
expect ( grid . rows [ 0 ] . entity . str ) . toBe ( 'abc' ) ;
485
485
expect ( grid . rows [ 1 ] . entity . str ) . toBe ( 'cba' ) ;
486
486
expect ( grid . rows [ 2 ] . entity . str ) . toBe ( 'bac' ) ;
487
+ } ) ;
487
488
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' } ) ;
491
491
grid . modifyRows ( dataRows ) ;
492
+
493
+ expect ( grid . getRow ) . not . toHaveBeenCalled ( ) ;
492
494
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 ) ;
493
516
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' ) ;
495
519
} ) ;
496
- */
497
520
} ) ;
498
521
499
522
describe ( 'binding' , function ( ) {
0 commit comments