@@ -2273,7 +2273,7 @@ describe('core', () => {
2273
2273
2274
2274
expect ( Object . keys ( memory . _slices . snap . data ) . length ) . to . equal ( 1 ) ;
2275
2275
patch = memory . _slices . snap . data [ ID ] ;
2276
- expect ( Object . values ( patch . patch ) ) . to . deep . equal ( [ 1 , 2 , 3 ] ) ;
2276
+ expect ( Object . values ( patch . patch ) . sort ( ) ) . to . deep . equal ( [ 1 , 2 , 3 ] ) ;
2277
2277
} ) ;
2278
2278
it ( 'snapshot set changes' , ( ) => {
2279
2279
const memory = new Memory ( ) ;
@@ -2316,7 +2316,7 @@ describe('core', () => {
2316
2316
2317
2317
const add = [ ] ;
2318
2318
patch . add . forEach ( ( item : number ) => add . push ( item ) ) ;
2319
- expect ( add ) . to . deep . equal ( [ 1 , 3 ] ) ;
2319
+ expect ( add . sort ( ) ) . to . deep . equal ( [ 1 , 3 ] ) ;
2320
2320
const remove = [ ] ;
2321
2321
patch . delete . forEach ( ( item : number ) => remove . push ( item ) ) ;
2322
2322
expect ( remove ) . to . deep . equal ( [ 0 ] ) ;
@@ -2421,10 +2421,164 @@ describe('core', () => {
2421
2421
expect ( Object . keys ( memory . _slices ) . length ) . to . equal ( 4 ) ;
2422
2422
expect ( Object . keys ( memory . _slices . test . data ) . length ) . to . equal ( 2 ) ;
2423
2423
patch = memory . _slices . test . data [ ID ] ;
2424
- expect ( Object . values ( patch . patch ) ) . to . deep . equal ( [ 1 , 2 , 3 ] ) ;
2424
+ expect ( Object . values ( patch . patch ) . sort ( ) ) . to . deep . equal ( [ 1 , 2 , 3 ] ) ;
2425
2425
patch = memory . _slices . test . data [ obj [ memoryProxyPramsKey ] . ID ] ;
2426
2426
expect ( patch ) . to . deep . equal ( { props : { 'x+y' : 3 } } ) ;
2427
2427
} ) ;
2428
+ it ( 'snapshop create some slice and concat data' , ( ) => {
2429
+ const memory = new Memory ( ) ;
2430
+ memory . _numberOfFlatSlices = 5 ;
2431
+ memory . _numberOfSlicePerSnapshot = 3 ;
2432
+
2433
+ memory . create ( 'test' ) ;
2434
+ memory . switchTo ( 'test' ) ;
2435
+
2436
+ const object = new VersionableObject ( ) ;
2437
+ memory . attach ( object ) ;
2438
+
2439
+ object [ 'x+' ] = 1 ;
2440
+
2441
+ for ( let i = 0 ; i < 10 ; i ++ ) {
2442
+ memory . create ( i . toString ( ) ) ;
2443
+ memory . switchTo ( i . toString ( ) ) ;
2444
+ }
2445
+
2446
+ object [ 'y+' ] = 2 ;
2447
+
2448
+ for ( let i = 10 ; i < 20 ; i ++ ) {
2449
+ memory . create ( i . toString ( ) ) ;
2450
+ memory . switchTo ( i . toString ( ) ) ;
2451
+ }
2452
+
2453
+ const sliceAndChanges = memory . getSliceAndChanges ( object ) ;
2454
+ expect ( sliceAndChanges . length ) . to . equal (
2455
+ 6 ,
2456
+ 'creation in "test", change in "9" and 4 snapshots' ,
2457
+ ) ;
2458
+
2459
+ for ( const c of sliceAndChanges ) {
2460
+ switch ( c . sliceKey ) {
2461
+ case 'test' :
2462
+ case '2[snapshot from test]' :
2463
+ case '5[snapshot from test]' :
2464
+ case '8[snapshot from test]' :
2465
+ expect ( c . changes ) . to . deep . equal ( { props : { 'x+' : 1 } } , c . sliceKey ) ;
2466
+ break ;
2467
+ case '9' :
2468
+ expect ( c . changes ) . to . deep . equal ( { props : { 'y+' : 2 } } , c . sliceKey ) ;
2469
+ break ;
2470
+ case '11[snapshot from test]' :
2471
+ expect ( c . changes ) . to . deep . equal (
2472
+ { props : { 'x+' : 1 , 'y+' : 2 } } ,
2473
+ c . sliceKey ,
2474
+ ) ;
2475
+ break ;
2476
+ default :
2477
+ expect ( true ) . to . equal ( false ) ;
2478
+ }
2479
+ }
2480
+ } ) ;
2481
+ it ( 'undo the slice after a snapshot of added prop of object' , ( ) => {
2482
+ const memory = new Memory ( ) ;
2483
+ memory . _numberOfFlatSlices = 5 ;
2484
+ memory . _numberOfSlicePerSnapshot = 3 ;
2485
+
2486
+ memory . create ( 'test' ) ;
2487
+ memory . switchTo ( 'test' ) ;
2488
+
2489
+ const object = new VersionableObject ( ) ;
2490
+ memory . attach ( object ) ;
2491
+
2492
+ object [ 'x+' ] = 1 ;
2493
+
2494
+ for ( let i = 0 ; i < 10 ; i ++ ) {
2495
+ memory . create ( i . toString ( ) ) ;
2496
+ memory . switchTo ( i . toString ( ) ) ;
2497
+ }
2498
+
2499
+ object [ 'y+' ] = 2 ;
2500
+
2501
+ for ( let i = 10 ; i < 20 ; i ++ ) {
2502
+ memory . create ( i . toString ( ) ) ;
2503
+ memory . switchTo ( i . toString ( ) ) ;
2504
+ }
2505
+
2506
+ memory . switchTo ( '15' ) ;
2507
+ expect ( object ) . to . deep . equal ( { 'x+' : 1 , 'y+' : 2 } ) ;
2508
+
2509
+ memory . switchTo ( '1' ) ;
2510
+ expect ( object ) . to . deep . equal (
2511
+ { 'x+' : 1 } ,
2512
+ 'Should removed the last created props' ,
2513
+ ) ;
2514
+ } ) ;
2515
+ it ( 'undo the slice after a snapshot of added item in array' , ( ) => {
2516
+ const memory = new Memory ( ) ;
2517
+ memory . _numberOfFlatSlices = 5 ;
2518
+ memory . _numberOfSlicePerSnapshot = 3 ;
2519
+
2520
+ memory . create ( 'test' ) ;
2521
+ memory . switchTo ( 'test' ) ;
2522
+
2523
+ const array = new VersionableArray ( ) ;
2524
+ memory . attach ( array ) ;
2525
+
2526
+ const object1 = new VersionableObject ( { id : '1' } ) ;
2527
+ array [ 1 ] = object1 ;
2528
+
2529
+ for ( let i = 0 ; i < 10 ; i ++ ) {
2530
+ memory . create ( i . toString ( ) ) ;
2531
+ memory . switchTo ( i . toString ( ) ) ;
2532
+ }
2533
+
2534
+ const object2 = new VersionableObject ( { id : '3' } ) ;
2535
+ array [ 3 ] = object2 ;
2536
+
2537
+ for ( let i = 10 ; i < 20 ; i ++ ) {
2538
+ memory . create ( i . toString ( ) ) ;
2539
+ memory . switchTo ( i . toString ( ) ) ;
2540
+ }
2541
+
2542
+ memory . switchTo ( '15' ) ;
2543
+ expect ( array ) . to . deep . equal ( [ undefined , { id : '1' } , undefined , { id : '3' } ] ) ;
2544
+
2545
+ memory . switchTo ( '1' ) ;
2546
+ expect ( array ) . to . deep . equal (
2547
+ [ undefined , { id : '1' } ] ,
2548
+ 'Should removed the last created items' ,
2549
+ ) ;
2550
+ } ) ;
2551
+ it ( 'undo the slice after a snapshot of added item in set' , ( ) => {
2552
+ const memory = new Memory ( ) ;
2553
+ memory . _numberOfFlatSlices = 5 ;
2554
+ memory . _numberOfSlicePerSnapshot = 3 ;
2555
+
2556
+ memory . create ( 'test' ) ;
2557
+ memory . switchTo ( 'test' ) ;
2558
+
2559
+ const set = new VersionableSet ( ) ;
2560
+ memory . attach ( set ) ;
2561
+
2562
+ set . add ( 1 ) ;
2563
+
2564
+ for ( let i = 0 ; i < 10 ; i ++ ) {
2565
+ memory . create ( i . toString ( ) ) ;
2566
+ memory . switchTo ( i . toString ( ) ) ;
2567
+ }
2568
+
2569
+ set . add ( 2 ) ;
2570
+
2571
+ for ( let i = 10 ; i < 20 ; i ++ ) {
2572
+ memory . create ( i . toString ( ) ) ;
2573
+ memory . switchTo ( i . toString ( ) ) ;
2574
+ }
2575
+
2576
+ memory . switchTo ( '15' ) ;
2577
+ expect ( [ ...set ] ) . to . deep . equal ( [ 1 , 2 ] ) ;
2578
+
2579
+ memory . switchTo ( '1' ) ;
2580
+ expect ( [ ...set ] ) . to . deep . equal ( [ 1 ] , 'Should removed the last added items' ) ;
2581
+ } ) ;
2428
2582
} ) ;
2429
2583
2430
2584
describe ( 'root & path & changes' , ( ) => {
0 commit comments