|
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.filter(function(d, i) { return i > 1; }).append("span"); |
|
15 s[0][3] = null; |
|
16 |
|
17 return s.transition() |
|
18 .delay(function(d, i) { return i * 13; }) |
|
19 .duration(function(d, i) { return i * 21; }); |
|
20 }, |
|
21 |
|
22 "selects all matching elements": function(transition) { |
|
23 var t = transition.selectAll("span"); |
|
24 assert.domEqual(t[1][0].node.parentNode, transition[0][1].node); |
|
25 assert.domEqual(t[2][0].node.parentNode, transition[0][2].node); |
|
26 assert.domEqual(t[2][1].node.parentNode, transition[0][2].node); |
|
27 }, |
|
28 "ignores null elements": function(transition) { |
|
29 var t = transition.selectAll("span"); |
|
30 assert.equal(t.length, 3); |
|
31 }, |
|
32 "propagates delay to the selected elements": function(transition) { |
|
33 var t = transition.selectAll("span"); |
|
34 assert.domEqual(t[1][0].delay, 13); |
|
35 assert.domEqual(t[2][0].delay, 26); |
|
36 assert.domEqual(t[2][1].delay, 26); |
|
37 }, |
|
38 "propagates duration to the selected elements": function(transition) { |
|
39 var t = transition.selectAll("span"); |
|
40 assert.domEqual(t[1][0].duration, 21); |
|
41 assert.domEqual(t[2][0].duration, 42); |
|
42 assert.domEqual(t[2][1].duration, 42); |
|
43 }, |
|
44 "returns empty if no match is found": function(transition) { |
|
45 var t = transition.selectAll("span"); |
|
46 assert.isEmpty(t[0]); |
|
47 }, |
|
48 "inherits transition id": function(transition) { |
|
49 var id = transition.id, |
|
50 t0 = transition.selectAll("span"), |
|
51 t1 = transition.selectAll("span"); |
|
52 assert.equal(t0.id, id); |
|
53 assert.equal(t1.id, id); |
|
54 }, |
|
55 "groups are not instances of NodeList": function(transition) { |
|
56 var t = transition.selectAll(function() { return this.getElementsByClassName("span"); }); |
|
57 assert.isFalse(t[0] instanceof window.NodeList); |
|
58 } |
|
59 }; |