@@ -15,84 +15,71 @@ describe('orgchart -- unit tests', function () {
15
15
16
16
var $container = $ ( '#chart-container' ) ,
17
17
ds = {
18
- 'id' : '1 ' ,
18
+ 'id' : 'n1 ' ,
19
19
'name' : 'Lao Lao' ,
20
20
'title' : 'general manager' ,
21
21
'children' : [
22
- { 'id' : '2 ' , 'name' : 'Bo Miao' , 'title' : 'department manager' } ,
23
- { 'id' : '3 ' , 'name' : 'Su Miao' , 'title' : 'department manager' ,
22
+ { 'id' : 'n2 ' , 'name' : 'Bo Miao' , 'title' : 'department manager' } ,
23
+ { 'id' : 'n3 ' , 'name' : 'Su Miao' , 'title' : 'department manager' ,
24
24
'children' : [
25
- { 'id' : '6 ' , 'name' : 'Tie Hua' , 'title' : 'senior engineer' } ,
26
- { 'id' : '7 ' , 'name' : 'Hei Hei' , 'title' : 'senior engineer' ,
25
+ { 'id' : 'n5 ' , 'name' : 'Tie Hua' , 'title' : 'senior engineer' } ,
26
+ { 'id' : 'n6 ' , 'name' : 'Hei Hei' , 'title' : 'senior engineer' ,
27
27
'children' : [
28
- { 'id' : '9' , 'name' : 'Dan Dan' , 'title' : 'engineer' ,
29
- 'children' : [
30
- { 'id' : '10' , 'name' : 'Er Dan' , 'title' : 'intern' }
31
- ]
32
- }
28
+ { 'id' : 'n8' , 'name' : 'Dan Dan' , 'title' : 'engineer' }
33
29
]
34
30
} ,
35
- { 'id' : '8 ' , 'name' : 'Pang Pang' , 'title' : 'senior engineer' }
31
+ { 'id' : 'n7 ' , 'name' : 'Pang Pang' , 'title' : 'senior engineer' }
36
32
]
37
33
} ,
38
- { 'id' : '4' , 'name' : 'Hong Miao' , 'title' : 'department manager' } ,
39
- { 'id' : '5' , 'name' : 'Chun Miao' , 'title' : 'department manager' }
34
+ { 'id' : 'n4' , 'name' : 'Hong Miao' , 'title' : 'department manager' }
40
35
]
41
36
} ,
42
37
oc = { } ,
43
38
hierarchy = {
44
- id : '1 ' ,
39
+ id : 'n1 ' ,
45
40
children : [
46
- { id : '2 ' } ,
47
- { id : '3 ' ,
41
+ { id : 'n2 ' } ,
42
+ { id : 'n3 ' ,
48
43
children : [
49
- { id : '6 ' } ,
50
- { id : '7 ' ,
44
+ { id : 'n5 ' } ,
45
+ { id : 'n6 ' ,
51
46
children : [
52
- { id : '9' ,
53
- children : [
54
- { id : '10' }
55
- ]
56
- }
47
+ { id : 'n8' }
57
48
]
58
49
} ,
59
- { id : '8 ' }
50
+ { id : 'n7 ' }
60
51
]
61
52
} ,
62
- { id : '4' } ,
63
- { id : '5' }
53
+ { id : 'n4' }
64
54
]
65
55
} ,
66
- $root ,
56
+ $laolao ,
67
57
$bomiao ,
68
58
$sumiao ,
69
59
$hongmiao ,
70
60
$chunmiao ,
71
61
$tiehua ,
72
62
$heihei ,
73
63
$pangpang ,
74
- $dandan ,
75
- $erdan ;
64
+ $dandan ;
76
65
77
66
beforeEach ( function ( ) {
78
67
oc = $ ( '#chart-container' ) . orgchart ( {
79
68
'data' : ds ,
80
69
'nodeContent' : 'title'
81
70
} ) ,
82
- $root = $ ( '#1' ) ,
83
- $bomiao = $ ( '#2' ) ,
84
- $sumiao = $ ( '#3' ) ,
85
- $hongmiao = $ ( '#4' ) ,
86
- $chunmiao = $ ( '#5' ) ,
87
- $tiehua = $ ( '#6' ) ,
88
- $heihei = $ ( '#7' ) ,
89
- $pangpang = $ ( '#8' ) ,
90
- $dandan = $ ( '#9' ) ,
91
- $erdan = $ ( '#10' ) ;
71
+ $laolao = $ ( '#n1' ) ,
72
+ $bomiao = $ ( '#n2' ) ,
73
+ $sumiao = $ ( '#n3' ) ,
74
+ $hongmiao = $ ( '#n4' ) ,
75
+ $tiehua = $ ( '#n5' ) ,
76
+ $heihei = $ ( '#n6' ) ,
77
+ $pangpang = $ ( '#n7' ) ,
78
+ $dandan = $ ( '#n8' ) ;
92
79
} ) ;
93
80
94
81
afterEach ( function ( ) {
95
- $root = $bomiao = $sumiao = $hongmiao = $chunmiao = $ tiehua = $heihei = $pangpang = $dandan = $erdan = null ;
82
+ $laolao = $bomiao = $sumiao = $hongmiao = $tiehua = $heihei = $pangpang = $dandan = null ;
96
83
$container . empty ( ) ;
97
84
} ) ;
98
85
@@ -119,9 +106,9 @@ describe('orgchart -- unit tests', function () {
119
106
120
107
it ( 'getNodeState() works well' , function ( ) {
121
108
oc . init ( { 'depth' : 2 } ) . $chart . on ( 'init.orgchart' , function ( ) {
122
- oc . getNodeState ( $root , 'parent' ) . should . deep . equal ( { 'exist' : false , 'visible' : false } ) ;
123
- oc . getNodeState ( $root , 'children' ) . should . deep . equal ( { 'exist' : true , 'visible' : true } ) ;
124
- oc . getNodeState ( $root , 'siblings' ) . should . deep . equal ( { 'exist' : false , 'visible' : false } ) ;
109
+ oc . getNodeState ( $laolao , 'parent' ) . should . deep . equal ( { 'exist' : false , 'visible' : false } ) ;
110
+ oc . getNodeState ( $laolao , 'children' ) . should . deep . equal ( { 'exist' : true , 'visible' : true } ) ;
111
+ oc . getNodeState ( $laolao , 'siblings' ) . should . deep . equal ( { 'exist' : false , 'visible' : false } ) ;
125
112
126
113
oc . getNodeState ( $bomiao , 'parent' ) . should . deep . equal ( { 'exist' : true , 'visible' : true } ) ;
127
114
oc . getNodeState ( $bomiao , 'children' ) . should . deep . equal ( { 'exist' : false , 'visible' : false } ) ;
@@ -154,32 +141,32 @@ describe('orgchart -- unit tests', function () {
154
141
oc . getRelatedNodes ( $ ( 'td:first' ) , 'children' ) . should . deep . equal ( $ ( ) ) ;
155
142
oc . getRelatedNodes ( $ ( '.node:first' ) , 'child' ) . should . deep . equal ( $ ( ) ) ;
156
143
157
- oc . getRelatedNodes ( $root , 'parent' ) . should . deep . equal ( $ ( ) ) ;
158
- oc . getRelatedNodes ( $root , 'children' ) . toArray ( ) . should . members ( [ $bomiao [ 0 ] , $sumiao [ 0 ] , $hongmiao [ 0 ] , $chunmiao [ 0 ] ] ) ;
159
- oc . getRelatedNodes ( $root , 'siblings' ) . should . deep . equal ( $ ( ) ) ;
144
+ oc . getRelatedNodes ( $laolao , 'parent' ) . should . deep . equal ( $ ( ) ) ;
145
+ oc . getRelatedNodes ( $laolao , 'children' ) . toArray ( ) . should . members ( [ $bomiao [ 0 ] , $sumiao [ 0 ] , $hongmiao [ 0 ] ] ) ;
146
+ oc . getRelatedNodes ( $laolao , 'siblings' ) . should . deep . equal ( $ ( ) ) ;
160
147
161
- oc . getRelatedNodes ( $bomiao , 'parent' ) . should . deep . equal ( $root ) ;
148
+ oc . getRelatedNodes ( $bomiao , 'parent' ) . should . deep . equal ( $laolao ) ;
162
149
oc . getRelatedNodes ( $bomiao , 'children' ) . should . have . lengthOf ( 0 ) ;
163
- oc . getRelatedNodes ( $bomiao , 'siblings' ) . toArray ( ) . should . members ( [ $sumiao [ 0 ] , $hongmiao [ 0 ] , $chunmiao [ 0 ] ] ) ;
150
+ oc . getRelatedNodes ( $bomiao , 'siblings' ) . toArray ( ) . should . members ( [ $sumiao [ 0 ] , $hongmiao [ 0 ] ] ) ;
164
151
} ) ;
165
152
166
153
it ( 'hideParent() works well' , function ( ) {
167
154
var spy = sinon . spy ( oc , 'hideSiblings' ) ;
168
155
oc . hideParent ( $heihei ) ;
169
156
spy . should . have . been . callCount ( 2 ) ;
170
157
oc . hideParentEnd ( { 'target' : $sumiao [ 0 ] , 'data' : { 'upperLevel' : $heihei . closest ( '.nodes' ) . siblings ( ) } } ) ;
171
- oc . hideParentEnd ( { 'target' : $root [ 0 ] , 'data' : { 'upperLevel' : $sumiao . closest ( '.nodes' ) . siblings ( ) } } ) ;
158
+ oc . hideParentEnd ( { 'target' : $laolao [ 0 ] , 'data' : { 'upperLevel' : $sumiao . closest ( '.nodes' ) . siblings ( ) } } ) ;
172
159
173
160
$heihei . parents ( '.nodes' ) . each ( function ( ) {
174
161
$ ( this ) . siblings ( ) . filter ( '.hidden' ) . should . lengthOf ( 3 ) ;
175
162
} ) ;
176
163
$sumiao . is ( '.slide-down' ) . should . be . true ;
177
- $root . is ( '.slide-down' ) . should . be . true ;
164
+ $laolao . is ( '.slide-down' ) . should . be . true ;
178
165
} ) ;
179
166
180
167
it ( 'showParent() works well' , function ( ) {
181
168
var spy = sinon . spy ( oc , 'repaint' ) ;
182
- $root . add ( $sumiao ) . closest ( 'tr' ) . nextUntil ( '.nodes' ) . addBack ( ) . addClass ( 'hidden' ) ;
169
+ $laolao . add ( $sumiao ) . closest ( 'tr' ) . nextUntil ( '.nodes' ) . addBack ( ) . addClass ( 'hidden' ) ;
183
170
oc . showParent ( $heihei ) ;
184
171
spy . should . have . been . called ;
185
172
var $upperLevel = $heihei . closest ( '.nodes' ) . siblings ( ) ;
@@ -196,13 +183,17 @@ describe('orgchart -- unit tests', function () {
196
183
} ) ;
197
184
198
185
it ( 'hideChildren() works well' , function ( ) {
199
- oc . hideChildren ( $heihei ) ;
200
- $heihei . closest ( 'table' ) . find ( '.lines' ) . filter ( '[style*="visibility: hidden"]' ) . should . lengthOf ( 4 ) ;
186
+ oc . hideChildren ( $sumiao ) ;
187
+ $sumiao . closest ( 'table' ) . find ( '.lines' ) . filter ( '[style*="visibility: hidden"]' ) . should . lengthOf ( 4 ) ;
188
+ $tiehua . is ( '.sliding,.slide-up' ) . should . be . true ;
189
+ $heihei . is ( '.sliding,.slide-up' ) . should . be . true ;
190
+ $pangpang . is ( '.sliding,.slide-up' ) . should . be . true ;
201
191
$dandan . is ( '.sliding,.slide-up' ) . should . be . true ;
202
- $erdan . is ( '.sliding,.slide-up' ) . should . be . true ;
203
- oc . hideChildrenEnd ( { 'data' : { 'visibleNodes' : $dandan . add ( $erdan ) , 'lowerLevel' : $heihei . closest ( 'tr' ) . siblings ( ) , 'isVerticalDesc' : false , 'node' : $heihei } } ) ;
192
+ oc . hideChildrenEnd ( { 'data' : { 'visibleNodes' : $ ( [ $tiehua [ 0 ] , $heihei [ 0 ] , $pangpang [ 0 ] , $dandan [ 0 ] ] ) , 'lowerLevel' : $sumiao . closest ( 'tr' ) . siblings ( ) , 'isVerticalDesc' : false , 'node' : $sumiao } } ) ;
193
+ $tiehua . is ( '.sliding' ) . should . be . false ;
194
+ $heihei . is ( '.sliding' ) . should . be . false ;
195
+ $pangpang . is ( '.sliding' ) . should . be . false ;
204
196
$dandan . is ( '.sliding' ) . should . be . false ;
205
- $erdan . is ( '.sliding' ) . should . be . false ;
206
197
} ) ;
207
198
208
199
} ) ;
0 commit comments