1
1
var chai = require ( "chai" ) ;
2
2
var sinon = require ( "sinon" ) ;
3
3
var sinonChai = require ( "sinon-chai" ) ;
4
- chai . should ( ) ;
4
+ var should = chai . should ( ) ;
5
5
chai . use ( sinonChai ) ;
6
6
var jsdom = require ( "jsdom" ) ;
7
7
var { JSDOM } = jsdom ;
@@ -101,17 +101,57 @@ describe('orgchart -- integration tests', function () {
101
101
$container . empty ( ) ;
102
102
} ) ;
103
103
104
- it ( "Adding new root node" , function ( ) {
104
+ it ( 'addParent()' , function ( ) {
105
105
oc . addParent ( $laolao , { 'name' : 'Lao Ye' , 'id' : 'n0' } ) ;
106
106
$laolao . closest ( '.nodes' ) . prevAll ( ) . should . lengthOf ( 3 ) ;
107
107
oc . $chart . find ( '.node:first' ) . should . deep . equal ( $ ( '#n0' ) ) ;
108
108
} ) ;
109
109
110
- it ( "when one node's parent is hidden, its sibling branches are hidden too" , function ( ) {
111
- oc . hideParent ( $hongmiao ) ;
112
- $bomiao . is ( '.slide-right' ) . should . be . true ;
113
- $sumiao . is ( '.slide-right' ) . should . be . true ;
114
- $sumiao . find ( '.slide-right' ) . should . lengthOf ( $sumiao . find ( '.node' ) . length ) ;
110
+ describe ( 'addChildren()' , function ( ) {
111
+ it ( 'Add child nodes to the leaf node' , function ( ) {
112
+ oc . addChildren ( $bomiao , { 'children' : [ { 'name' : 'Li Xin' , 'id' : 'n11' } ] } ) ;
113
+ $bomiao . closest ( 'tr' ) . siblings ( ) . should . lengthOf ( 3 ) ;
114
+ $bomiao . closest ( 'tr' ) . siblings ( '.nodes' ) . find ( '.node' ) . attr ( 'id' ) . should . equal ( 'n11' ) ;
115
+ } ) ;
116
+
117
+ it ( 'Add child nodes to the un-leaf node' , function ( ) {
118
+ oc . addChildren ( $sumiao , { 'children' : [ { 'name' : 'Li Xin' , 'id' : 'n11' } ] } ) ;
119
+ $sumiao . closest ( 'tr' ) . siblings ( '.nodes' ) . children ( ) . should . lengthOf ( 4 ) ;
120
+ $sumiao . closest ( 'tr' ) . siblings ( '.nodes' ) . children ( ':last' ) . find ( '.node' ) . attr ( 'id' ) . should . equal ( 'n11' ) ;
121
+ } ) ;
122
+ } ) ;
123
+
124
+ describe ( 'addSiblings()' , function ( ) {
125
+ it ( 'Just add sibling nodes' , function ( ) {
126
+ oc . addSiblings ( $sumiao , { 'siblings' : [ { 'name' : 'Li Xin' , 'id' : 'n11' } ] } ) ;
127
+ $laolao . closest ( 'tr' ) . siblings ( '.nodes' ) . children ( ) . should . lengthOf ( 4 ) ;
128
+ $laolao . closest ( 'tr' ) . siblings ( '.nodes' ) . children ( ':last' ) . find ( '.node' ) . attr ( 'id' ) . should . equal ( 'n11' ) ;
129
+ } ) ;
130
+
131
+ it ( 'Add sibling nodes as well as parent node' , function ( ) {
132
+ oc . addSiblings ( $laolao , { 'name' : 'Lao Ye' , 'id' : 'n0' , 'children' : [ { 'name' : 'Li Xin' , 'id' : 'n11' } ] } ) ;
133
+ $laolao . closest ( '.nodes' ) . prevAll ( ) . should . lengthOf ( 3 ) ;
134
+ oc . $chart . find ( '.node:first' ) . should . deep . equal ( $ ( '#n0' ) ) ;
135
+ $laolao . closest ( 'table' ) . parent ( ) . siblings ( ) . should . lengthOf ( 1 ) ;
136
+ $laolao . closest ( 'table' ) . parent ( ) . siblings ( ) . find ( '.node' ) . attr ( 'id' ) . should . equal ( 'n11' ) ;
137
+ } ) ;
138
+ } ) ;
139
+
140
+ describe ( 'removeNodes()' , function ( ) {
141
+ it ( 'Remove leaf node' , function ( ) {
142
+ oc . removeNodes ( $dandan ) ;
143
+ $tiehua . closest ( 'tr' ) . siblings ( ) . should . lengthOf ( 0 ) ;
144
+ } ) ;
145
+ it ( 'Remove parent node' , function ( ) {
146
+ oc . removeNodes ( $tiehua ) ;
147
+ $sumiao . closest ( 'tr' ) . siblings ( '.nodes' ) . children ( ) . should . lengthOf ( 2 ) ;
148
+ $ ( '#n5' ) . should . lengthOf ( 0 ) ;
149
+ $ ( '#n8' ) . should . lengthOf ( 0 ) ;
150
+ } ) ;
151
+ it ( 'Remove parent node' , function ( ) {
152
+ oc . removeNodes ( $laolao ) ;
153
+ oc . $chartContainer . is ( ':empty' ) . should . be . true ;
154
+ } ) ;
115
155
} ) ;
116
156
117
157
} ) ;
0 commit comments