|
1 require("../env"); |
|
2 require("../../d3"); |
|
3 |
|
4 var assert = require("assert"); |
|
5 |
|
6 module.exports = { |
|
7 topic: function() { |
|
8 var s = d3.select("body").append("div").selectAll("div") |
|
9 .data(["one", "two", "three", "four"]) |
|
10 .enter().append("div") |
|
11 .attr("class", String); |
|
12 |
|
13 s.filter(function(d, i) { return i > 0; }).append("span"); |
|
14 s[0][3] = null; |
|
15 |
|
16 return s.transition() |
|
17 .delay(function(d, i) { return i * 13; }) |
|
18 .duration(function(d, i) { return i * 21; }); |
|
19 }, |
|
20 |
|
21 "selects the first matching element": function(transition) { |
|
22 var t = transition.select("span"); |
|
23 assert.domEqual(t[0][1].node.parentNode, transition[0][1].node); |
|
24 assert.domEqual(t[0][2].node.parentNode, transition[0][2].node); |
|
25 }, |
|
26 "ignores null elements": function(transition) { |
|
27 var t = transition.select("span"); |
|
28 assert.isNull(t[0][3]); |
|
29 }, |
|
30 "propagates data to the selected elements": function(transition) { |
|
31 var t = transition.select("span"); |
|
32 assert.equal(t[0][1].node.__data__, "two"); |
|
33 assert.equal(t[0][2].node.__data__, "three"); |
|
34 }, |
|
35 "propagates delay to the selected elements": function(transition) { |
|
36 var t = transition.select("span"); |
|
37 assert.equal(t[0][1].delay, 13); |
|
38 assert.equal(t[0][2].delay, 26); |
|
39 }, |
|
40 "propagates duration to the selected elements": function(transition) { |
|
41 var t = transition.select("span"); |
|
42 assert.equal(t[0][1].duration, 21); |
|
43 assert.equal(t[0][2].duration, 42); |
|
44 }, |
|
45 "does not propagate data if no data was specified": function(transition) { |
|
46 delete transition[0][1].node.__data__; |
|
47 delete transition[0][1].node.firstChild.__data__; |
|
48 var t = transition.select("span"); |
|
49 assert.isUndefined(t[0][1].node.__data__); |
|
50 assert.equal(t[0][2].node.__data__, "three"); |
|
51 }, |
|
52 "returns null if no match is found": function(transition) { |
|
53 var t = transition.select("span"); |
|
54 assert.isNull(t[0][0]); |
|
55 }, |
|
56 "inherits transition id": function(transition) { |
|
57 var id = transition.id, |
|
58 t0 = transition.select("span"), |
|
59 t1 = transition.select("span"); |
|
60 assert.equal(t0.id, id); |
|
61 assert.equal(t1.id, id); |
|
62 } |
|
63 }; |