var merged = helpers.configMerge(baseConfig, toMerge);
expect(merged).toEqual({
arrayProp: [{
- prop1: 'myProp1',
- prop2: 56,
- prop3: 'prop3'
- },
- 2, {
- prop1: 'myProp1'
- }],
+ prop1: 'myProp1',
+ prop2: 56,
+ prop3: 'prop3'
+ },
+ 2, {
+ prop1: 'myProp1'
+ }
+ ],
});
});
- it ('Should merge scale configs', function() {
+ it('Should merge scale configs', function() {
var baseConfig = {
scales: {
prop1: {
});
});
- it ('should get value or default', function() {
+ it('should get value or default', function() {
expect(helpers.getValueAtIndexOrDefault(98, 0, 56)).toBe(98);
- expect(helpers.getValueAtIndexOrDefault(0, 0, 56)).toBe(0);
+ expect(helpers.getValueAtIndexOrDefault(0, 0, 56)).toBe(0);
expect(helpers.getValueAtIndexOrDefault(undefined, undefined, 56)).toBe(56);
expect(helpers.getValueAtIndexOrDefault([1, 2, 3], 1, 100)).toBe(2);
expect(helpers.getValueAtIndexOrDefault([1, 2, 3], 3, 100)).toBe(100);
});
- it ('should filter an array', function() {
+ it('should filter an array', function() {
var data = [-10, 0, 6, 0, 7];
- var callback = function(item) { return item > 2};
+ var callback = function(item) {
+ return item > 2
+ };
expect(helpers.where(data, callback)).toEqual([6, 7]);
expect(helpers.findNextWhere(data, callback)).toEqual(6);
expect(helpers.findNextWhere(data, callback, 2)).toBe(7);
expect(helpers.findPreviousWhere(data, callback, 0)).toBe(undefined);
});
- it ('Should get the correct sign', function() {
+ it('Should get the correct sign', function() {
expect(helpers.sign(0)).toBe(0);
expect(helpers.sign(10)).toBe(1);
expect(helpers.sign(-5)).toBe(-1);
});
- it ('should do a log10 operation', function() {
+ it('should do a log10 operation', function() {
expect(helpers.log10(0)).toBe(-Infinity);
expect(helpers.log10(1)).toBe(0);
expect(helpers.log10(1000)).toBe(3);
});
- it ('Should generate ids', function() {
+ it('Should generate ids', function() {
expect(helpers.uid()).toBe('chart-0');
expect(helpers.uid()).toBe('chart-1');
expect(helpers.uid()).toBe('chart-2');
expect(helpers.uid()).toBe('chart-3');
});
- it ('should detect a number', function() {
+ it('should detect a number', function() {
expect(helpers.isNumber(123)).toBe(true);
expect(helpers.isNumber('123')).toBe(true);
expect(helpers.isNumber(null)).toBe(false);
expect(helpers.isNumber('cbc')).toBe(false);
});
- it ('should convert between radians and degrees', function() {
+ it('should convert between radians and degrees', function() {
expect(helpers.toRadians(180)).toBe(Math.PI);
expect(helpers.toRadians(90)).toBe(0.5 * Math.PI);
expect(helpers.toDegrees(Math.PI)).toBe(180);
- expect(helpers.toDegrees(Math.PI * 3 /2)).toBe(270);
+ expect(helpers.toDegrees(Math.PI * 3 / 2)).toBe(270);
});
- it ('should get an angle from a point', function() {
+ it('should get an angle from a point', function() {
var center = {
x: 0,
y: 0
};
- expect(helpers.getAngleFromPoint(center, {x: 0, y: 10})).toEqual({
+ expect(helpers.getAngleFromPoint(center, {
+ x: 0,
+ y: 10
+ })).toEqual({
angle: Math.PI / 2,
distance: 10,
});
- expect(helpers.getAngleFromPoint(center, {x: Math.sqrt(2), y: Math.sqrt(2)})).toEqual({
+ expect(helpers.getAngleFromPoint(center, {
+ x: Math.sqrt(2),
+ y: Math.sqrt(2)
+ })).toEqual({
angle: Math.PI / 4,
distance: 2
});
- expect(helpers.getAngleFromPoint(center, {x: -1.0 * Math.sqrt(2), y: -1.0 * Math.sqrt(2)})).toEqual({
+ expect(helpers.getAngleFromPoint(center, {
+ x: -1.0 * Math.sqrt(2),
+ y: -1.0 * Math.sqrt(2)
+ })).toEqual({
angle: Math.PI * 1.25,
distance: 2
});
});
- it ('should spline curves', function() {
- expect(helpers.splineCurve({x: 0, y: 0}, {x: 1, y: 1}, { x: 2, y: 0}, 0)).toEqual({
+ it('should spline curves', function() {
+ expect(helpers.splineCurve({
+ x: 0,
+ y: 0
+ }, {
+ x: 1,
+ y: 1
+ }, {
+ x: 2,
+ y: 0
+ }, 0)).toEqual({
previous: {
x: 1,
y: 1,
}
});
- expect(helpers.splineCurve({x: 0, y: 0}, {x: 1, y: 1}, { x: 2, y: 0}, 1)).toEqual({
+ expect(helpers.splineCurve({
+ x: 0,
+ y: 0
+ }, {
+ x: 1,
+ y: 1
+ }, {
+ x: 2,
+ y: 0
+ }, 1)).toEqual({
previous: {
x: 0,
y: 1,
});
});
- it ('should get the next or previous item in an array', function() {
+ it('should get the next or previous item in an array', function() {
var testData = [0, 1, 2];
expect(helpers.nextItem(testData, 0, false)).toEqual(1);
expect(helpers.previousItem(testData, 1, true)).toEqual(0);
});
- it ('should clear a canvas', function() {
+ it('should clear a canvas', function() {
var context = window.createMockContext();
helpers.clear({
width: 100,
}]);
});
- it ('should draw a rounded rectangle', function() {
+ it('should draw a rounded rectangle', function() {
var context = window.createMockContext();
helpers.drawRoundedRectangle(context, 10, 20, 30, 40, 5);
args: []
}])
});
-});
\ No newline at end of file
+});
// Time scale tests
describe('Time scale tests', function() {
+
+ it('Should load moment.js as a dependency', function() {
+ expect(window.moment).not.toBe(undefined);
+ });
+
it('Should register the constructor with the scale service', function() {
var Constructor = Chart.scaleService.getScaleConstructor('time');
expect(Constructor).not.toBe(undefined);
});
});
- it ('should build ticks using days', function() {
+ it('should build ticks using days', function() {
var scaleID = 'myScale';
var mockData = {
expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 2, 2015', 'Jan 3, 2015', 'Jan 4, 2015', 'Jan 5, 2015', 'Jan 6, 2015', 'Jan 7, 2015', 'Jan 8, 2015', 'Jan 9, 2015', 'Jan 10, 2015', 'Jan 11, 2015']);
});
- it ('should build ticks using the config unit', function() {
+ it('should build ticks using the config unit', function() {
var scaleID = 'myScale';
var mockData = {
expect(scale.ticks).toEqual(['Jan 1, 8PM', 'Jan 1, 9PM', 'Jan 1, 10PM', 'Jan 1, 11PM', 'Jan 2, 12AM', 'Jan 2, 1AM', 'Jan 2, 2AM', 'Jan 2, 3AM', 'Jan 2, 4AM', 'Jan 2, 5AM', 'Jan 2, 6AM', 'Jan 2, 7AM', 'Jan 2, 8AM', 'Jan 2, 9AM', 'Jan 2, 10AM', 'Jan 2, 11AM', 'Jan 2, 12PM', 'Jan 2, 1PM', 'Jan 2, 2PM', 'Jan 2, 3PM', 'Jan 2, 4PM', 'Jan 2, 5PM', 'Jan 2, 6PM', 'Jan 2, 7PM', 'Jan 2, 8PM', 'Jan 2, 9PM']);
});
- it ('should build ticks using the config diff', function() {
+ it('should build ticks using the config diff', function() {
var scaleID = 'myScale';
var mockData = {
expect(scale.ticks).toEqual(['Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015', 'Jan 18, 2015', 'Jan 25, 2015', 'Feb 1, 2015', 'Feb 8, 2015', 'Feb 15, 2015']);
});
- it ('should get the correct pixel for a value', function() {
+ it('should get the correct pixel for a value', function() {
var scaleID = 'myScale';
var mockData = {
expect(verticalScale.getPixelForValue('', 0, 0)).toBe(6);
expect(verticalScale.getPixelForValue('', 6, 0)).toBe(394);
});
-});
\ No newline at end of file
+});