From: Tanner Linsley Date: Sat, 17 Oct 2015 03:14:07 +0000 (-0600) Subject: Testing fixes for time scale X-Git-Tag: 2.0.0-beta~8^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1541%2Fhead;p=thirdparty%2FChart.js.git Testing fixes for time scale --- diff --git a/gulpfile.js b/gulpfile.js index 5f23288cb..39cbc817e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -36,8 +36,11 @@ var srcFiles = [ './src/charts/**', ]; -var testFiles = [ +var preTestFiles = [ './node_modules/moment/min/moment.min.js', +]; + +var testFiles = [ './test/mockContext.js', './test/*.js' ]; @@ -131,6 +134,7 @@ function validHTMLTask() { function unittestTask() { var files = srcFiles.slice(); + Array.prototype.unshift.apply(files, preTestFiles); Array.prototype.push.apply(files, testFiles); return gulp.src(files) @@ -142,6 +146,7 @@ function unittestTask() { function unittestWatchTask() { var files = srcFiles.slice(); + Array.prototype.unshift.apply(files, preTestFiles); Array.prototype.push.apply(files, testFiles); return gulp.src(files) @@ -153,6 +158,7 @@ function unittestWatchTask() { function coverageTask() { var files = srcFiles.slice(); + Array.prototype.unshift.apply(files, preTestFiles); Array.prototype.push.apply(files, testFiles); return gulp.src(files) diff --git a/package.json b/package.json index c8b45c6f5..cb2b1570f 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "type": "git", "url": "https://github.com/nnnick/Chart.js.git" }, - "dependences": {}, "devDependencies": { "color": "git://github.com/chartjs/color", "gulp": "3.5.x", diff --git a/src/scales/scale.radialLinear.js b/src/scales/scale.radialLinear.js index 67860d9c9..f55b321e3 100644 --- a/src/scales/scale.radialLinear.js +++ b/src/scales/scale.radialLinear.js @@ -59,7 +59,7 @@ this.height = this.maxHeight; this.xCenter = Math.round(this.width / 2); this.yCenter = Math.round(this.height / 2); - + var minSize = helpers.min([this.height, this.width]); this.drawingArea = (this.options.display) ? (minSize / 2) - (this.options.ticks.fontSize / 2 + this.options.ticks.backdropPaddingY) : (minSize / 2); }, diff --git a/test/core.helpers.tests.js b/test/core.helpers.tests.js index 4ceb1b2d0..ce0c98757 100644 --- a/test/core.helpers.tests.js +++ b/test/core.helpers.tests.js @@ -150,17 +150,18 @@ describe('Core helper tests', function() { 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: { @@ -288,17 +289,19 @@ describe('Core helper tests', function() { }); }); - 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); @@ -308,26 +311,26 @@ describe('Core helper tests', function() { 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); @@ -336,37 +339,55 @@ describe('Core helper tests', function() { 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, @@ -377,7 +398,16 @@ describe('Core helper tests', function() { } }); - 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, @@ -389,7 +419,7 @@ describe('Core helper tests', function() { }); }); - 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); @@ -404,7 +434,7 @@ describe('Core helper tests', function() { 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, @@ -418,7 +448,7 @@ describe('Core helper tests', function() { }]); }); - 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); @@ -457,4 +487,4 @@ describe('Core helper tests', function() { args: [] }]) }); -}); \ No newline at end of file +}); diff --git a/test/scale.linear.tests.js b/test/scale.linear.tests.js index d67564d1e..dd31c7bce 100644 --- a/test/scale.linear.tests.js +++ b/test/scale.linear.tests.js @@ -623,7 +623,7 @@ describe('Linear Scale', function() { }); }); - it('should draw correctly horizontally', function() { + it('Should draw correctly horizontally', function() { var scaleID = 'myScale'; var mockData = { @@ -795,7 +795,7 @@ describe('Linear Scale', function() { config.gridLines.drawOnChartArea = false; config.ticks.show = false; config.scaleLabel.show = true; - config.scaleLabel.labelString = 'myLabel' + config.scaleLabel.labelString = 'myLabel'; mockContext.resetCalls(); @@ -852,7 +852,7 @@ describe('Linear Scale', function() { expect(mockContext.getCalls()).toEqual([]); }); - it('should draw correctly vertically', function() { + it('Should draw correctly vertically', function() { var scaleID = 'myScale'; var mockData = { @@ -1399,4 +1399,4 @@ describe('Linear Scale', function() { "args": [] }]); }); -}); \ No newline at end of file +}); diff --git a/test/scale.time.tests.js b/test/scale.time.tests.js index a5c4ec0dd..eb573df4a 100644 --- a/test/scale.time.tests.js +++ b/test/scale.time.tests.js @@ -1,5 +1,10 @@ // 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); @@ -52,7 +57,7 @@ describe('Time scale tests', function() { }); }); - it ('should build ticks using days', function() { + it('should build ticks using days', function() { var scaleID = 'myScale'; var mockData = { @@ -75,7 +80,7 @@ describe('Time scale tests', function() { 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 = { @@ -98,7 +103,7 @@ describe('Time scale tests', function() { 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 = { @@ -122,7 +127,7 @@ describe('Time scale tests', function() { 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 = { @@ -171,4 +176,4 @@ describe('Time scale tests', function() { expect(verticalScale.getPixelForValue('', 0, 0)).toBe(6); expect(verticalScale.getPixelForValue('', 6, 0)).toBe(394); }); -}); \ No newline at end of file +});