@@ -495,6 +495,7 @@ describe("arrayToTree", () => {
495
495
} ,
496
496
] ) ;
497
497
} ) ;
498
+
498
499
it ( "should work with nested id property" , ( ) => {
499
500
expect (
500
501
arrayToTree (
@@ -516,6 +517,7 @@ describe("arrayToTree", () => {
516
517
} ,
517
518
] ) ;
518
519
} ) ;
520
+
519
521
it ( "should work with nested parentId property" , ( ) => {
520
522
expect (
521
523
arrayToTree (
@@ -537,6 +539,7 @@ describe("arrayToTree", () => {
537
539
} ,
538
540
] ) ;
539
541
} ) ;
542
+
540
543
it ( "should work with nested id and parentId properties" , ( ) => {
541
544
expect (
542
545
arrayToTree (
@@ -558,4 +561,48 @@ describe("arrayToTree", () => {
558
561
} ,
559
562
] ) ;
560
563
} ) ;
564
+
565
+ it ( "should work with nested id and parentId properties if the parent is null" , ( ) => {
566
+ expect (
567
+ arrayToTree (
568
+ [
569
+ { one : { id : "1" } , two : null , custom : "1" } ,
570
+ { one : { id : "1.1" } , two : { parentId : "1" } , custom : "1.1" } ,
571
+ ] ,
572
+ { id : "one.id" , parentId : "two.parentId" }
573
+ )
574
+ ) . to . deep . equal ( [
575
+ {
576
+ data : { one : { id : "1" } , two : null , custom : "1" } ,
577
+ children : [
578
+ {
579
+ data : { one : { id : "1.1" } , two : { parentId : "1" } , custom : "1.1" } ,
580
+ children : [ ] ,
581
+ } ,
582
+ ] ,
583
+ } ,
584
+ ] ) ;
585
+ } ) ;
586
+
587
+ it ( "should work with nested id and parentId properties if the parent is undefined" , ( ) => {
588
+ expect (
589
+ arrayToTree (
590
+ [
591
+ { one : { id : "1" } , custom : "1" } ,
592
+ { one : { id : "1.1" } , two : { parentId : "1" } , custom : "1.1" } ,
593
+ ] ,
594
+ { id : "one.id" , parentId : "two.parentId" }
595
+ )
596
+ ) . to . deep . equal ( [
597
+ {
598
+ data : { one : { id : "1" } , custom : "1" } ,
599
+ children : [
600
+ {
601
+ data : { one : { id : "1.1" } , two : { parentId : "1" } , custom : "1.1" } ,
602
+ children : [ ] ,
603
+ } ,
604
+ ] ,
605
+ } ,
606
+ ] ) ;
607
+ } ) ;
561
608
} ) ;
0 commit comments