Skip to content

Commit 9e66f33

Browse files
two simple tests for barChart xUnitPaddingUnit
thanks @stillesjo! with a month test that's plenty for this code path for #1234 note these must get broken when #792 is fixed
1 parent 5ed2a5c commit 9e66f33

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

spec/bar-chart-spec.js

+29-21
Original file line numberDiff line numberDiff line change
@@ -949,42 +949,51 @@ describe('dc.barChart', function () {
949949
});
950950
});
951951
});
952-
describe('with elasticX and x-axis padding', function() {
952+
describe('with elasticX and x-axis padding', function () {
953953
var date = makeDate(2012, 5, 1);
954954
beforeEach(function () {
955-
956955
var rows = [
957-
{x: date, y: 4},
956+
{x: date, y: 4},
958957
];
959958
data = crossfilter(rows);
960959
dimension = data.dimension(function (d) {
961-
return d.x;
960+
return d.x;
962961
});
963962
group = dimension.group().reduceSum(function (d) {
964-
return d.y;
963+
return d.y;
965964
});
966965
chart = dc.barChart('#' + id);
967966
chart.width(500)
968-
.transitionDuration(0)
969-
.x(d3.time.scale())
970-
.elasticY(true).elasticX(true)
971-
.dimension(dimension)
972-
.group(group)
967+
.transitionDuration(0)
968+
.x(d3.time.scale())
969+
.elasticY(true).elasticX(true)
970+
.dimension(dimension)
971+
.group(group);
973972
chart.render();
974973
});
975-
it ('should render the right xAxisMax/Min when no padding', function () {
974+
// note: these tests assume that the bar width is not included in the
975+
// chart width, so they should be broken when #792 is fixed
976+
it('should render the right xAxisMax/Min when no padding', function () {
976977
expect(chart.xAxisMin()).toEqual(date);
977978
expect(chart.xAxisMax()).toEqual(date);
978-
})
979-
it ('should render the right xAxisMax/Min when 10 day padding', function () {
980-
chart.xAxisPadding(10)
981-
let expectedStartDate = d3.time.day.offset(date, -10);
982-
let expectedEndDate = d3.time.day.offset(date, 10);
983-
expect(chart.xAxisMin()).toEqual(expectedStartDate);
984-
expect(chart.xAxisMax()).toEqual(expectedEndDate);
985979
});
986-
987-
it ('should render the right ')
980+
it('should render the right xAxisMax/Min when 10 day padding', function () {
981+
chart.xAxisPadding(10)
982+
.render();
983+
var expectedStartDate = d3.time.day.offset(date, -10);
984+
var expectedEndDate = d3.time.day.offset(date, 10);
985+
expect(chart.xAxisMin()).toEqual(expectedStartDate);
986+
expect(chart.xAxisMax()).toEqual(expectedEndDate);
987+
});
988+
it('should render the right xAxisMax/Min when 2 month padding', function () {
989+
chart.xAxisPaddingUnit('month')
990+
.xAxisPadding(2)
991+
.render();
992+
var expectedStartDate = d3.time.month.offset(date, -2);
993+
var expectedEndDate = d3.time.month.offset(date, 2);
994+
expect(chart.xAxisMin()).toEqual(expectedStartDate);
995+
expect(chart.xAxisMax()).toEqual(expectedEndDate);
996+
});
988997
});
989998
describe('with changing number of bars and elasticX', function () {
990999
beforeEach(function () {
@@ -1034,7 +1043,6 @@ describe('dc.barChart', function () {
10341043
});
10351044
});
10361045

1037-
10381046
describe('with changing number of ordinal bars and elasticX', function () {
10391047
beforeEach(function () {
10401048
var rows1 = [

0 commit comments

Comments
 (0)