-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhierarchy-test.js
40 lines (37 loc) · 1.47 KB
/
hierarchy-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var vows = require("vows"),
load = require("../load"),
assert = require("../assert");
var suite = vows.describe("d3.layout.hierarchy");
suite.addBatch({
"hierarchy": {
topic: load("layout/treemap").expression("d3.layout.treemap"), // hierarchy is abstract, so test a subclass
"doesn't overwrite the value of a node that has an empty children array": function(hierarchy) {
var h = hierarchy(),
nodes = h.sticky(true).nodes({value: 1, children: []});
assert.equal(nodes[0].value, 1);
h.nodes(nodes[0]);
assert.equal(nodes[0].value, 1);
},
"a valueless node that has an empty children array gets a value of 0": function(hierarchy) {
var h = hierarchy(),
nodes = h.sticky(true).nodes({children: []});
assert.equal(nodes[0].value, 0);
h.nodes(nodes[0]);
assert.equal(nodes[0].value, 0);
},
"removes the children array for a node that has no children": function(hierarchy) {
var h = hierarchy(),
nodes = h.children(function() { return null; }).nodes({children: [{}]});
assert.equal(nodes[0].value, 0);
assert.isUndefined(nodes[0].children);
},
"revalue": function(hierarchy) {
var h = hierarchy().sticky(true),
nodes = h.nodes({children: [{children: [{value: 1}, {value: 2}]}, {value: 3}]});
assert.equal(nodes[0].value, 6);
h(nodes[0]); // calls hierarchy.revalue
assert.equal(nodes[0].value, 6);
}
}
});
suite.export(module);