|
1 require("../env"); |
|
2 require("../../d3"); |
|
3 |
|
4 var vows = require("vows"), |
|
5 assert = require("assert"); |
|
6 |
|
7 var suite = vows.describe("selection.property"); |
|
8 |
|
9 suite.addBatch({ |
|
10 "select(body)": { |
|
11 topic: function() { |
|
12 return d3.select("body").html(""); |
|
13 }, |
|
14 "sets a property as a string": function(body) { |
|
15 body.property("bgcolor", "red"); |
|
16 assert.equal(document.body.bgcolor, "red"); |
|
17 }, |
|
18 "sets a property as a number": function(body) { |
|
19 body.property("opacity", 1); |
|
20 assert.equal(document.body.opacity, "1"); |
|
21 }, |
|
22 "sets a property as a function": function(body) { |
|
23 body.property("bgcolor", function() { return "orange"; }); |
|
24 assert.equal(document.body.bgcolor, "orange"); |
|
25 }, |
|
26 "gets a property value": function(body) { |
|
27 document.body.bgcolor = "yellow"; |
|
28 assert.equal(body.property("bgcolor"), "yellow"); |
|
29 }, |
|
30 "removes a property as null": function(body) { |
|
31 body.property("bgcolor", "yellow").property("bgcolor", null); |
|
32 assert.isFalse("bgcolor" in document.body); |
|
33 }, |
|
34 "removes a property as a function": function(body) { |
|
35 body.property("bgcolor", "yellow").property("bgcolor", function() { return null }); |
|
36 assert.isFalse("bgcolor" in document.body); |
|
37 }, |
|
38 "returns the current selection": function(body) { |
|
39 assert.isTrue(body.property("bgcolor", "yellow") === body); |
|
40 } |
|
41 } |
|
42 }); |
|
43 |
|
44 suite.addBatch({ |
|
45 "selectAll(div)": { |
|
46 topic: function() { |
|
47 return d3.select("body").html("").selectAll("div").data(d3.range(2)).enter().append("div"); |
|
48 }, |
|
49 "sets a property as a string": function(div) { |
|
50 div.property("bgcolor", "red"); |
|
51 assert.equal(div[0][0].bgcolor, "red"); |
|
52 assert.equal(div[0][1].bgcolor, "red"); |
|
53 }, |
|
54 "sets a property as a number": function(div) { |
|
55 div.property("opacity", 0.4); |
|
56 assert.equal(div[0][0].opacity, "0.4"); |
|
57 assert.equal(div[0][1].opacity, "0.4"); |
|
58 }, |
|
59 "sets a property as a function": function(div) { |
|
60 div.property("bgcolor", d3.interpolateRgb("brown", "steelblue")); |
|
61 assert.equal(div[0][0].bgcolor, "#a52a2a"); |
|
62 assert.equal(div[0][1].bgcolor, "#4682b4"); |
|
63 }, |
|
64 "gets a property value": function(div) { |
|
65 div[0][0].bgcolor = "purple"; |
|
66 assert.equal(div.property("bgcolor"), "purple"); |
|
67 }, |
|
68 "removes a property as null": function(div) { |
|
69 div.property("bgcolor", "yellow").property("bgcolor", null); |
|
70 assert.isFalse("bgcolor" in div[0][0]); |
|
71 assert.isFalse("bgcolor" in div[0][1]); |
|
72 }, |
|
73 "removes a property as a function": function(div) { |
|
74 div.property("bgcolor", "yellow").property("bgcolor", function() { return null }); |
|
75 assert.isFalse("bgcolor" in div[0][0]); |
|
76 assert.isFalse("bgcolor" in div[0][1]); |
|
77 }, |
|
78 "ignores null nodes": function(div) { |
|
79 var some = d3.selectAll("div"); |
|
80 some[0][1] = null; |
|
81 some.property("bgcolor", null).property("bgcolor", "red"); |
|
82 assert.equal(div[0][0].bgcolor, "red"); |
|
83 assert.isFalse("bgcolor" in div[0][1]); |
|
84 }, |
|
85 "returns the current selection": function(div) { |
|
86 assert.isTrue(div.property("bgcolor", "yellow") === div); |
|
87 } |
|
88 } |
|
89 }); |
|
90 |
|
91 suite.export(module); |