-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature to toggle classes
- Loading branch information
Showing
8 changed files
with
1,825 additions
and
1,453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var tape = require("tape"); | ||
var jsdom = require("./jsdom"); | ||
var d3 = Object.assign({}, require("d3-selection"), require("../")); | ||
|
||
tape("render class names: data-class with literal value", function(test) { | ||
global.document = jsdom("<div class='fixed' data-class-checked='{{d}}'></div>"); | ||
var selection = d3.select("div").template(); | ||
selection.render(true); | ||
test.equal(selection.classed("checked"), true, "Class checked is rendered on element through true"); | ||
test.equal(selection.classed("fixed"), true, "Class fixed is still present"); | ||
selection.render(false); | ||
test.equal(selection.classed("checked"), false, "Class checked is no longer present through false"); | ||
test.equal(selection.classed("fixed"), true, "Class fixed is still present"); | ||
selection.render(1); | ||
test.equal(selection.classed("checked"), true, "Class checked is rendered on element through 1"); | ||
test.equal(selection.classed("fixed"), true, "Class fixed is still present"); | ||
selection.render(0); | ||
test.equal(selection.classed("checked"), false, "Class checked is no longer present through 0"); | ||
test.equal(selection.classed("fixed"), true, "Class fixed is still present"); | ||
selection.render("hello"); | ||
test.equal(selection.classed("checked"), true, "Class checked is rendered on element through \"hello\""); | ||
test.equal(selection.classed("fixed"), true, "Class fixed is still present"); | ||
selection.render(""); | ||
test.equal(selection.classed("checked"), false, "Class checked is no longer present through \"\""); | ||
test.equal(selection.classed("fixed"), true, "Class fixed is still present"); | ||
test.end(); | ||
}); | ||
|
||
tape("render class names: data-class with object value", function(test) { | ||
global.document = jsdom("<div><span data-class-red='{{d.red}}' data-class-green='{{d.green}}' data-class-blue='{{d.blue}}'></span></div>"); | ||
var selection = d3.select("div").template(); | ||
selection.render({ red: true, green: "", blue: [] }); | ||
test.equal(selection.select("span").classed("red"), true, "Class ref is rendered on element"); | ||
test.equal(selection.select("span").classed("green"), false, "Class green is not rendered on element"); | ||
test.equal(selection.select("span").classed("blue"), true, "Class blue is rendered on element"); | ||
test.end(); | ||
}); | ||
|
||
tape("render class names: data-class with object value and logic", function(test) { | ||
global.document = jsdom("<div><span class='fixed' data-class-red='{{d.red >= 50}}' data-class-green='{{d.green >= 50}}' data-class-blue='{{d.blue >= 50}}'></span></div>"); | ||
var selection = d3.select("div").template(); | ||
selection.render({ red: 0, green: 100, blue: 100 }); | ||
test.equal(selection.select("span").classed("red"), false, "Class ref is not rendered on element - 1"); | ||
test.equal(selection.select("span").classed("green"), true, "Class green is rendered on element - 1"); | ||
test.equal(selection.select("span").classed("blue"), true, "Class blue is rendered on element - 1"); | ||
test.equal(selection.select("span").classed("fixed"), true, "Class fixed is still present"); | ||
selection.render({ red: 50, green: 50, blue: 50 }); | ||
test.equal(selection.select("span").classed("red"), true, "Class ref is rendered on element - 2"); | ||
test.equal(selection.select("span").classed("green"), true, "Class green is rendered on element - 2"); | ||
test.equal(selection.select("span").classed("blue"), true, "Class blue is rendered on element - 2"); | ||
test.equal(selection.select("span").classed("fixed"), true, "Class fixed is still present"); | ||
selection.render({ red: 0, green: 0, blue: 0 }); | ||
test.equal(selection.select("span").classed("red"), false, "Class ref is not rendered on element - 2"); | ||
test.equal(selection.select("span").classed("green"), false, "Class green is not rendered on element - 2"); | ||
test.equal(selection.select("span").classed("blue"), false, "Class blue is not rendered on element - 2"); | ||
test.equal(selection.select("span").classed("fixed"), true, "Class fixed is still present"); | ||
test.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters