]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Unit tests for Chart constructor and deprecations
authorSimon Brunel <simonbrunel@users.noreply.github.com>
Sat, 28 Jan 2017 12:17:38 +0000 (13:17 +0100)
committerEvert Timberg <evert.timberg+github@gmail.com>
Fri, 10 Feb 2017 23:37:56 +0000 (18:37 -0500)
src/core/core.controller.js
src/core/core.interaction.js
test/core.controller.tests.js
test/global.deprecations.tests.js [new file with mode: 0644]

index 57a6cfe4210ae963b614ec9e4c1c40c9345a314a..0d4c128bad75d16cd00e998f41f78a43599d2002 100644 (file)
@@ -373,6 +373,7 @@ module.exports = function(Chart) {
                         * @method IPlugin#afterScaleUpdate
                         * @deprecated since version 2.5.0
                         * @todo remove at version 3
+                        * @private
                         */
                        plugins.notify(me, 'afterScaleUpdate');
                        plugins.notify(me, 'afterLayout');
index 53a479f61fcbdbe6eecb1b9c259f4d106ebaf99c..c2c4ffcbf91390fc64e5127ed87fa28e0c3c5c55 100644 (file)
@@ -158,6 +158,8 @@ module.exports = function(Chart) {
                        /**
                         * @function Chart.Interaction.modes.label
                         * @deprecated since version 2.4.0
+                        * @todo remove at version 3
+                        * @private
                         */
                        label: indexMode,
 
@@ -196,6 +198,8 @@ module.exports = function(Chart) {
                        /**
                         * @function Chart.Interaction.modes.x-axis
                         * @deprecated since version 2.4.0. Use index mode and intersect == true
+                        * @todo remove at version 3
+                        * @private
                         */
                        'x-axis': function(chart, e) {
                                return indexMode(chart, e, true);
index 9c5e9e26dd21a5386ef3f21fea50039d4034c4e3..f29542cbf591d2f74188cd2117e4eab5ec2c973f 100644 (file)
@@ -1,4 +1,4 @@
-describe('Chart.Controller', function() {
+describe('Chart', function() {
 
        function waitForResize(chart, callback) {
                var resizer = chart.canvas.parentNode._chartjs.resizer;
@@ -13,6 +13,17 @@ describe('Chart.Controller', function() {
                Chart.helpers.addEvent(content, state !== 'complete'? 'load' : 'resize', handler);
        }
 
+       // https://github.com/chartjs/Chart.js/issues/2481
+       // See global.deprecations.tests.js for backward compatibility
+       it('should be defined and prototype of chart instances', function() {
+               var chart = acquireChart({});
+               expect(Chart).toBeDefined();
+               expect(Chart instanceof Object).toBeTruthy();
+               expect(chart.constructor).toBe(Chart);
+               expect(chart instanceof Chart).toBeTruthy();
+               expect(Chart.prototype.isPrototypeOf(chart)).toBeTruthy();
+       });
+
        describe('config initialization', function() {
                it('should create missing config.data properties', function() {
                        var chart = acquireChart({});
diff --git a/test/global.deprecations.tests.js b/test/global.deprecations.tests.js
new file mode 100644 (file)
index 0000000..a6b4f70
--- /dev/null
@@ -0,0 +1,94 @@
+describe('Deprecations', function() {
+       describe('Version 2.6.0', function() {
+               // https://github.com/chartjs/Chart.js/issues/2481
+               describe('Chart.Controller', function() {
+                       it('should be defined and an alias of Chart', function() {
+                               expect(Chart.Controller).toBeDefined();
+                               expect(Chart.Controller).toBe(Chart);
+                       });
+                       it('should be prototype of chart instances', function() {
+                               var chart = acquireChart({});
+                               expect(chart.constructor).toBe(Chart.Controller);
+                               expect(chart instanceof Chart.Controller).toBeTruthy();
+                               expect(Chart.Controller.prototype.isPrototypeOf(chart)).toBeTruthy();
+                       });
+               });
+
+               describe('chart.chart', function() {
+                       it('should be defined and an alias of chart', function() {
+                               var chart = acquireChart({});
+                               var proxy = chart.chart;
+                               expect(proxy).toBeDefined();
+                               expect(proxy).toBe(chart);
+                       });
+                       it('should defined previously existing properties', function() {
+                               var chart = acquireChart({}, {
+                                       canvas: {
+                                               style: 'width: 140px; height: 320px'
+                                       }
+                               });
+
+                               var proxy = chart.chart;
+                               expect(proxy.config instanceof Object).toBeTruthy();
+                               expect(proxy.controller instanceof Chart.Controller).toBeTruthy();
+                               expect(proxy.canvas instanceof HTMLCanvasElement).toBeTruthy();
+                               expect(proxy.ctx instanceof CanvasRenderingContext2D).toBeTruthy();
+                               expect(proxy.currentDevicePixelRatio).toBe(window.devicePixelRatio || 1);
+                               expect(proxy.aspectRatio).toBe(140/320);
+                               expect(proxy.height).toBe(320);
+                               expect(proxy.width).toBe(140);
+                       });
+               });
+       });
+
+       describe('Version 2.5.0', function() {
+               describe('Chart.PluginBase', function() {
+                       it('should exist and extendable', function() {
+                               expect(Chart.PluginBase).toBeDefined();
+                               expect(Chart.PluginBase.extend).toBeDefined();
+                       });
+               });
+
+               describe('IPlugin.afterScaleUpdate', function() {
+                       it('should be called after the chart as been layed out', function() {
+                               var sequence = [];
+                               var plugin = {};
+                               var hooks = [
+                                       'beforeLayout',
+                                       'afterScaleUpdate',
+                                       'afterLayout'
+                               ];
+
+                               var override = Chart.layoutService.update;
+                               Chart.layoutService.update = function() {
+                                       sequence.push('layoutUpdate');
+                                       override.apply(this, arguments);
+                               };
+
+                               hooks.forEach(function(name) {
+                                       plugin[name] = function() {
+                                               sequence.push(name);
+                                       };
+                               });
+
+                               window.acquireChart({plugins: [plugin]});
+                               expect(sequence).toEqual([].concat(
+                                       'beforeLayout',
+                                       'layoutUpdate',
+                                       'afterScaleUpdate',
+                                       'afterLayout'
+                               ));
+                       });
+               });
+       });
+
+       describe('Version 2.1.5', function() {
+               // https://github.com/chartjs/Chart.js/pull/2752
+               describe('Chart.pluginService', function() {
+                       it('should be defined and an alias of Chart.plugins', function() {
+                               expect(Chart.pluginService).toBeDefined();
+                               expect(Chart.pluginService).toBe(Chart.plugins);
+                       });
+               });
+       });
+});