@@ -10,13 +10,17 @@ describe('arrayToTree', () => {
10
10
{ id : '1' , parentId : '418' , custom : 'ZZZz' } ,
11
11
{ id : '418' , parentId : null , custom : 'ü' } ,
12
12
] ) ) . to . deep . equal ( [
13
- { data : { id : '4' , parentId : null , custom : 'abc' } , children : [
14
- { data : { id : '31' , parentId : '4' , custom : '12' } , children : [ ] } ,
15
- ] } ,
16
- { data : { id : '418' , parentId : null , custom : 'ü' } , children : [
17
- { data : { id : '1941' , parentId : '418' , custom : 'de' } , children : [ ] } ,
18
- { data : { id : '1' , parentId : '418' , custom : 'ZZZz' } , children : [ ] } ,
19
- ] } ,
13
+ {
14
+ data : { id : '4' , parentId : null , custom : 'abc' } , children : [
15
+ { data : { id : '31' , parentId : '4' , custom : '12' } , children : [ ] } ,
16
+ ] ,
17
+ } ,
18
+ {
19
+ data : { id : '418' , parentId : null , custom : 'ü' } , children : [
20
+ { data : { id : '1941' , parentId : '418' , custom : 'de' } , children : [ ] } ,
21
+ { data : { id : '1' , parentId : '418' , custom : 'ZZZz' } , children : [ ] } ,
22
+ ] ,
23
+ } ,
20
24
] )
21
25
} )
22
26
@@ -31,13 +35,40 @@ describe('arrayToTree', () => {
31
35
] as any ) ,
32
36
{ id : 'num' , parentId : 'ref' } ,
33
37
) ) . to . deep . equal ( [
34
- { data : { num : '4' , ref : null , custom : 'abc' } , children : [
35
- { data : { num : '31' , ref : '4' , custom : '12' } , children : [ ] } ,
36
- ] } ,
37
- { data : { num : '418' , ref : null , custom : 'ü' } , children : [
38
- { data : { num : '1941' , ref : '418' , custom : 'de' } , children : [ ] } ,
39
- { data : { num : '1' , ref : '418' , custom : 'ZZZz' } , children : [ ] } ,
40
- ] } ,
38
+ {
39
+ data : { num : '4' , ref : null , custom : 'abc' } , children : [
40
+ { data : { num : '31' , ref : '4' , custom : '12' } , children : [ ] } ,
41
+ ] ,
42
+ } ,
43
+ {
44
+ data : { num : '418' , ref : null , custom : 'ü' } , children : [
45
+ { data : { num : '1941' , ref : '418' , custom : 'de' } , children : [ ] } ,
46
+ { data : { num : '1' , ref : '418' , custom : 'ZZZz' } , children : [ ] } ,
47
+ ] ,
48
+ } ,
49
+ ] )
50
+ } )
51
+
52
+ it ( 'should ignore objects if parentId does not exist' , ( ) => {
53
+ expect ( arrayToTree ( [
54
+ { id : '4' , parentId : null , custom : 'abc' } ,
55
+ { id : '31' , parentId : '4' , custom : '12' } ,
56
+ { id : '1941' , parentId : '418' , custom : 'de' } ,
57
+ { id : '1' , parentId : '418' , custom : 'ZZZz' } ,
58
+ { id : '418' , parentId : null , custom : 'ü' } ,
59
+ { id : '1313' , parentId : '13' , custom : 'Not existing' } ,
60
+ ] ) ) . to . deep . equal ( [
61
+ {
62
+ data : { id : '4' , parentId : null , custom : 'abc' } , children : [
63
+ { data : { id : '31' , parentId : '4' , custom : '12' } , children : [ ] } ,
64
+ ] ,
65
+ } ,
66
+ {
67
+ data : { id : '418' , parentId : null , custom : 'ü' } , children : [
68
+ { data : { id : '1941' , parentId : '418' , custom : 'de' } , children : [ ] } ,
69
+ { data : { id : '1' , parentId : '418' , custom : 'ZZZz' } , children : [ ] } ,
70
+ ] ,
71
+ } ,
41
72
] )
42
73
} )
43
74
0 commit comments