Skip to content

Commit

Permalink
Test env update
Browse files Browse the repository at this point in the history
- Fixed test cases which was unclear selecting from global context
- Fixed helper function on generating chart
- Add comment & update missing dependency module
  • Loading branch information
netil committed Jul 3, 2017
1 parent 97d0b69 commit d9d0920
Show file tree
Hide file tree
Showing 29 changed files with 939 additions and 1,004 deletions.
27 changes: 24 additions & 3 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@ module.exports = function(config) {

files: [
"./node_modules/lite-fixture/index.js",
"./node_modules/d3/build/d3.min.js",
"./dist/billboard.css",
"./spec/*-spec.js"
//"./spec/*-spec.js"
// to maintain order
"./spec/api.axis-spec.js",
"./spec/api.data-spec.js",
"./spec/api.focus-spec.js",
"./spec/api.grid-spec.js",
"./spec/api.load-spec.js",
"./spec/api.region-spec.js",
"./spec/api.zoom-spec.js",
"./spec/arc-spec.js",
"./spec/bb-spec.js",
"./spec/class-spec.js",
"./spec/core-spec.js",
"./spec/data-spec.js",
"./spec/domain-spec.js",
"./spec/grid-spec.js",
"./spec/interaction-spec.js",
"./spec/legend-spec.js",
"./spec/shape.bar-spec.js",
"./spec/shape.line-spec.js",
"./spec/title-spec.js",
"./spec/tooltip-spec.js",
"./spec/type-spec.js",
"./spec/zoom-spec.js"
],

exclude: [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"babel-preset-es2015": "^6.24.1",
"chai": "^4.0.2",
"clean-webpack-plugin": "^0.1.16",
"coveralls": "^2.13.1",
"css-loader": "^0.28.4",
"docdash": "^0.4.0",
"eslint": "^3.19.0",
Expand Down
79 changes: 38 additions & 41 deletions spec/api.axis-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,55 @@
import util from "./assets/util";

describe("API axis", function() {
let chart;
let args;

beforeEach(done => {
chart = util.initChart(chart, args, done);
const chart = util.generate({
data: {
columns: [
["data1", 30, 200, 100],
["data2", 50, 20, 10]
],
axes: {
data1: "y",
data2: "y2"
}
},
axis: {
y: {
label: "Y Axis Label"
},
y2: {
show: true,
label: "Y2 Axis Label"
}
}
});

describe("axis.labels", () => {
it("should update args", () => {
args = {
data: {
columns: [
["data1", 30, 200, 100],
["data2", 50, 20, 10]
],
axes: {
data1: "y",
data2: "y2"
}
},
axis: {
y: {
label: "Y Axis Label"
},
y2: {
show: true,
label: "Y2 Axis Label"
}
}
};

expect(true).to.be.ok;
});

it("should update y axis label", () => {
it("should update y axis label", done => {
chart.axis.labels({y: "New Y Axis Label"});

const label = d3.select(".bb-axis-y-label");
setTimeout(() => {
const label = chart.internal.main.select(".bb-axis-y-label");

expect(label.text()).to.be.equal("New Y Axis Label");
expect(label.attr("dx")).to.be.equal("-0.5em");
expect(label.attr("dy")).to.be.equal("1.2em");
expect(label.text()).to.be.equal("New Y Axis Label");
expect(label.attr("dx")).to.be.equal("-0.5em");
expect(label.attr("dy")).to.be.equal("1.2em");

done();
}, 500);
});

it("should update y axis label", () => {
it("should update y axis label", done => {
chart.axis.labels({y2: "New Y2 Axis Label"});

const label = d3.select(".bb-axis-y2-label");
setTimeout(() => {
const label = chart.internal.main.select(".bb-axis-y2-label");

expect(label.text()).to.be.equal("New Y2 Axis Label");
expect(label.attr("dx")).to.be.equal("-0.5em");
expect(label.attr("dy")).to.be.equal("-0.5em");

expect(label.text()).to.be.equal("New Y2 Axis Label");
expect(label.attr("dx")).to.be.equal("-0.5em");
expect(label.attr("dy")).to.be.equal("-0.5em");
done();
}, 500);
});
});
});
75 changes: 42 additions & 33 deletions spec/api.data-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import util from "./assets/util";

describe("API data", function() {
let chart;
let args = {
const chart = util.generate({
data: {
columns: [
["data1", 30, 200, 100, 400, 150, 250],
Expand All @@ -31,7 +30,7 @@ describe("API data", function() {
show: true
}
}
};
});

function toHex(value) {
function rgb2hex(rgb) {
Expand All @@ -46,12 +45,7 @@ describe("API data", function() {
return value.match("rgb") ? rgb2hex(value) : value;
}

beforeEach(done => {
chart = util.initChart(chart, args, done);
});

describe("data()", () => {

it("should return all of data if no argument given", () => {
const results = chart.data();
const expected = ["data1", "data2"];
Expand Down Expand Up @@ -87,6 +81,9 @@ describe("API data", function() {

expect(results.length).to.be.equal(1);
expect(results[0].id).to.be.equal("data2");

// revert
chart.show("data1");
});

});
Expand Down Expand Up @@ -119,7 +116,7 @@ describe("API data", function() {
expect(results.data2).to.be.equal("Data Name 2");
});

it("should return data.names specified as api", () => {
it("should return data.names specified as API", () => {
const results = chart.data.names({
data1: "New Data Name 1",
data2: "New Data Name 2"
Expand All @@ -129,14 +126,15 @@ describe("API data", function() {
expect(results.data2).to.be.equal("New Data Name 2");
});

it("should set data.names specified as api", () => {
expect(d3.select(".bb-legend-item-data1 text").text())
it("should set data.names specified as API", () => {
const svg = chart.internal.svg;

expect(svg.select(".bb-legend-item-data1 text").text())
.to.be.equal("New Data Name 1");

expect(d3.select(".bb-legend-item-data2 text").text())
expect(svg.select(".bb-legend-item-data2 text").text())
.to.be.equal("New Data Name 2");
});

});

describe("data.colors()", () => {
Expand All @@ -147,7 +145,7 @@ describe("API data", function() {
expect(toHex(results.data2)).to.be.equal("#00FF00");
});

it("should return data.colors specified as api", () => {
it("should return data.colors specified as API", () => {
const results = chart.data.colors({
data1: "#00FF00",
data2: "#FF0000"
Expand All @@ -157,51 +155,62 @@ describe("API data", function() {
expect(toHex(results.data2)).to.be.equal("#FF0000");
});

it("should set data.colors specified as api", () => {
expect(toHex(d3.select(".bb-line-data1").style("stroke")))
.to.be.equal("#00ff00");
it("should set data.colors specified as API", done => {
setTimeout(() => {
const svg = chart.internal.svg;

expect(toHex(d3.select(".bb-line-data2").style("stroke")))
.to.be.equal("#ff0000");
expect(toHex(svg.select(".bb-line-data1").style("stroke")))
.to.be.equal("#00ff00");

expect(toHex(d3.select(".bb-legend-item-data1 .bb-legend-item-tile").style("stroke")))
.to.be.equal("#00ff00");
expect(toHex(svg.select(".bb-line-data2").style("stroke")))
.to.be.equal("#ff0000");

expect(toHex(d3.select(".bb-legend-item-data2 .bb-legend-item-tile").style("stroke")))
.to.be.equal("#ff0000");
expect(toHex(svg.select(".bb-legend-item-data1 .bb-legend-item-tile").style("stroke")))
.to.be.equal("#00ff00");

expect(toHex(svg.select(".bb-legend-item-data2 .bb-legend-item-tile").style("stroke")))
.to.be.equal("#ff0000");

done();
}, 500);
});

});

describe("data.axes()", () => {

it("should return data.axes specified as argument", () => {
const main = chart.internal.main;
const results = chart.data.axes();

expect(results.data1).to.be.equal("y");
expect(results.data2).to.be.equal("y2");

expect(d3.select(".bb-axis-y g.tick text").text())
expect(main.select(".bb-axis-y g.tick text").text())
.to.be.equal("0");

expect(d3.select(".bb-axis-y2 g.tick text").text())
expect(main.select(".bb-axis-y2 g.tick text").text())
.to.be.equal("1000");
});

it("should return data.axes specified as api", () => {
it("should return data.axes specified as API", done => {
const main = chart.internal.main;
const results = chart.data.axes({
data1: "y2",
data2: "y"
});

expect(results.data1).to.be.equal("y2");
expect(results.data2).to.be.equal("y");
setTimeout(() => {
expect(results.data1).to.be.equal("y2");
expect(results.data2).to.be.equal("y");

expect(d3.select(".bb-axis-y g.tick text").text())
.to.be.equal("1000");
expect(main.select(".bb-axis-y g.tick text").text())
.to.be.equal("1000");

expect(d3.select(".bb-axis-y2 g.tick text").text())
.to.be.equal("0");
expect(main.select(".bb-axis-y2 g.tick text").text())
.to.be.equal("0");

done();
}, 500);
});
});
});

0 comments on commit d9d0920

Please sign in to comment.