Skip to content

Commit

Permalink
Add unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcopperfield committed Dec 15, 2017
1 parent 7802e97 commit 3324b28
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions test/specs/scale.time.tests.js
Expand Up @@ -703,7 +703,7 @@ describe('Time scale tests', function() {
expect(getTicksLabels(scale)).toEqual([
'2017', '2019', '2020', '2025', '2042']);
});
it ('should correctly handle empty `data.labels`', function() {
it ('should correctly handle empty `data.labels` using "day" if `time.unit` is undefined`', function() {
var chart = this.chart;
var scale = chart.scales.x;

Expand All @@ -714,6 +714,19 @@ describe('Time scale tests', function() {
expect(scale.max).toEqual(+moment().endOf('day') + 1);
expect(getTicksLabels(scale)).toEqual([]);
});
it ('should correctly handle empty `data.labels` using `time.unit`', function() {
var chart = this.chart;
var scale = chart.scales.x;
var options = chart.options.scales.xAxes[0];

options.time.unit = 'year';
chart.data.labels = [];
chart.update();

expect(scale.min).toEqual(+moment().startOf('year'));
expect(scale.max).toEqual(+moment().endOf('year') + 1);
expect(getTicksLabels(scale)).toEqual([]);
});
});

describe('is "data"', function() {
Expand Down Expand Up @@ -784,7 +797,7 @@ describe('Time scale tests', function() {
expect(getTicksLabels(scale)).toEqual([
'2017', '2018', '2019', '2020', '2025', '2042', '2043']);
});
it ('should correctly handle empty `data.labels`', function() {
it ('should correctly handle empty `data.labels` using "day" if `time.unit` is undefined`', function() {
var chart = this.chart;
var scale = chart.scales.x;

Expand All @@ -796,6 +809,21 @@ describe('Time scale tests', function() {
expect(getTicksLabels(scale)).toEqual([
'2018', '2020', '2043']);
});
it ('should correctly handle empty `data.labels` and hidden datasets using `time.unit`', function() {
var chart = this.chart;
var scale = chart.scales.x;
var options = chart.options.scales.xAxes[0];

options.time.unit = 'year';
chart.data.labels = [];
var meta = chart.getDatasetMeta(1);
meta.hidden = true;
chart.update();

expect(scale.min).toEqual(+moment().startOf('year'));
expect(scale.max).toEqual(+moment().endOf('year') + 1);
expect(getTicksLabels(scale)).toEqual([]);
});
});
});

Expand Down

0 comments on commit 3324b28

Please sign in to comment.