Skip to content

Commit

Permalink
Merge pull request #102 from palantir/add-axis-tests
Browse files Browse the repository at this point in the history
Added a rudimentary axis test.
  • Loading branch information
teamdandelion committed Feb 17, 2014
2 parents 8d6547c + 555ac51 commit d65870b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Axis extends Component {
}

public render() {
if (this.orientation === "left") {this.axisElement.attr("transform", "translate(" + Axis.yWidth + ")");};
if (this.orientation === "left") {this.axisElement.attr("transform", "translate(" + Axis.yWidth + ", 0)");};
if (this.orientation === "top") {this.axisElement.attr("transform", "translate(0," + Axis.xHeight + ")");};
var domain = this.scale.domain();
var extent = Math.abs(domain[1] - domain[0]);
Expand Down
15 changes: 15 additions & 0 deletions test/axisTests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
///<reference path="testReference.ts" />

var assert = chai.assert;

describe("Axes", () => {
// TODO: Rewrite these tests when the Axis class gets refactored
it("Renders ticks", () => {
var svg = generateSVG(500, 100);
var xScale = new LinearScale();
xScale.domain([0, 10]);
xScale.range([0, 500]);
var axis = new XAxis(xScale, "bottom");
axis.anchor(svg).computeLayout().render();
var ticks = svg.selectAll(".tick");
assert.operator(ticks[0].length, ">=", 2, "There are at least two ticks.");
svg.remove();
});
});
6 changes: 4 additions & 2 deletions test/componentTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ describe("Component behavior", () => {
it("clipPath works as expected", () => {
assert.isFalse(c.clipPathEnabled, "clipPathEnabled defaults to false");
c.clipPathEnabled = true;
var expectedClipPathID: number = (<any> Component).clipPathId;
c.anchor(svg).computeLayout(0, 0, 100, 100).render();
assert.equal((<any> Component).clipPathId, 1, "clipPathId incremented");
assert.equal(c.element.attr("clip-path"), "url(#clipPath0)", "the element has clip-path url attached");
assert.equal((<any> Component).clipPathId, expectedClipPathID+1, "clipPathId incremented");
var expectedClipPathURL = "url(#clipPath" + expectedClipPathID+ ")";
assert.equal(c.element.attr("clip-path"), expectedClipPathURL, "the element has clip-path url attached");
var clipRect = c.element.select(".clip-rect");
assert.equal(clipRect.attr("width"), 100, "the clipRect has an appropriate width");
assert.equal(clipRect.attr("height"), 100, "the clipRect has an appropriate height");
Expand Down

0 comments on commit d65870b

Please sign in to comment.