forked from linkedin/parseq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd3Treeify-test.js
More file actions
142 lines (117 loc) · 4.21 KB
/
d3Treeify-test.js
File metadata and controls
142 lines (117 loc) · 4.21 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var assert = require('./assert'),
CDigraph = require('graphlib').CDigraph,
d3Treeify = require('../../lib/trace/d3Treeify');
describe('d3Treeify', function() {
it('can treeify a single node', function() {
var g = new CDigraph();
var n1 = createNode();
n1.name = 'foo';
n1.value = 'bar';
g.addNode(1, n1);
var root = d3Treeify(g);
assert.deepPropertyVal(root, 'children[0].id', 1);
assert.deepPropertyVal(root, 'children[0].name', n1.name);
assert.deepPropertyVal(root, 'children[0].value', n1.value);
});
it('adds a totalMillis property derived from startNanos and endNanos', function() {
var g = new CDigraph();
var n1 = createNode();
n1.startNanos = 50 * 1000 * 1000;
n1.endNanos = 125 * 1000 * 1000;
g.addNode(1, n1);
var root = d3Treeify(g);
assert.deepPropertyVal(root, 'children[0].id', 1);
assert.deepPropertyVal(root, 'children[0].totalMillis', 75);
});
it('adds a runMillis property derived from startNanos and pendingNanos', function() {
var g = new CDigraph();
var n1 = createNode();
n1.startNanos = 50 * 1000 * 1000;
n1.pendingNanos = 125 * 1000 * 1000;
g.addNode(1, n1);
var root = d3Treeify(g);
assert.deepPropertyVal(root, 'children[0].id', 1);
assert.deepPropertyVal(root, 'children[0].runMillis', 75);
});
it('does not add a runMillis property if pendingNanos is missing', function() {
var g = new CDigraph();
var n1 = createNode();
n1.startNanos = 50 * 1000 * 1000;
g.addNode(1, n1);
var root = d3Treeify(g);
assert.deepPropertyVal(root, 'children[0].id', 1);
assert.notDeepProperty(root, 'children[0].runMillis');
});
it('can handle a shallow tree of nodes', function() {
var g = new CDigraph();
var n1 = createNode();
var n2 = createNode();
n2.name = 'some other node';
n2.value = 'some other value';
g.addNode(1, n1);
g.addNode(2, n2);
g.parent(2, 1);
var root = d3Treeify(g);
assert.deepPropertyVal(root, 'children[0].id', 1);
assert.deepPropertyVal(root, 'children[0].children[0].id', 2);
assert.deepPropertyVal(root, 'children[0].children[0].name', n2.name);
assert.deepPropertyVal(root, 'children[0].children[0].value', n2.value);
});
it('can handle deeply nested trees', function() {
var g = new CDigraph();
g.addNode(1, createNode());
g.addNode(2, createNode());
g.parent(2, 1);
g.addNode(3, createNode());
g.parent(3, 1);
g.addNode(4, createNode());
g.parent(4, 3);
g.addNode(5, createNode());
g.parent(5, 3);
var root = d3Treeify(g);
assert.deepPropertyVal(root, 'children[0].id', 1);
assert.deepPropertyVal(root, 'children[0].children[0].id', 2);
assert.deepPropertyVal(root, 'children[0].children[1].id', 3);
assert.deepPropertyVal(root, 'children[0].children[1].children[0].id', 4);
assert.deepPropertyVal(root, 'children[0].children[1].children[1].id', 5);
});
it('sets start time relative to smallest start time in the graph', function() {
var g = new CDigraph();
var n1 = createNode();
n1.startNanos = 50 * 1000 * 1000;
n1.endNanos = 500 * 1000 * 1000;
var n2 = createNode();
n2.startNanos = 100 * 1000 * 1000;
n2.endNanos = 300 * 1000 * 1000;
g.addNode(1, n1);
g.addNode(2, n2);
g.parent(2, 1);
var root = d3Treeify(g);
assert.deepPropertyVal(root, 'children[0].startMillis', 0);
assert.deepPropertyVal(root, 'children[0].totalMillis', 450);
assert.deepPropertyVal(root, 'children[0].children[0].startMillis', 50);
assert.deepPropertyVal(root, 'children[0].children[0].totalMillis', 200);
});
it('works for two root nodes', function() {
var g = new CDigraph();
g.addNode(1, createNode());
g.addNode(2, createNode());
var root = d3Treeify(g);
assert.lengthOf(root.children, 2);
assert.sameMembers(root.children.map(function(x) { return x.id; }), [1, 2]);
});
it('fails for an empty graph', function() {
assert.throws(function() { d3Treeify(new CDigraph()); });
});
});
function createNode() {
return {
hidden: false,
systemHidden: false,
name: 'unset name',
value: 'unset value',
resultType: 'SUCCESS',
startNanos: 0,
endNanos: 0
};
}