@@ -528,11 +528,23 @@ describe('useTreeData', function () {
528
528
expect ( result . current . items [ 0 ] . children [ 0 ] ) . toBe ( initialResult . items [ 0 ] . children [ 0 ] ) ;
529
529
expect ( result . current . items [ 0 ] . children [ 1 ] ) . not . toBe ( initialResult . items [ 0 ] . children [ 1 ] ) ;
530
530
expect ( result . current . items [ 0 ] . children [ 1 ] . children ) . toHaveLength ( 2 ) ;
531
- expect ( result . current . items [ 0 ] . children [ 1 ] . children [ 0 ] ) . toBe ( initialResult . items [ 0 ] . children [ 1 ] . children [ 1 ] ) ;
531
+ expect ( result . current . items [ 0 ] . children [ 1 ] . children [ 0 ] ) . toEqual ( initialResult . items [ 0 ] . children [ 1 ] . children [ 1 ] ) ;
532
532
expect ( result . current . items [ 0 ] . children [ 1 ] . children [ 1 ] ) . toBe ( initialResult . items [ 0 ] . children [ 1 ] . children [ 0 ] ) ;
533
533
expect ( result . current . items [ 0 ] . children [ 2 ] ) . toBe ( initialResult . items [ 0 ] . children [ 2 ] ) ;
534
534
} ) ;
535
535
536
+ it ( 'update parentKey when a node is moved to another parent' , function ( ) {
537
+ const { result} = renderHook ( ( ) => useTreeData ( { initialItems : initial , getChildren, getKey} ) ) ;
538
+
539
+ act ( ( ) => {
540
+ result . current . move ( 'Brad' , 'John' , 0 ) ;
541
+ } ) ;
542
+
543
+ const john = result . current . items [ 0 ] . children [ 0 ] ;
544
+ const brad = john . children [ 0 ] ;
545
+ expect ( brad . parentKey ) . toBe ( john . key ) ;
546
+ } ) ;
547
+
536
548
it ( 'should move an item to a different parent' , function ( ) {
537
549
let { result} = renderHook ( ( ) => useTreeData ( { initialItems : initial , getChildren, getKey} ) ) ;
538
550
let initialResult = result . current ;
@@ -547,7 +559,7 @@ describe('useTreeData', function () {
547
559
expect ( result . current . items [ 0 ] . children ) . toHaveLength ( 3 ) ;
548
560
expect ( result . current . items [ 0 ] . children [ 0 ] ) . not . toBe ( initialResult . items [ 0 ] . children [ 0 ] ) ;
549
561
expect ( result . current . items [ 0 ] . children [ 0 ] . children ) . toHaveLength ( 2 ) ;
550
- expect ( result . current . items [ 0 ] . children [ 0 ] . children [ 0 ] ) . toBe ( initialResult . items [ 0 ] . children [ 1 ] . children [ 1 ] ) ;
562
+ expect ( result . current . items [ 0 ] . children [ 0 ] . children [ 0 ] . value ) . toBe ( initialResult . items [ 0 ] . children [ 1 ] . children [ 1 ] . value ) ;
551
563
expect ( result . current . items [ 0 ] . children [ 0 ] . children [ 1 ] ) . toBe ( initialResult . items [ 0 ] . children [ 0 ] . children [ 0 ] ) ;
552
564
expect ( result . current . items [ 0 ] . children [ 1 ] ) . not . toBe ( initialResult . items [ 0 ] . children [ 1 ] ) ;
553
565
expect ( result . current . items [ 0 ] . children [ 1 ] . children ) . toHaveLength ( 1 ) ;
0 commit comments