Skip to content

Commit

Permalink
use UTC time throughout tests
Browse files Browse the repository at this point in the history
i think this explains most of the unreproduceable failures
we were seeing across the world.

fixes dc-js#559
fixes dc-js#550
closes dc-js#496
  • Loading branch information
gordonwoodhull committed Jul 18, 2014
1 parent 48d356c commit dd84a0c
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 176 deletions.
56 changes: 28 additions & 28 deletions spec/bar-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('dc.barChart', function() {

beforeEach(function () {
data = crossfilter(loadDateFixture());
dimension = data.dimension(function(d) { return d3.time.day(d.dd); });
dimension = data.dimension(function(d) { return d3.time.day.utc(d.dd); });
group = dimension.group();

id = 'bar-chart';
Expand All @@ -13,7 +13,7 @@ describe('dc.barChart', function() {
chart = dc.barChart('#' + id);
chart.dimension(dimension).group(group)
.width(1100).height(200)
.x(d3.time.scale().domain([new Date("2012/01/01"), new Date("2012/12/31")]))
.x(d3.time.scale.utc().domain([makeDate(2012, 0, 1), makeDate(2012, 11, 31)]))
.transitionDuration(0);
});

Expand Down Expand Up @@ -61,15 +61,15 @@ describe('dc.barChart', function() {
beforeEach(function() {
chart.rescale(); // BUG: barWidth cannot change after initial rendering

var domain = [new Date("5/20/2012"), new Date("8/15/2012")];
var domain = [makeDate(2012, 4, 20), makeDate(2012, 7, 15)];

chart.x(d3.time.scale().domain(domain))
chart.x(d3.time.scale.utc().domain(domain))
.group(dimension.group().reduceSum(function(d) {
return +d.nvalue;
}))
.elasticY(true)
.centerBar(false)
.xUnits(d3.time.days)
.xUnits(d3.time.days.utc)
.yAxis().ticks(5);

chart.render();
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('dc.barChart', function() {

chart
.brushOn(false)
.x(d3.time.scale().domain([new Date("2012/5/20"), new Date("2012/8/15")]))
.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)]))
.group(idGroup, "stack 0")
.title("stack 0", function (d) { return "stack 0: " + d.value; })
.stack(sumGroup, "stack 1")
Expand Down Expand Up @@ -377,12 +377,12 @@ describe('dc.barChart', function() {
var negativeGroup = dimension.group().reduceSum(function(d){ return d.nvalue; });

chart.group(negativeGroup).stack(negativeGroup).stack(negativeGroup);
chart.x(d3.time.scale().domain([new Date("2012/5/20"), new Date("2012/8/15")]));
chart.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)]));

chart.margins({top: 30, right: 50, bottom: 30, left: 30})
.yAxisPadding(5)
.elasticY(true)
.xUnits(d3.time.days)
.xUnits(d3.time.days.utc)
.yAxis().ticks(5);

chart.rescale(); // BUG: barWidth cannot change after initial rendering
Expand Down Expand Up @@ -444,8 +444,8 @@ describe('dc.barChart', function() {

describe('when focused', function() {
beforeEach(function() {
chart.elasticY(true).gap(1).xUnits(d3.time.days);
chart.focus([new Date("2012/6/11"), new Date("2012/7/9")]);
chart.elasticY(true).gap(1).xUnits(d3.time.days.utc);
chart.focus([makeDate(2012, 5, 11), makeDate(2012, 6, 9)]);
});

it('should render the one (focused) bar', function() {
Expand All @@ -461,15 +461,7 @@ describe('dc.barChart', function() {
});

it('should redraw the x-axis scale and ticks', function() {
chart.focus(null);
expect(nthXAxisText(0).text()).toBe("2012");
expect(nthXAxisText(1).text()).toBe("February");
expect(nthXAxisText(2).text()).toBe("March");
expect(nthXAxisText(3).text()).toBe("April");

function nthXAxisText(n) {
return d3.select(chart.selectAll("g.x text")[0][n]);
}
expect(xAxisText().slice(0,4)).toEqual(["Mon 11", "Wed 13", "Fri 15", "Jun 17"]);
});

it('should set its focus flag', function() {
Expand All @@ -488,7 +480,13 @@ describe('dc.barChart', function() {

function itBehavesLikeItWasReset() {
expect(chart.refocused()).toBeFalsy();
expect(chart.x().domain()).toEqual([new Date("2012/1/1"), new Date("2012/12/31")]);
expect(chart.x().domain()).toEqual([makeDate(2012, 0, 1), makeDate(2012, 11, 31)]);

expect(xAxisText().slice(0,4)).toEqual(["2012", "February", "March", "April"]);
}

function xAxisText() {
return chart.selectAll("g.x text")[0].map(function(x) { return d3.select(x).text(); });
}
});

Expand Down Expand Up @@ -539,12 +537,13 @@ describe('dc.barChart', function() {
beforeEach(function () {
d3.select("#" + id).append("span").attr("class", "filter").style("display", "none");
d3.select("#" + id).append("a").attr("class", "reset").style("display", "none");
chart.filter([new Date("2012/6/1"), new Date("2012/6/30")]).redraw();
chart.filter([makeDate(2012, 5, 1), makeDate(2012, 5, 30)]).redraw();
dc.dateFormat = d3.time.format.utc("%m/%d/%Y");
chart.redraw();
});

it('should set the chart filter', function () {
expect(chart.filter()).toEqual([new Date("2012/6/1"), new Date("2012/6/30")]);
expect(chart.filter()).toEqual([makeDate(2012, 5, 1), makeDate(2012, 5, 30)]);
});

it("should enable the reset link after rendering", function() {
Expand Down Expand Up @@ -625,7 +624,7 @@ describe('dc.barChart', function() {

describe("a chart with a large domain", function() {
beforeEach(function() {
chart.x(d3.time.scale().domain([new Date("2000/01/01"), new Date("2012/12/31")]));
chart.x(d3.time.scale.utc().domain([makeDate(2000, 0, 1), makeDate(2012, 11, 31)]));
});

describe("when filters are applied", function() {
Expand Down Expand Up @@ -685,7 +684,7 @@ describe('dc.barChart', function() {
beforeEach(function () {
chart
.brushOn(true)
.round(d3.time.month.round)
.round(d3.time.month.utc.round)
.centerBar(true);
});

Expand All @@ -696,7 +695,7 @@ describe('dc.barChart', function() {
chart.alwaysUseRounding(false);
consoleWarnSpy = spyOn(console, "warn");
chart.render();
chart.brush().extent([new Date(2012, 6, 1), new Date(2012, 7, 15)]);
chart.brush().extent([makeDate(2012, 6, 1), makeDate(2012, 7, 15)]);
chart.brush().event(chart.root());
});

Expand All @@ -706,20 +705,21 @@ describe('dc.barChart', function() {

it("should not round the brush", function () {
jasmine.clock().tick(100);
expect(chart.filter()).toEqual([new Date(2012, 6, 1), new Date(2012, 7, 15)]);
expect(chart.filter()).toEqual([makeDate(2012, 6, 1), makeDate(2012, 7, 15)]);
});
});

describe("with alwaysUseRounding enabled", function() {
beforeEach(function() {
chart.alwaysUseRounding(true);
chart.render();
chart.brush().extent([new Date(2012, 6, 1), new Date(2012, 7, 15)]);
chart.brush().extent([makeDate(2012, 6, 1), makeDate(2012, 7, 15)]);
chart.brush().event(chart.root());
});

it("should round the brush", function () {
expect(chart.brush().extent()).toEqual([new Date(2012, 6, 1), new Date(2012, 7, 1)]);
jasmine.clock().tick(100);
expect(chart.brush().extent()).toEqual([makeDate(2012, 6, 1), makeDate(2012, 7, 1)]);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion spec/base-mixin-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe("dc.baseMixin", function () {
beforeEach(function () {
var data = crossfilter(loadDateFixture());
dimension = data.dimension(function (d) {
return d3.time.day(d.dd);
return d3.time.day.utc(d.dd);
});
group = dimension.group().reduceSum(function (d) {
return d.value;
Expand Down
16 changes: 8 additions & 8 deletions spec/composite-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ describe('dc.compositeChart', function() {

beforeEach(function () {
data = crossfilter(loadDateFixture());
dateDimension = data.dimension(function(d) { return d3.time.day(d.dd); });
dateDimension = data.dimension(function(d) { return d3.time.day.utc(d.dd); });
dateValueSumGroup = dateDimension.group().reduceSum(function(d) { return d.value; });
dateIdSumGroup = dateDimension.group().reduceSum(function(d) { return d.id; });
dateGroup = dateDimension.group();
Expand All @@ -17,9 +17,9 @@ describe('dc.compositeChart', function() {
.group(dateIdSumGroup)
.width(500)
.height(150)
.x(d3.time.scale().domain([new Date(2012, 4, 20), new Date(2012, 7, 15)]))
.x(d3.time.scale.utc().domain([makeDate(2012, 4, 20), makeDate(2012, 7, 15)]))
.transitionDuration(0)
.xUnits(d3.time.days)
.xUnits(d3.time.days.utc)
.shareColors(true)
.compose([
dc.barChart(chart)
Expand Down Expand Up @@ -69,12 +69,12 @@ describe('dc.compositeChart', function() {
});

it('should set the x domain to endpoint dates', function () {
expect(chart.x().domain()[0].getTime()).toBe(new Date(2012, 4, 20).getTime());
expect(chart.x().domain()[1].getTime()).toBe(new Date(2012, 7, 15).getTime());
expect(chart.x().domain()[0].getTime()).toBe(makeDate(2012, 4, 20).getTime());
expect(chart.x().domain()[1].getTime()).toBe(makeDate(2012, 7, 15).getTime());
});

it('should set the x units', function(){
expect(chart.xUnits()).toBe(d3.time.days);
expect(chart.xUnits()).toBe(d3.time.days.utc);
});

it('should create the x axis', function(){
Expand All @@ -94,7 +94,7 @@ describe('dc.compositeChart', function() {
});

it('can change round', function () {
chart.round(d3.time.day.round);
chart.round(d3.time.day.utc.round);
expect(chart.round()).not.toBeNull();
});

Expand Down Expand Up @@ -257,7 +257,7 @@ describe('dc.compositeChart', function() {

describe('when filtering the chart', function () {
beforeEach(function () {
chart.filter([new Date(2012, 5, 1), new Date(2012, 5, 30)]).redraw();
chart.filter([makeDate(2012, 5, 1), makeDate(2012, 5, 30)]).redraw();
});

it('should set extent width to chart width based on filter set', function () {
Expand Down
Loading

0 comments on commit dd84a0c

Please sign in to comment.