|
1 require("../env"); |
|
2 require("../../d3"); |
|
3 |
|
4 var vows = require("vows"), |
|
5 assert = require("assert"); |
|
6 |
|
7 var suite = vows.describe("selection.style"); |
|
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.style("background-color", "red"); |
|
16 assert.equal(document.body.style["background-color"], "red"); |
|
17 }, |
|
18 "sets a property as a number": function(body) { |
|
19 body.style("opacity", .3); |
|
20 assert.equal(document.body.style["opacity"], "0.3"); |
|
21 }, |
|
22 "sets a property as a function": function(body) { |
|
23 body.style("background-color", function() { return "orange"; }); |
|
24 assert.equal(document.body.style["background-color"], "orange"); |
|
25 }, |
|
26 "gets a property value": function(body) { |
|
27 document.body.style.setProperty("background-color", "yellow", ""); |
|
28 assert.equal(body.style("background-color"), "yellow"); |
|
29 }, |
|
30 "observes the specified priority": function(body) { |
|
31 body.style("background-color", "green", "important"); |
|
32 assert.equal(document.body.style.getPropertyPriority("background-color"), "important"); |
|
33 }, |
|
34 "removes a property as null": function(body) { |
|
35 body.style("background-color", "green").style("background-color", null); |
|
36 assert.equal(body.style("background-color"), ""); |
|
37 }, |
|
38 "removes a property as a function": function(body) { |
|
39 body.style("background-color", "green").style("background-color", function() { return null; }); |
|
40 assert.equal(body.style("background-color"), ""); |
|
41 }, |
|
42 "returns the current selection": function(body) { |
|
43 assert.isTrue(body.style("background-color", "green") === body); |
|
44 } |
|
45 } |
|
46 }); |
|
47 |
|
48 suite.addBatch({ |
|
49 "selectAll(div)": { |
|
50 topic: function() { |
|
51 return d3.select("body").html("").selectAll("div").data(d3.range(2)).enter().append("div"); |
|
52 }, |
|
53 "sets a property as a string": function(div) { |
|
54 div.style("background-color", "red"); |
|
55 assert.equal(div[0][0].style["background-color"], "red"); |
|
56 assert.equal(div[0][1].style["background-color"], "red"); |
|
57 }, |
|
58 "sets a property as a number": function(div) { |
|
59 div.style("opacity", .5); |
|
60 assert.equal(div[0][0].style["opacity"], "0.5"); |
|
61 assert.equal(div[0][1].style["opacity"], "0.5"); |
|
62 }, |
|
63 "sets a property as a function": function(div) { |
|
64 div.style("background-color", d3.interpolateRgb("orange", "yellow")); |
|
65 assert.equal(div[0][0].style["background-color"], "#ffa500"); |
|
66 assert.equal(div[0][1].style["background-color"], "#ffff00"); |
|
67 }, |
|
68 "gets a property value": function(div) { |
|
69 div[0][0].style.setProperty("background-color", "green", ""); |
|
70 assert.equal(div.style("background-color"), "green"); |
|
71 }, |
|
72 "observes the specified priority": function(div) { |
|
73 div.style("background-color", "blue", "important"); |
|
74 assert.equal(div[0][0].style.getPropertyPriority("background-color"), "important"); |
|
75 assert.equal(div[0][1].style.getPropertyPriority("background-color"), "important"); |
|
76 }, |
|
77 "removes a property as null": function(div) { |
|
78 div.style("background-color", "red").style("background-color", null); |
|
79 assert.equal(div[0][0].style["background-color"], ""); |
|
80 assert.equal(div[0][1].style["background-color"], ""); |
|
81 }, |
|
82 "removes a property as a function": function(div) { |
|
83 div.style("background-color", "red").style("background-color", function() { return null; }); |
|
84 assert.equal(div[0][0].style["background-color"], ""); |
|
85 assert.equal(div[0][1].style["background-color"], ""); |
|
86 }, |
|
87 "ignores null nodes": function(div) { |
|
88 var some = d3.selectAll("div"); |
|
89 some[0][1] = null; |
|
90 some.style("background-color", null).style("background-color", "red"); |
|
91 assert.equal(div[0][0].style["background-color"], "red"); |
|
92 assert.equal(div[0][1].style["background-color"], ""); |
|
93 }, |
|
94 "returns the current selection": function(div) { |
|
95 assert.isTrue(div.style("background-color", "green") === div); |
|
96 } |
|
97 } |
|
98 }); |
|
99 |
|
100 suite.export(module); |