Skip to content

Commit

Permalink
Add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nagix committed Apr 24, 2019
1 parent f63aaf1 commit da2ef6d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/core/core.datasetControllers.js
@@ -0,0 +1,41 @@
'use strict';

var defaults = require('./core.defaults');
var helpers = require('../helpers/index');

module.exports = {
constructors: {},

defaults: {},
registerControllerType: function(type, scaleConstructor, scaleDefaults) {
this.constructors[type] = scaleConstructor;
this.defaults[type] = helpers.clone(scaleDefaults);
},

getControllerConstructor: function(type) {
return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
},

getControllerDefaults: function(type) {
// Return the scale defaults merged with the global settings so that we always use the latest ones
return this.defaults.hasOwnProperty(type) ? helpers.merge({}, [defaults.scale, this.defaults[type]]) : {};
},

updateControllerDefaults: function(type, additions) {
var me = this;
if (me.defaults.hasOwnProperty(type)) {
me.defaults[type] = helpers.extend(me.defaults[type], additions);
}
},

addControllerToLayout: function(chart) {
// Adds each scale to the chart.boxes array to be sized accordingly
helpers.each(chart.scales, function(scale) {
// Set ILayoutItem parameters for backwards compatibility
scale.fullWidth = scale.options.fullWidth;
scale.position = scale.options.position;
scale.weight = scale.options.weight;
layouts.addBox(chart, scale);
});
}
};
22 changes: 21 additions & 1 deletion test/specs/scale.time.tests.js
Expand Up @@ -298,7 +298,7 @@ describe('Time scale tests', function() {
expect(ticks).toEqual(['8PM', '9PM', '10PM', '11PM', '12AM', '1AM', '2AM', '3AM', '4AM', '5AM', '6AM', '7AM', '8AM', '9AM', '10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM', '5PM', '6PM', '7PM', '8PM', '9PM']);
});

it('build ticks honoring the minUnit', function() {
it('should build ticks honoring the minUnit', function() {
var mockData = {
labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00'], // days
};
Expand All @@ -316,6 +316,26 @@ describe('Time scale tests', function() {
expect(ticks).toEqual(['Jan 1', 'Jan 2', 'Jan 3']);
});

it('should build ticks based on the appropriate label capacity', function() {
var mockData = {
labels: [
'2012-01-01', '2013-01-01', '2014-01-01', '2015-01-01',
'2016-01-01', '2017-01-01',' 2018-01-01', '2019-01-01'
]
};

var config = Chart.helpers.mergeIf({
time: {
unit: 'year'
}
}, Chart.scaleService.getScaleDefaults('time'));

var scale = createScale(mockData, config);
var ticks = getTicksLabels(scale);

expect(ticks).toEqual(['2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019']);
});

it('should build ticks using the config diff', function() {
var mockData = {
labels: ['2015-01-01T20:00:00', '2015-02-02T21:00:00', '2015-02-21T01:00:00'], // days
Expand Down

0 comments on commit da2ef6d

Please sign in to comment.