1
+ const expect = require ( 'chai' ) . expect
2
+
3
+ describe ( 'Test Dependencies' , ( ) => {
4
+ before ( ( ) => {
5
+ this . isDependant = require ( '../dependencies.js' ) . isDependant ;
6
+ this . isHeadOf = {
7
+ "PARENT" : {
8
+ "CHILD_SING" : "SING:" ,
9
+ "CHILD_MULT" : "MULT:" ,
10
+ "CHILD_MULT_UNID" : "MULT:UNID" ,
11
+ "CHILD_MULT_LEFT" : "MULT:LEFT" ,
12
+ "CHILD_MULT_RIGHT" : "MULT:RIGHT"
13
+ }
14
+ }
15
+ } )
16
+
17
+ it ( 'Should only get one dependant if SING' , ( ) => {
18
+ const child = { type : 'CHILD_SING' , position : 0 , children : [ ] }
19
+ const parent = { type : 'PARENT' , position : 1 , children : [ ] }
20
+
21
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . true
22
+
23
+ //add a children with the same name
24
+ parent . children . push ( { type : 'CHILD_SING' , position : 2 } )
25
+
26
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . false
27
+ } )
28
+
29
+ it ( 'Should get many dependants if MULT' , ( ) => {
30
+ const child = { type : 'CHILD_MULT' , position : 0 , children : [ ] }
31
+ const parent = { type : 'PARENT' , position : 1 , children : [ ] }
32
+
33
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . true
34
+
35
+ //add a children with the same name
36
+ parent . children . push ( { type : 'CHILD_MULT' , position : 2 } )
37
+
38
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . true
39
+ } )
40
+
41
+ it ( 'Should only get dependants on one side if MULT:UNID' , ( ) => {
42
+ const child = { type : 'CHILD_MULT_UNID' , position : 0 , children : [ ] }
43
+ const parent = { type : 'PARENT' , position : 2 , children : [ ] }
44
+
45
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . true
46
+
47
+ //add a children with the same name on the same direction
48
+ parent . children . push ( { type : 'CHILD_MULT_UNID' , position : 1 } )
49
+
50
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . true
51
+
52
+ //clear children
53
+ parent . children . length = 0
54
+ //add a children with the same name on a different direction
55
+ parent . children . push ( { type : 'CHILD_MULT_UNID' , position : 3 } )
56
+
57
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . false
58
+ } )
59
+
60
+ it ( 'Should only get dependants on the left if MULT:RIGHT (because RIGHT refers to the position of the HEAD)' , ( ) => {
61
+ const child = { type : 'CHILD_MULT_RIGHT' , position : 0 , children : [ ] }
62
+ const parent = { type : 'PARENT' , position : 2 , children : [ ] }
63
+
64
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . true
65
+
66
+ //add a children with the same name to the left
67
+ parent . children . push ( { type : 'CHILD_MULT_RIGHT' , position : 1 } )
68
+
69
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . true
70
+
71
+ //change child position to the right
72
+ child . position = 3
73
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . false
74
+ } )
75
+
76
+ it ( 'Should only get dependants on the left if MULT:LEFT (because RIGHT refers to the position of the HEAD)' , ( ) => {
77
+ const child = { type : 'CHILD_MULT_LEFT' , position : 2 , children : [ ] }
78
+ const parent = { type : 'PARENT' , position : 1 , children : [ ] }
79
+
80
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . true
81
+
82
+ //add a children with the same name to the right
83
+ parent . children . push ( { type : 'CHILD_LEFT' , position : 3 } )
84
+
85
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . true
86
+
87
+ //change child position to the left
88
+ child . position = 0
89
+ expect ( this . isDependant ( child , parent , this . isHeadOf ) ) . false
90
+ } )
91
+ } )
0 commit comments