diff --git a/gulpfile.js b/gulpfile.js index 57cbd1cc607..58b8bf8fa29 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -22,6 +22,7 @@ var package = require('./package.json'); var srcDir = './src/'; var outDir = './dist/'; +var testDir = './test/'; var header = "/*!\n" + " * Chart.js\n" + @@ -132,6 +133,7 @@ function packageTask() { function lintTask() { var files = [ srcDir + '**/*.js', + testDir + '**/*.js' ]; // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict @@ -141,7 +143,21 @@ function lintTask() { rules: { 'complexity': [1, 6], 'max-statements': [1, 30] - } + }, + globals: [ + 'Chart', + 'acquireChart', + 'afterAll', + 'afterEach', + 'beforeAll', + 'beforeEach', + 'describe', + 'expect', + 'it', + 'jasmine', + 'moment', + 'spyOn' + ] }; return gulp.src(files) diff --git a/test/controller.bar.tests.js b/test/controller.bar.tests.js index 3ef9cabdf52..a77eea22ead 100644 --- a/test/controller.bar.tests.js +++ b/test/controller.bar.tests.js @@ -5,8 +5,8 @@ describe('Bar controller tests', function() { type: 'bar', data: { datasets: [ - { data: [] }, - { data: [] } + {data: []}, + {data: []} ], labels: [] } @@ -30,8 +30,8 @@ describe('Bar controller tests', function() { type: 'bar', data: { datasets: [ - { data: [] }, - { data: [] } + {data: []}, + {data: []} ], labels: [] }, @@ -57,10 +57,10 @@ describe('Bar controller tests', function() { type: 'bar', data: { datasets: [ - { data: [], type: 'line' }, - { data: [], hidden: true }, - { data: [] }, - { data: [] } + {data: [], type: 'line'}, + {data: [], hidden: true}, + {data: []}, + {data: []} ], labels: [] } @@ -75,10 +75,10 @@ describe('Bar controller tests', function() { type: 'bar', data: { datasets: [ - { data: [] }, - { data: [], hidden: true }, - { data: [], type: 'line' }, - { data: [] } + {data: []}, + {data: [], hidden: true}, + {data: [], type: 'line'}, + {data: []} ], labels: [] } @@ -94,8 +94,8 @@ describe('Bar controller tests', function() { type: 'bar', data: { datasets: [ - { data: [] }, - { data: [10, 15, 0, -4] } + {data: []}, + {data: [10, 15, 0, -4]} ], labels: [] } @@ -154,8 +154,9 @@ describe('Bar controller tests', function() { expect(meta.data.length).toBe(2); - [ { x: 122, y: 484 }, - { x: 234, y: 32 } + [ + {x: 122, y: 484}, + {x: 234, y: 32} ].forEach(function(expected, i) { expect(meta.data[i]._datasetIndex).toBe(1); expect(meta.data[i]._index).toBe(i); @@ -251,10 +252,11 @@ describe('Bar controller tests', function() { var meta0 = chart.getDatasetMeta(0); - [ { b: 290, w: 91, x: 95, y: 161 }, - { b: 290, w: 91, x: 209, y: 419 }, - { b: 290, w: 91, x: 322, y: 161 }, - { b: 290, w: 91, x: 436, y: 419 } + [ + {b: 290, w: 91, x: 95, y: 161}, + {b: 290, w: 91, x: 209, y: 419}, + {b: 290, w: 91, x: 322, y: 161}, + {b: 290, w: 91, x: 436, y: 419} ].forEach(function(values, i) { expect(meta0.data[i]._model.base).toBeCloseToPixel(values.b); expect(meta0.data[i]._model.width).toBeCloseToPixel(values.w); @@ -264,10 +266,11 @@ describe('Bar controller tests', function() { var meta1 = chart.getDatasetMeta(1); - [ { b: 161, w: 91, x: 95, y: 32 }, - { b: 290, w: 91, x: 209, y: 97 }, - { b: 161, w: 91, x: 322, y: 161 }, - { b: 419, w: 91, x: 436, y: 471 } + [ + {b: 161, w: 91, x: 95, y: 32}, + {b: 290, w: 91, x: 209, y: 97}, + {b: 161, w: 91, x: 322, y: 161}, + {b: 419, w: 91, x: 436, y: 471} ].forEach(function(values, i) { expect(meta1.data[i]._model.base).toBeCloseToPixel(values.b); expect(meta1.data[i]._model.width).toBeCloseToPixel(values.w); @@ -305,10 +308,11 @@ describe('Bar controller tests', function() { var meta0 = chart.getDatasetMeta(0); - [ { b: 290, w: 91, x: 95, y: 161 }, - { b: 290, w: 91, x: 209, y: 419 }, - { b: 290, w: 91, x: 322, y: 161 }, - { b: 290, w: 91, x: 436, y: 419 } + [ + {b: 290, w: 91, x: 95, y: 161}, + {b: 290, w: 91, x: 209, y: 419}, + {b: 290, w: 91, x: 322, y: 161}, + {b: 290, w: 91, x: 436, y: 419} ].forEach(function(values, i) { expect(meta0.data[i]._model.base).toBeCloseToPixel(values.b); expect(meta0.data[i]._model.width).toBeCloseToPixel(values.w); @@ -318,10 +322,11 @@ describe('Bar controller tests', function() { var meta1 = chart.getDatasetMeta(1); - [ { b: 161, w: 91, x: 95, y: 32 }, - { b: 290, w: 91, x: 209, y: 97 }, - { b: 161, w: 91, x: 322, y: 161 }, - { b: 419, w: 91, x: 436, y: 471 } + [ + {b: 161, w: 91, x: 95, y: 32}, + {b: 290, w: 91, x: 209, y: 97}, + {b: 161, w: 91, x: 322, y: 161}, + {b: 419, w: 91, x: 436, y: 471} ].forEach(function(values, i) { expect(meta1.data[i]._model.base).toBeCloseToPixel(values.b); expect(meta1.data[i]._model.width).toBeCloseToPixel(values.w); diff --git a/test/controller.bubble.tests.js b/test/controller.bubble.tests.js index ec61a0b50bc..977b2d517b1 100644 --- a/test/controller.bubble.tests.js +++ b/test/controller.bubble.tests.js @@ -133,10 +133,11 @@ describe('Bubble controller tests', function() { var meta = chart.getDatasetMeta(0); - [ { r: 5, x: 38, y: 32 }, - { r: 1, x: 189, y: 484 }, - { r: 2, x: 341, y: 461 }, - { r: 1, x: 492, y: 32 } + [ + {r: 5, x: 38, y: 32}, + {r: 1, x: 189, y: 484}, + {r: 2, x: 341, y: 461}, + {r: 1, x: 492, y: 32} ].forEach(function(expected, i) { expect(meta.data[i]._model.radius).toBe(expected.r); expect(meta.data[i]._model.x).toBeCloseToPixel(expected.x); diff --git a/test/controller.doughnut.tests.js b/test/controller.doughnut.tests.js index 0d31653a733..d9319bb807a 100644 --- a/test/controller.doughnut.tests.js +++ b/test/controller.doughnut.tests.js @@ -78,10 +78,11 @@ describe('Doughnut controller tests', function() { expect(meta.data.length).toBe(4); - [ { c: 0 }, - { c: 0 }, - { c: 0, }, - { c: 0 } + [ + {c: 0}, + {c: 0}, + {c: 0}, + {c: 0} ].forEach(function(expected, i) { expect(meta.data[i]._model.x).toBeCloseToPixel(256); expect(meta.data[i]._model.y).toBeCloseToPixel(272); @@ -96,14 +97,15 @@ describe('Doughnut controller tests', function() { borderColor: 'rgb(0, 0, 255)', borderWidth: 2 })); - }) + }); chart.update(); - [ { c: 1.7453292519, s: -1.5707963267, e: 0.1745329251 }, - { c: 2.0943951023, s: 0.1745329251, e: 2.2689280275 }, - { c: 0, s: 2.2689280275, e: 2.2689280275 }, - { c: 2.4434609527, s: 2.2689280275, e: 4.7123889803 } + [ + {c: 1.7453292519, s: -1.5707963267, e: 0.1745329251}, + {c: 2.0943951023, s: 0.1745329251, e: 2.2689280275}, + {c: 0, s: 2.2689280275, e: 2.2689280275}, + {c: 2.4434609527, s: 2.2689280275, e: 4.7123889803} ].forEach(function(expected, i) { expect(meta.data[i]._model.x).toBeCloseToPixel(256); expect(meta.data[i]._model.y).toBeCloseToPixel(272); @@ -118,7 +120,7 @@ describe('Doughnut controller tests', function() { borderColor: 'rgb(0, 0, 255)', borderWidth: 2 })); - }) + }); // Change the amount of data and ensure that arcs are updated accordingly chart.data.datasets[1].data = [1, 2]; // remove 2 elements from dataset 0 @@ -172,17 +174,18 @@ describe('Doughnut controller tests', function() { expect(meta.data.length).toBe(2); // Only startAngle, endAngle and circumference should be different. - [ { c: Math.PI / 8, s: Math.PI, e: Math.PI + Math.PI / 8 }, - { c: 3 * Math.PI / 8, s: Math.PI + Math.PI / 8, e: Math.PI + Math.PI / 2 } + [ + {c: Math.PI / 8, s: Math.PI, e: Math.PI + Math.PI / 8}, + {c: 3 * Math.PI / 8, s: Math.PI + Math.PI / 8, e: Math.PI + Math.PI / 2} ].forEach(function(expected, i) { expect(meta.data[i]._model.x).toBeCloseToPixel(495); expect(meta.data[i]._model.y).toBeCloseToPixel(511); expect(meta.data[i]._model.outerRadius).toBeCloseToPixel(478); expect(meta.data[i]._model.innerRadius).toBeCloseToPixel(359); - expect(meta.data[i]._model.circumference).toBeCloseTo(expected.c,8); + expect(meta.data[i]._model.circumference).toBeCloseTo(expected.c, 8); expect(meta.data[i]._model.startAngle).toBeCloseTo(expected.s, 8); expect(meta.data[i]._model.endAngle).toBeCloseTo(expected.e, 8); - }) + }); }); it ('should draw all arcs', function() { diff --git a/test/controller.line.tests.js b/test/controller.line.tests.js index 9afc9cec055..3c66b268ec0 100644 --- a/test/controller.line.tests.js +++ b/test/controller.line.tests.js @@ -165,12 +165,12 @@ describe('Line controller tests', function() { var chart = window.acquireChart({ type: 'line', data: { - datasets: [{ - data: [10, 15, 0, -4], - label: 'dataset', - xAxisID: 'firstXScaleID', - yAxisID: 'firstYScaleID' - }], + datasets: [{ + data: [10, 15, 0, -4], + label: 'dataset', + xAxisID: 'firstXScaleID', + yAxisID: 'firstYScaleID' + }], labels: ['label1', 'label2', 'label3', 'label4'] }, options: { @@ -202,8 +202,9 @@ describe('Line controller tests', function() { expect(meta.data.length).toBe(2); - [ { x: 44, y: 484 }, - { x: 193, y: 32 } + [ + {x: 44, y: 484}, + {x: 193, y: 32} ].forEach(function(expected, i) { expect(meta.data[i]._datasetIndex).toBe(0); expect(meta.data[i]._index).toBe(i); @@ -223,23 +224,23 @@ describe('Line controller tests', function() { expect(meta.data.length).toBe(3); // should add a new meta data item }); - it('should correctly calculate x scale for label and point', function(){ - var chart = window.acquireChart({ + it('should correctly calculate x scale for label and point', function() { + var chart = window.acquireChart({ type: 'line', - data: { - labels: ["One"], - datasets: [{ - data: [1], - }] + data: { + labels: ['One'], + datasets: [{ + data: [1], + }] + }, + options: { + hover: { + mode: 'single' }, - options: { - hover: { - mode: 'single' - }, scales: { yAxes: [{ ticks: { - beginAtZero:true + beginAtZero: true } }] } @@ -252,7 +253,7 @@ describe('Line controller tests', function() { expect(point._model.x).toBeCloseToPixel(267); // 2 points - chart.data.labels = ["One", "Two"]; + chart.data.labels = ['One', 'Two']; chart.data.datasets[0].data = [1, 2]; chart.update(); @@ -262,7 +263,7 @@ describe('Line controller tests', function() { expect(points[1]._model.x).toBeCloseToPixel(498); // 3 points - chart.data.labels = ["One", "Two", "Three"]; + chart.data.labels = ['One', 'Two', 'Three']; chart.data.datasets[0].data = [1, 2, 3]; chart.update(); @@ -273,7 +274,7 @@ describe('Line controller tests', function() { expect(points[2]._model.x).toBeCloseToPixel(493); // 4 points - chart.data.labels = ["One", "Two", "Three", "Four"]; + chart.data.labels = ['One', 'Two', 'Three', 'Four']; chart.data.datasets[0].data = [1, 2, 3, 4]; chart.update(); @@ -309,24 +310,26 @@ describe('Line controller tests', function() { var meta0 = chart.getDatasetMeta(0); - [ { x: 38, y: 161 }, - { x: 189, y: 419 }, - { x: 341, y: 161 }, - { x: 492, y: 419 } + [ + {x: 38, y: 161}, + {x: 189, y: 419}, + {x: 341, y: 161}, + {x: 492, y: 419} ].forEach(function(values, i) { - expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x); - expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y); + expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x); + expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y); }); var meta1 = chart.getDatasetMeta(1); - [ { x: 38, y: 32 }, - { x: 189, y: 97 }, - { x: 341, y: 161 }, - { x: 492, y: 471 } + [ + {x: 38, y: 32}, + {x: 189, y: 97}, + {x: 341, y: 161}, + {x: 492, y: 471} ].forEach(function(values, i) { - expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x); - expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y); + expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x); + expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y); }); }); @@ -362,24 +365,26 @@ describe('Line controller tests', function() { var meta0 = chart.getDatasetMeta(0); - [ { x: 76, y: 161 }, - { x: 215, y: 419 }, - { x: 353, y: 161 }, - { x: 492, y: 419 } + [ + {x: 76, y: 161}, + {x: 215, y: 419}, + {x: 353, y: 161}, + {x: 492, y: 419} ].forEach(function(values, i) { - expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x); - expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y); + expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x); + expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y); }); var meta1 = chart.getDatasetMeta(1); - [ { x: 76, y: 32 }, - { x: 215, y: 97 }, - { x: 353, y: 161 }, - { x: 492, y: 471 } + [ + {x: 76, y: 32}, + {x: 215, y: 97}, + {x: 353, y: 161}, + {x: 492, y: 471} ].forEach(function(values, i) { - expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x); - expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y); + expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x); + expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y); }); }); @@ -432,24 +437,26 @@ describe('Line controller tests', function() { var meta0 = chart.getDatasetMeta(0); - [ { x: 38, y: 161 }, - { x: 189, y: 419 }, - { x: 341, y: 161 }, - { x: 492, y: 419 } + [ + {x: 38, y: 161}, + {x: 189, y: 419}, + {x: 341, y: 161}, + {x: 492, y: 419} ].forEach(function(values, i) { - expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x); - expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y); + expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x); + expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y); }); var meta1 = chart.getDatasetMeta(1); - [ { x: 38, y: 32 }, - { x: 189, y: 97 }, - { x: 341, y: 161 }, - { x: 492, y: 471 } + [ + {x: 38, y: 32}, + {x: 189, y: 97}, + {x: 341, y: 161}, + {x: 492, y: 471} ].forEach(function(values, i) { - expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x); - expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y); + expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x); + expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y); }); }); @@ -478,24 +485,26 @@ describe('Line controller tests', function() { var meta0 = chart.getDatasetMeta(0); - [ { x: 38, y: 161 }, - { x: 189, y: 419 }, - { x: 341, y: 161 }, - { x: 492, y: 419 } + [ + {x: 38, y: 161}, + {x: 189, y: 419}, + {x: 341, y: 161}, + {x: 492, y: 419} ].forEach(function(values, i) { - expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x); - expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y); + expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x); + expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y); }); var meta1 = chart.getDatasetMeta(1); - [ { x: 38, y: 32 }, - { x: 189, y: 97 }, - { x: 341, y: 161 }, - { x: 492, y: 471 } + [ + {x: 38, y: 32}, + {x: 189, y: 97}, + {x: 341, y: 161}, + {x: 492, y: 471} ].forEach(function(values, i) { - expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x); - expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y); + expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x); + expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y); }); }); diff --git a/test/controller.polarArea.tests.js b/test/controller.polarArea.tests.js index 648117a4c10..3bd95eb231e 100644 --- a/test/controller.polarArea.tests.js +++ b/test/controller.polarArea.tests.js @@ -2,14 +2,14 @@ describe('Polar area controller tests', function() { it('should be constructed', function() { var chart = window.acquireChart({ - type: 'polarArea', - data: { - datasets: [ - { data: [] }, - { data: [] } - ], - labels: [] - } + type: 'polarArea', + data: { + datasets: [ + {data: []}, + {data: []} + ], + labels: [] + } }); var meta = chart.getDatasetMeta(1); @@ -28,8 +28,8 @@ describe('Polar area controller tests', function() { type: 'polarArea', data: { datasets: [ - { data: [] }, - { data: [10, 15, 0, -4] } + {data: []}, + {data: [10, 15, 0, -4]} ], labels: [] } @@ -45,14 +45,14 @@ describe('Polar area controller tests', function() { it('should draw all elements', function() { var chart = window.acquireChart({ - type: 'polarArea', - data: { - datasets: [{ - data: [10, 15, 0, -4], - label: 'dataset2' - }], - labels: ['label1', 'label2', 'label3', 'label4'] - } + type: 'polarArea', + data: { + datasets: [{ + data: [10, 15, 0, -4], + label: 'dataset2' + }], + labels: ['label1', 'label2', 'label3', 'label4'] + } }); var meta = chart.getDatasetMeta(0); @@ -95,10 +95,11 @@ describe('Polar area controller tests', function() { var meta = chart.getDatasetMeta(0); expect(meta.data.length).toBe(4); - [ { o: 156, s: -0.5 * Math.PI, e: 0 }, - { o: 211, s: 0, e: 0.5 * Math.PI }, - { o: 45, s: 0.5 * Math.PI, e: Math.PI }, - { o: 0, s: Math.PI, e: 1.5 * Math.PI } + [ + {o: 156, s: -0.5 * Math.PI, e: 0}, + {o: 211, s: 0, e: 0.5 * Math.PI}, + {o: 45, s: 0.5 * Math.PI, e: Math.PI}, + {o: 0, s: Math.PI, e: 1.5 * Math.PI} ].forEach(function(expected, i) { expect(meta.data[i]._model.x).toBeCloseToPixel(256); expect(meta.data[i]._model.y).toBeCloseToPixel(272); @@ -176,10 +177,11 @@ describe('Polar area controller tests', function() { var meta = chart.getDatasetMeta(0); expect(meta.data.length).toBe(4); - [ { o: 156, s: 0, e: 0.5 * Math.PI }, - { o: 211, s: 0.5 * Math.PI, e: Math.PI }, - { o: 45, s: Math.PI, e: 1.5 * Math.PI }, - { o: 0, s: 1.5 * Math.PI, e: 2.0 * Math.PI } + [ + {o: 156, s: 0, e: 0.5 * Math.PI}, + {o: 211, s: 0.5 * Math.PI, e: Math.PI}, + {o: 45, s: Math.PI, e: 1.5 * Math.PI}, + {o: 0, s: 1.5 * Math.PI, e: 2.0 * Math.PI} ].forEach(function(expected, i) { expect(meta.data[i]._model.x).toBeCloseToPixel(256); expect(meta.data[i]._model.y).toBeCloseToPixel(272); @@ -230,7 +232,7 @@ describe('Polar area controller tests', function() { expect(meta.data[0] instanceof Chart.elements.Arc).toBe(true); expect(meta.data[1] instanceof Chart.elements.Arc).toBe(true); - // add 3 items + // add 3 items chart.data.labels = ['label1', 'label2', 'label3', 'label4', 'label5']; chart.data.datasets[0].data = [1, 2, 3, 4, 5]; chart.update(); diff --git a/test/controller.radar.tests.js b/test/controller.radar.tests.js index 421ff9eb388..449d295c9c4 100644 --- a/test/controller.radar.tests.js +++ b/test/controller.radar.tests.js @@ -32,8 +32,6 @@ describe('Radar controller tests', function() { } }); - var controller = new Chart.controllers.radar(chart, 0); - var meta = chart.getDatasetMeta(0); expect(meta.dataset instanceof Chart.elements.Line).toBe(true); // line element expect(meta.data.length).toBe(4); // 4 points created @@ -130,10 +128,10 @@ describe('Radar controller tests', function() { })); [ - { x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272}, - { x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272}, - { x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272}, - { x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272}, + {x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272}, + {x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272}, + {x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272}, + {x: 256, y: 272, cppx: 256, cppy: 272, cpnx: 256, cpny: 272}, ].forEach(function(expected, i) { expect(meta.data[i]._model.x).toBeCloseToPixel(expected.x); expect(meta.data[i]._model.y).toBeCloseToPixel(expected.y); @@ -157,10 +155,10 @@ describe('Radar controller tests', function() { meta.controller.update(); [ - { x: 256, y: 133, cppx: 246, cppy: 133, cpnx: 272, cpny: 133 }, - { x: 464, y: 272, cppx: 464, cppy: 264, cpnx: 464, cpny: 278 }, - { x: 256, y: 272, cppx: 276.9, cppy: 272, cpnx: 250.4, cpny: 272 }, - { x: 200, y: 272, cppx: 200, cppy: 275, cpnx: 200, cpny: 261 }, + {x: 256, y: 133, cppx: 246, cppy: 133, cpnx: 272, cpny: 133}, + {x: 464, y: 272, cppx: 464, cppy: 264, cpnx: 464, cpny: 278}, + {x: 256, y: 272, cppx: 276.9, cppy: 272, cpnx: 250.4, cpny: 272}, + {x: 200, y: 272, cppx: 200, cppy: 275, cpnx: 200, cpny: 261}, ].forEach(function(expected, i) { expect(meta.data[i]._model.x).toBeCloseToPixel(expected.x); expect(meta.data[i]._model.y).toBeCloseToPixel(expected.y); @@ -218,10 +216,10 @@ describe('Radar controller tests', function() { // Since tension is now 0, we don't care about the control points [ - { x: 256, y: 133 }, - { x: 464, y: 272 }, - { x: 256, y: 272 }, - { x: 200, y: 272 }, + {x: 256, y: 133}, + {x: 464, y: 272}, + {x: 256, y: 272}, + {x: 200, y: 272}, ].forEach(function(expected, i) { expect(meta.data[i]._model.x).toBeCloseToPixel(expected.x); expect(meta.data[i]._model.y).toBeCloseToPixel(expected.y); @@ -454,4 +452,4 @@ describe('Radar controller tests', function() { expect(point._model.borderWidth).toBe(5.5); expect(point._model.radius).toBe(4.4); }); -}); \ No newline at end of file +}); diff --git a/test/core.element.tests.js b/test/core.element.tests.js index 6443de099d0..7d194562e73 100644 --- a/test/core.element.tests.js +++ b/test/core.element.tests.js @@ -25,9 +25,9 @@ describe('Core element tests', function() { element._model.numberProp = 100; element._model.numberProp2 = 250; element._model._underscoreProp = 200; - element._model.stringProp = 'def' + element._model.stringProp = 'def'; element._model.newStringProp = 'newString'; - element._model.colorProp = 'rgb(255, 255, 0)' + element._model.colorProp = 'rgb(255, 255, 0)'; element.transition(0.25); expect(element._view).toEqual({ @@ -42,4 +42,4 @@ describe('Core element tests', function() { colorProp: 'rgb(64, 64, 0)', }); }); -}); \ No newline at end of file +}); diff --git a/test/core.helpers.tests.js b/test/core.helpers.tests.js index 3d431606234..e9cbb8e4354 100644 --- a/test/core.helpers.tests.js +++ b/test/core.helpers.tests.js @@ -7,7 +7,7 @@ describe('Core helper tests', function() { }); it('should iterate over an array and pass the extra data to that function', function() { - var testData = [0, 9, "abc"]; + var testData = [0, 9, 'abc']; var scope = {}; // fake out the scope and ensure that 'this' is the correct thing helpers.each(testData, function(item, index) { @@ -183,7 +183,7 @@ describe('Core helper tests', function() { display: true, gridLines: { - color: "rgba(0, 0, 0, 0.1)", + color: 'rgba(0, 0, 0, 0.1)', drawBorder: true, drawOnChartArea: true, drawTicks: true, // draw ticks extending towards the label @@ -191,12 +191,12 @@ describe('Core helper tests', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: "rgba(0,0,0,0.25)", + zeroLineColor: 'rgba(0,0,0,0.25)', zeroLineWidth: 1, borderDash: [], borderDashOffset: 0.0 }, - position: "right", + position: 'right', scaleLabel: { labelString: '', display: false, @@ -219,7 +219,7 @@ describe('Core helper tests', function() { display: true, gridLines: { - color: "rgba(0, 0, 0, 0.1)", + color: 'rgba(0, 0, 0, 0.1)', drawBorder: true, drawOnChartArea: true, drawTicks: true, // draw ticks extending towards the label, @@ -227,12 +227,12 @@ describe('Core helper tests', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: "rgba(0,0,0,0.25)", + zeroLineColor: 'rgba(0,0,0,0.25)', zeroLineWidth: 1, borderDash: [], borderDashOffset: 0.0 }, - position: "left", + position: 'left', scaleLabel: { labelString: '', display: false, @@ -271,7 +271,7 @@ describe('Core helper tests', function() { it('should filter an array', function() { var data = [-10, 0, 6, 0, 7]; var callback = function(item) { - return item > 2 + return item > 2; }; expect(helpers.where(data, callback)).toEqual([6, 7]); expect(helpers.findNextWhere(data, callback)).toEqual(6); @@ -400,19 +400,19 @@ describe('Core helper tests', function() { it('should spline curves with monotone cubic interpolation', function() { var dataPoints = [ - { _model: { x: 0, y: 0, skip: false } }, - { _model: { x: 3, y: 6, skip: false } }, - { _model: { x: 9, y: 6, skip: false } }, - { _model: { x: 12, y: 60, skip: false } }, - { _model: { x: 15, y: 60, skip: false } }, - { _model: { x: 18, y: 120, skip: false } }, - { _model: { x: null, y: null, skip: true } }, - { _model: { x: 21, y: 180, skip: false } }, - { _model: { x: 24, y: 120, skip: false } }, - { _model: { x: 27, y: 125, skip: false } }, - { _model: { x: 30, y: 105, skip: false } }, - { _model: { x: 33, y: 110, skip: false } }, - { _model: { x: 36, y: 170, skip: false } } + {_model: {x: 0, y: 0, skip: false}}, + {_model: {x: 3, y: 6, skip: false}}, + {_model: {x: 9, y: 6, skip: false}}, + {_model: {x: 12, y: 60, skip: false}}, + {_model: {x: 15, y: 60, skip: false}}, + {_model: {x: 18, y: 120, skip: false}}, + {_model: {x: null, y: null, skip: true}}, + {_model: {x: 21, y: 180, skip: false}}, + {_model: {x: 24, y: 120, skip: false}}, + {_model: {x: 27, y: 125, skip: false}}, + {_model: {x: 30, y: 105, skip: false}}, + {_model: {x: 33, y: 110, skip: false}}, + {_model: {x: 36, y: 170, skip: false}} ]; helpers.splineCurveMonotone(dataPoints); expect(dataPoints).toEqual([{ @@ -580,13 +580,13 @@ describe('Core helper tests', function() { it('should return the width of the longest text in an Array and 2D Array', function() { var context = window.createMockContext(); var font = "normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"; - var arrayOfThings_1D = ['FooBar','Bar']; - var arrayOfThings_2D = [['FooBar_1','Bar_2'],'Foo_1']; - + var arrayOfThings1D = ['FooBar', 'Bar']; + var arrayOfThings2D = [['FooBar_1', 'Bar_2'], 'Foo_1']; + // Regardless 'FooBar' is the longest label it should return (charcters * 10) - expect(helpers.longestText(context, font, arrayOfThings_1D, {})).toEqual(60); - expect(helpers.longestText(context, font, arrayOfThings_2D, {})).toEqual(80); + expect(helpers.longestText(context, font, arrayOfThings1D, {})).toEqual(60); + expect(helpers.longestText(context, font, arrayOfThings2D, {})).toEqual(80); // We check to make sure we made the right calls to the canvas. expect(context.getCalls()).toEqual([{ name: 'measureText', @@ -629,14 +629,14 @@ describe('Core helper tests', function() { }); it('count look at all the labels and return maximum number of lines', function() { - var context = window.createMockContext(); - var arrayOfThings_1 = ['Foo','Bar']; - var arrayOfThings_2 = [['Foo','Bar'],'Foo']; - var arrayOfThings_3 = [['Foo','Bar','Boo'],['Foo','Bar'],'Foo']; + window.createMockContext(); + var arrayOfThings1 = ['Foo', 'Bar']; + var arrayOfThings2 = [['Foo', 'Bar'], 'Foo']; + var arrayOfThings3 = [['Foo', 'Bar', 'Boo'], ['Foo', 'Bar'], 'Foo']; - expect(helpers.numberOfLabelLines(arrayOfThings_1)).toEqual(1); - expect(helpers.numberOfLabelLines(arrayOfThings_2)).toEqual(2); - expect(helpers.numberOfLabelLines(arrayOfThings_3)).toEqual(3); + expect(helpers.numberOfLabelLines(arrayOfThings1)).toEqual(1); + expect(helpers.numberOfLabelLines(arrayOfThings2)).toEqual(2); + expect(helpers.numberOfLabelLines(arrayOfThings3)).toEqual(3); }); it('should draw a rounded rectangle', function() { @@ -676,14 +676,14 @@ describe('Core helper tests', function() { }, { name: 'closePath', args: [] - }]) + }]); }); it ('should get the maximum width and height for a node', function() { // Create div with fixed size as a test bed var div = document.createElement('div'); - div.style.width = "200px"; - div.style.height = "300px"; + div.style.width = '200px'; + div.style.height = '300px'; document.body.appendChild(div); @@ -700,14 +700,14 @@ describe('Core helper tests', function() { it ('should get the maximum width of a node that has a max-width style', function() { // Create div with fixed size as a test bed var div = document.createElement('div'); - div.style.width = "200px"; - div.style.height = "300px"; + div.style.width = '200px'; + div.style.height = '300px'; document.body.appendChild(div); // Create the div we want to get the max size for and set a max-width style var innerDiv = document.createElement('div'); - innerDiv.style.maxWidth = "150px"; + innerDiv.style.maxWidth = '150px'; div.appendChild(innerDiv); expect(helpers.getMaximumWidth(innerDiv)).toBe(150); @@ -718,14 +718,14 @@ describe('Core helper tests', function() { it ('should get the maximum height of a node that has a max-height style', function() { // Create div with fixed size as a test bed var div = document.createElement('div'); - div.style.width = "200px"; - div.style.height = "300px"; + div.style.width = '200px'; + div.style.height = '300px'; document.body.appendChild(div); // Create the div we want to get the max size for and set a max-height style var innerDiv = document.createElement('div'); - innerDiv.style.maxHeight = "150px"; + innerDiv.style.maxHeight = '150px'; div.appendChild(innerDiv); expect(helpers.getMaximumHeight(innerDiv)).toBe(150); @@ -736,14 +736,14 @@ describe('Core helper tests', function() { it ('should get the maximum width of a node when the parent has a max-width style', function() { // Create div with fixed size as a test bed var div = document.createElement('div'); - div.style.width = "200px"; - div.style.height = "300px"; + div.style.width = '200px'; + div.style.height = '300px'; document.body.appendChild(div); // Create an inner wrapper around our div we want to size and give that a max-width style var parentDiv = document.createElement('div'); - parentDiv.style.maxWidth = "150px"; + parentDiv.style.maxWidth = '150px'; div.appendChild(parentDiv); // Create the div we want to get the max size for @@ -758,19 +758,19 @@ describe('Core helper tests', function() { it ('should get the maximum height of a node when the parent has a max-height style', function() { // Create div with fixed size as a test bed var div = document.createElement('div'); - div.style.width = "200px"; - div.style.height = "300px"; + div.style.width = '200px'; + div.style.height = '300px'; document.body.appendChild(div); // Create an inner wrapper around our div we want to size and give that a max-height style var parentDiv = document.createElement('div'); - parentDiv.style.maxHeight = "150px"; + parentDiv.style.maxHeight = '150px'; div.appendChild(parentDiv); // Create the div we want to get the max size for var innerDiv = document.createElement('div'); - innerDiv.style.height = "300px"; // make it large + innerDiv.style.height = '300px'; // make it large parentDiv.appendChild(innerDiv); expect(helpers.getMaximumHeight(innerDiv)).toBe(150); @@ -781,14 +781,14 @@ describe('Core helper tests', function() { it ('should get the maximum width of a node that has a percentage max-width style', function() { // Create div with fixed size as a test bed var div = document.createElement('div'); - div.style.width = "200px"; - div.style.height = "300px"; + div.style.width = '200px'; + div.style.height = '300px'; document.body.appendChild(div); // Create the div we want to get the max size for and set a max-width style var innerDiv = document.createElement('div'); - innerDiv.style.maxWidth = "50%"; + innerDiv.style.maxWidth = '50%'; div.appendChild(innerDiv); expect(helpers.getMaximumWidth(innerDiv)).toBe(100); @@ -799,14 +799,14 @@ describe('Core helper tests', function() { it ('should get the maximum height of a node that has a percentage max-height style', function() { // Create div with fixed size as a test bed var div = document.createElement('div'); - div.style.width = "200px"; - div.style.height = "300px"; + div.style.width = '200px'; + div.style.height = '300px'; document.body.appendChild(div); // Create the div we want to get the max size for and set a max-height style var innerDiv = document.createElement('div'); - innerDiv.style.maxHeight = "50%"; + innerDiv.style.maxHeight = '50%'; div.appendChild(innerDiv); expect(helpers.getMaximumHeight(innerDiv)).toBe(150); @@ -817,14 +817,14 @@ describe('Core helper tests', function() { it ('should get the maximum width of a node when the parent has a percentage max-width style', function() { // Create div with fixed size as a test bed var div = document.createElement('div'); - div.style.width = "200px"; - div.style.height = "300px"; + div.style.width = '200px'; + div.style.height = '300px'; document.body.appendChild(div); // Create an inner wrapper around our div we want to size and give that a max-width style var parentDiv = document.createElement('div'); - parentDiv.style.maxWidth = "50%"; + parentDiv.style.maxWidth = '50%'; div.appendChild(parentDiv); // Create the div we want to get the max size for @@ -839,18 +839,18 @@ describe('Core helper tests', function() { it ('should get the maximum height of a node when the parent has a percentage max-height style', function() { // Create div with fixed size as a test bed var div = document.createElement('div'); - div.style.width = "200px"; - div.style.height = "300px"; + div.style.width = '200px'; + div.style.height = '300px'; document.body.appendChild(div); // Create an inner wrapper around our div we want to size and give that a max-height style var parentDiv = document.createElement('div'); - parentDiv.style.maxHeight = "50%"; + parentDiv.style.maxHeight = '50%'; div.appendChild(parentDiv); var innerDiv = document.createElement('div'); - innerDiv.style.height = "300px"; // make it large + innerDiv.style.height = '300px'; // make it large parentDiv.appendChild(innerDiv); expect(helpers.getMaximumHeight(innerDiv)).toBe(150); @@ -891,7 +891,7 @@ describe('Core helper tests', function() { expect(backgroundColor instanceof CanvasPattern).toBe(true); done(); - } + }; }); it('should return a modified version of color when called with a color', function() { diff --git a/test/core.interaction.tests.js b/test/core.interaction.tests.js index 312ac8fe663..15189a4771d 100644 --- a/test/core.interaction.tests.js +++ b/test/core.interaction.tests.js @@ -115,7 +115,7 @@ describe('Core.Interaction', function() { currentTarget: node }; - var elements = Chart.Interaction.modes.index(chartInstance, evt, { intersect: true }); + var elements = Chart.Interaction.modes.index(chartInstance, evt, {intersect: true}); expect(elements).toEqual([point, meta1.data[1]]); }); @@ -154,7 +154,7 @@ describe('Core.Interaction', function() { currentTarget: node }; - var elements = Chart.Interaction.modes.index(chartInstance, evt, { intersect: false }); + var elements = Chart.Interaction.modes.index(chartInstance, evt, {intersect: false}); expect(elements).toEqual([meta0.data[0], meta1.data[0]]); }); }); @@ -195,7 +195,7 @@ describe('Core.Interaction', function() { currentTarget: node }; - var elements = Chart.Interaction.modes.dataset(chartInstance, evt, { intersect: true }); + var elements = Chart.Interaction.modes.dataset(chartInstance, evt, {intersect: true}); expect(elements).toEqual(meta.data); }); @@ -230,7 +230,7 @@ describe('Core.Interaction', function() { currentTarget: node }; - var elements = Chart.Interaction.modes.dataset(chartInstance, evt, { intersect: false }); + var elements = Chart.Interaction.modes.dataset(chartInstance, evt, {intersect: false}); var meta = chartInstance.getDatasetMeta(1); expect(elements).toEqual(meta.data); @@ -260,7 +260,6 @@ describe('Core.Interaction', function() { // Trigger an event over top of the var meta = chartInstance.getDatasetMeta(1); var node = chartInstance.chart.canvas; - var rect = node.getBoundingClientRect(); var evt = { view: window, bubbles: true, @@ -271,7 +270,7 @@ describe('Core.Interaction', function() { }; // Nearest to 0,0 (top left) will be first point of dataset 2 - var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: false }); + var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: false}); expect(elements).toEqual([meta.data[0]]); }); @@ -318,7 +317,7 @@ describe('Core.Interaction', function() { }; // Nearest to 0,0 (top left) will be first point of dataset 2 - var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: false }); + var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: false}); expect(elements).toEqual([meta0.data[1]]); }); @@ -365,7 +364,7 @@ describe('Core.Interaction', function() { }; // Nearest to 0,0 (top left) will be first point of dataset 2 - var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: false }); + var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: false}); expect(elements).toEqual([meta0.data[1]]); }); }); @@ -406,7 +405,7 @@ describe('Core.Interaction', function() { }; // Nothing intersects so find nothing - var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: true }); + var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: true}); expect(elements).toEqual([]); evt = { @@ -417,7 +416,7 @@ describe('Core.Interaction', function() { clientY: rect.top + point._view.y, currentTarget: node }; - elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: true }); + elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: true}); expect(elements).toEqual([point]); }); @@ -463,7 +462,7 @@ describe('Core.Interaction', function() { }; // Nearest to 0,0 (top left) will be first point of dataset 2 - var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: true }); + var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: true}); expect(elements).toEqual([meta0.data[1]]); }); @@ -509,7 +508,7 @@ describe('Core.Interaction', function() { }; // Nearest to 0,0 (top left) will be first point of dataset 2 - var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: true }); + var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: true}); expect(elements).toEqual([meta0.data[1]]); }); @@ -555,7 +554,7 @@ describe('Core.Interaction', function() { }; // Nearest to 0,0 (top left) will be first point of dataset 2 - var elements = Chart.Interaction.modes.nearest(chartInstance, evt, { intersect: true }); + var elements = Chart.Interaction.modes.nearest(chartInstance, evt, {intersect: true}); expect(elements).toEqual([meta0.data[1]]); }); }); diff --git a/test/core.layoutService.tests.js b/test/core.layoutService.tests.js index 860b4b64900..4fa1039d569 100644 --- a/test/core.layoutService.tests.js +++ b/test/core.layoutService.tests.js @@ -5,7 +5,7 @@ describe('Test the layout service', function() { type: 'bar', data: { datasets: [ - { data: [10, 5, 0, 25, 78, -10] } + {data: [10, 5, 0, 25, 78, -10]} ], labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6'] }, @@ -53,7 +53,7 @@ describe('Test the layout service', function() { type: 'bar', data: { datasets: [ - { data: [10, 5, 0, 25, 78, -10] } + {data: [10, 5, 0, 25, 78, -10]} ], labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6'] }, @@ -121,7 +121,7 @@ describe('Test the layout service', function() { expect(chart.scale.right).toBeCloseToPixel(512); expect(chart.scale.top).toBeCloseToPixel(32); expect(chart.scale.width).toBeCloseToPixel(512); - expect(chart.scale.height).toBeCloseToPixel(480) + expect(chart.scale.height).toBeCloseToPixel(480); }); it('should fit multiple axes in the same position', function() { diff --git a/test/core.legend.tests.js b/test/core.legend.tests.js index caa35883a19..6d539fd1ec2 100644 --- a/test/core.legend.tests.js +++ b/test/core.legend.tests.js @@ -118,20 +118,21 @@ describe('Legend block tests', function() { expect(chart.legend.legendHitBoxes.length).toBe(3); - [ { h: 12, l: 101, t: 10, w: 93 }, - { h: 12, l: 205, t: 10, w: 93 }, - { h: 12, l: 308, t: 10, w: 93 } + [ + {h: 12, l: 101, t: 10, w: 93}, + {h: 12, l: 205, t: 10, w: 93}, + {h: 12, l: 308, t: 10, w: 93} ].forEach(function(expected, i) { expect(chart.legend.legendHitBoxes[i].height).toBeCloseToPixel(expected.h); expect(chart.legend.legendHitBoxes[i].left).toBeCloseToPixel(expected.l); expect(chart.legend.legendHitBoxes[i].top).toBeCloseToPixel(expected.t); expect(chart.legend.legendHitBoxes[i].width).toBeCloseToPixel(expected.w); - }) + }); // NOTE(SB) We should get ride of the following tests and use image diff instead. // For now, as discussed with Evert Timberg, simply comment out. // See http://humblesoftware.github.io/js-imagediff/test.html - /*chart.legend.ctx = window.createMockContext(); + /* chart.legend.ctx = window.createMockContext(); chart.update(); expect(chart.legend.ctx .getCalls()).toEqual([{ diff --git a/test/core.plugin.tests.js b/test/core.plugin.tests.js index 0d4186af8d6..59a71b1c55e 100644 --- a/test/core.plugin.tests.js +++ b/test/core.plugin.tests.js @@ -75,24 +75,52 @@ describe('Chart.plugins', function() { }; Chart.plugins.register(myplugin); - Chart.plugins.notify('trigger', [{ count: 10 }]); + Chart.plugins.notify('trigger', [{count: 10}]); expect(myplugin.count).toBe(10); }); it('should return TRUE if no plugin explicitly returns FALSE', function() { - Chart.plugins.register({ check: function() {} }); - Chart.plugins.register({ check: function() { return; } }); - Chart.plugins.register({ check: function() { return null; } }); - Chart.plugins.register({ check: function() { return 42 } }); + Chart.plugins.register({ + check: function() {} + }); + Chart.plugins.register({ + check: function() { + return; + } + }); + Chart.plugins.register({ + check: function() { + return null; + } + }); + Chart.plugins.register({ + check: function() { + return 42; + } + }); var res = Chart.plugins.notify('check'); expect(res).toBeTruthy(); }); it('should return FALSE if no plugin explicitly returns FALSE', function() { - Chart.plugins.register({ check: function() {} }); - Chart.plugins.register({ check: function() { return; } }); - Chart.plugins.register({ check: function() { return false; } }); - Chart.plugins.register({ check: function() { return 42 } }); + Chart.plugins.register({ + check: function() {} + }); + Chart.plugins.register({ + check: function() { + return; + } + }); + Chart.plugins.register({ + check: function() { + return false; + } + }); + Chart.plugins.register({ + check: function() { + return 42; + } + }); var res = Chart.plugins.notify('check'); expect(res).toBeFalsy(); }); diff --git a/test/core.scaleService.tests.js b/test/core.scaleService.tests.js index ca0eaf20d6c..aacac9879a9 100644 --- a/test/core.scaleService.tests.js +++ b/test/core.scaleService.tests.js @@ -15,7 +15,7 @@ describe('Test the scale service', function() { expect(Chart.scaleService.getScaleDefaults(type)).toEqual(jasmine.objectContaining({ testProp: true })); - + Chart.scaleService.updateScaleDefaults(type, { testProp: 'red', newProp: 42 diff --git a/test/core.title.tests.js b/test/core.title.tests.js index b8ecd18e5cb..7046052781e 100644 --- a/test/core.title.tests.js +++ b/test/core.title.tests.js @@ -14,14 +14,14 @@ describe('Title block tests', function() { fontStyle: 'bold', padding: 10, text: '' - }) + }); }); it('should update correctly', function() { var chart = {}; var options = Chart.helpers.clone(Chart.defaults.global.title); - options.text = "My title"; + options.text = 'My title'; var title = new Chart.Title({ chart: chart, @@ -50,7 +50,7 @@ describe('Title block tests', function() { var chart = {}; var options = Chart.helpers.clone(Chart.defaults.global.title); - options.text = "My title"; + options.text = 'My title'; options.position = 'left'; var title = new Chart.Title({ @@ -81,7 +81,7 @@ describe('Title block tests', function() { var context = window.createMockContext(); var options = Chart.helpers.clone(Chart.defaults.global.title); - options.text = "My title"; + options.text = 'My title'; var title = new Chart.Title({ chart: chart, @@ -130,7 +130,7 @@ describe('Title block tests', function() { var context = window.createMockContext(); var options = Chart.helpers.clone(Chart.defaults.global.title); - options.text = "My title"; + options.text = 'My title'; options.position = 'left'; var title = new Chart.Title({ diff --git a/test/core.tooltip.tests.js b/test/core.tooltip.tests.js index dd6ee17f59c..29c6b721a49 100755 --- a/test/core.tooltip.tests.js +++ b/test/core.tooltip.tests.js @@ -342,7 +342,7 @@ describe('Core.Tooltip', function() { return 'title'; }, afterTitle: function() { - return 'afterTitle' + return 'afterTitle'; }, beforeBody: function() { return 'beforeBody'; @@ -366,7 +366,7 @@ describe('Core.Tooltip', function() { return 'footer'; }, afterFooter: function() { - return 'afterFooter' + return 'afterFooter'; } } } @@ -494,9 +494,6 @@ describe('Core.Tooltip', function() { var meta0 = chartInstance.getDatasetMeta(0); var point0 = meta0.data[1]; - var meta1 = chartInstance.getDatasetMeta(1); - var point1 = meta1.data[1]; - var node = chartInstance.chart.canvas; var rect = node.getBoundingClientRect(); diff --git a/test/defaultConfig.tests.js b/test/defaultConfig.tests.js index 84c9655e6c7..0e859901434 100644 --- a/test/defaultConfig.tests.js +++ b/test/defaultConfig.tests.js @@ -1,6 +1,6 @@ // Test the bubble chart default config -describe("Default Configs", function() { - describe("Bubble Chart", function() { +describe('Default Configs', function() { + describe('Bubble Chart', function() { it('should return correct tooltip strings', function() { var config = Chart.defaults.bubble; var chart = window.acquireChart({ @@ -22,7 +22,7 @@ describe("Default Configs", function() { chart.tooltip._active = [chart.getDatasetMeta(0).data[0]]; chart.tooltip.update(); - // Title is always blank + // Title is always blank expect(chart.tooltip._model.title).toEqual([]); expect(chart.tooltip._model.body).toEqual([{ before: [], @@ -50,7 +50,7 @@ describe("Default Configs", function() { chart.tooltip._active = [chart.getDatasetMeta(0).data[1]]; chart.tooltip.update(); - // Title is always blank + // Title is always blank expect(chart.tooltip._model.title).toEqual([]); expect(chart.tooltip._model.body).toEqual([{ before: [], @@ -76,7 +76,7 @@ describe("Default Configs", function() { chart.tooltip._active = [chart.getDatasetMeta(0).data[1]]; chart.tooltip.update(); - // Title is always blank + // Title is always blank expect(chart.tooltip._model.title).toEqual([]); expect(chart.tooltip._model.body).toEqual([{ before: [], @@ -196,7 +196,7 @@ describe("Default Configs", function() { chart.tooltip._active = [chart.getDatasetMeta(0).data[1]]; chart.tooltip.update(); - // Title is always blank + // Title is always blank expect(chart.tooltip._model.title).toEqual([]); expect(chart.tooltip._model.body).toEqual([{ before: [], @@ -280,7 +280,7 @@ describe("Default Configs", function() { options: config }); var meta = chart.getDatasetMeta(0); - + spyOn(chart, 'update').and.callThrough(); var legendItem = chart.legend.legendItems[0]; diff --git a/test/element.arc.tests.js b/test/element.arc.tests.js index 7ce70517d24..b2caaadaa4c 100644 --- a/test/element.arc.tests.js +++ b/test/element.arc.tests.js @@ -213,4 +213,4 @@ describe('Arc element tests', function() { args: [] }]); }); -}); \ No newline at end of file +}); diff --git a/test/element.line.tests.js b/test/element.line.tests.js index 0f495c9d1fa..0a2a6eced56 100644 --- a/test/element.line.tests.js +++ b/test/element.line.tests.js @@ -2580,4 +2580,4 @@ describe('Line element tests', function() { args: [] }]); }); -}); \ No newline at end of file +}); diff --git a/test/element.point.tests.js b/test/element.point.tests.js index 9cbac8ea560..61fe3d09a4e 100644 --- a/test/element.point.tests.js +++ b/test/element.point.tests.js @@ -91,7 +91,7 @@ describe('Point element tests', function() { y: 10 }; - expect(point.getCenterPoint()).toEqual({ x: 10, y: 10 }); + expect(point.getCenterPoint()).toEqual({x: 10, y: 10}); }); it ('should draw correctly', function() { @@ -275,7 +275,7 @@ describe('Point element tests', function() { }, { name: 'lineTo', args: [12, 15], - },{ + }, { name: 'closePath', args: [], }, { @@ -347,7 +347,7 @@ describe('Point element tests', function() { }, { name: 'lineTo', args: [12, 15], - },{ + }, { name: 'moveTo', args: [10 - Math.cos(Math.PI / 4) * 2, 15 - Math.sin(Math.PI / 4) * 2] }, { @@ -501,4 +501,4 @@ describe('Point element tests', function() { expect(mockContext.getCalls()).toEqual([]); }); -}); \ No newline at end of file +}); diff --git a/test/element.rectangle.tests.js b/test/element.rectangle.tests.js index bd32ff3ac23..b833862bd6f 100644 --- a/test/element.rectangle.tests.js +++ b/test/element.rectangle.tests.js @@ -163,7 +163,7 @@ describe('Rectangle element tests', function() { y: 15 }; - expect(rectangle.getCenterPoint()).toEqual({ x: 10, y: 7.5 }); + expect(rectangle.getCenterPoint()).toEqual({x: 10, y: 7.5}); }); it ('should draw correctly', function() { @@ -276,10 +276,10 @@ describe('Rectangle element tests', function() { }]); }); - function testBorderSkipped (borderSkipped, expectedDrawCalls) { + function testBorderSkipped(borderSkipped, expectedDrawCalls) { var mockContext = window.createMockContext(); var rectangle = new Chart.elements.Rectangle({ - _chart: { ctx: mockContext } + _chart: {ctx: mockContext} }); // Attach a view object as if we were the controller @@ -291,47 +291,47 @@ describe('Rectangle element tests', function() { x: 10, y: 15, }; - + rectangle.draw(); - var drawCalls = rectangle._view.ctx.getCalls().splice(4, 4); + var drawCalls = rectangle._view.ctx.getCalls().splice(4, 4); expect(drawCalls).toEqual(expectedDrawCalls); } - + it ('should draw correctly respecting "borderSkipped" == "bottom"', function() { testBorderSkipped ('bottom', [ - { name: 'moveTo', args: [8, 0] }, - { name: 'lineTo', args: [8, 15] }, - { name: 'lineTo', args: [12, 15] }, - { name: 'lineTo', args: [12, 0] }, + {name: 'moveTo', args: [8, 0]}, + {name: 'lineTo', args: [8, 15]}, + {name: 'lineTo', args: [12, 15]}, + {name: 'lineTo', args: [12, 0]}, ]); }); it ('should draw correctly respecting "borderSkipped" == "left"', function() { testBorderSkipped ('left', [ - { name: 'moveTo', args: [8, 15] }, - { name: 'lineTo', args: [12, 15] }, - { name: 'lineTo', args: [12, 0] }, - { name: 'lineTo', args: [8, 0] }, + {name: 'moveTo', args: [8, 15]}, + {name: 'lineTo', args: [12, 15]}, + {name: 'lineTo', args: [12, 0]}, + {name: 'lineTo', args: [8, 0]}, ]); }); it ('should draw correctly respecting "borderSkipped" == "top"', function() { testBorderSkipped ('top', [ - { name: 'moveTo', args: [12, 15] }, - { name: 'lineTo', args: [12, 0] }, - { name: 'lineTo', args: [8, 0] }, - { name: 'lineTo', args: [8, 15] }, + {name: 'moveTo', args: [12, 15]}, + {name: 'lineTo', args: [12, 0]}, + {name: 'lineTo', args: [8, 0]}, + {name: 'lineTo', args: [8, 15]}, ]); }); it ('should draw correctly respecting "borderSkipped" == "right"', function() { testBorderSkipped ('right', [ - { name: 'moveTo', args: [12, 0] }, - { name: 'lineTo', args: [8, 0] }, - { name: 'lineTo', args: [8, 15] }, - { name: 'lineTo', args: [12, 15] }, + {name: 'moveTo', args: [12, 0]}, + {name: 'lineTo', args: [8, 0]}, + {name: 'lineTo', args: [8, 15]}, + {name: 'lineTo', args: [12, 15]}, ]); }); -}); \ No newline at end of file +}); diff --git a/test/mockContext.js b/test/mockContext.js index 8904cf88612..58a2ccf2355 100644 --- a/test/mockContext.js +++ b/test/mockContext.js @@ -1,3 +1,5 @@ +/* eslint guard-for-in: 1 */ +/* eslint camelcase: 1 */ (function() { // Code from http://stackoverflow.com/questions/4406864/html-canvas-unit-testing var Context = function() { @@ -13,44 +15,56 @@ // Define properties here so that we can record each time they are set Object.defineProperties(this, { - "fillStyle": { - 'get': function() { return this._fillStyle; }, - 'set': function(style) { + fillStyle: { + get: function() { + return this._fillStyle; + }, + set: function(style) { this._fillStyle = style; this.record('setFillStyle', [style]); } }, - 'lineCap': { - 'get': function() { return this._lineCap; }, - 'set': function(cap) { + lineCap: { + get: function() { + return this._lineCap; + }, + set: function(cap) { this._lineCap = cap; this.record('setLineCap', [cap]); } }, - 'lineDashOffset': { - 'get': function() { return this._lineDashOffset; }, - 'set': function(offset) { + lineDashOffset: { + get: function() { + return this._lineDashOffset; + }, + set: function(offset) { this._lineDashOffset = offset; this.record('setLineDashOffset', [offset]); } }, - 'lineJoin': { - 'get': function() { return this._lineJoin; }, - 'set': function(join) { + lineJoin: { + get: function() { + return this._lineJoin; + }, + set: function(join) { this._lineJoin = join; this.record('setLineJoin', [join]); } }, - 'lineWidth': { - 'get': function() { return this._lineWidth; }, - 'set': function (width) { + lineWidth: { + get: function() { + return this._lineWidth; + }, + set: function(width) { this._lineWidth = width; this.record('setLineWidth', [width]); } }, - 'strokeStyle': { - 'get': function() { return this._strokeStyle; }, - 'set': function(style) { + strokeStyle: { + get: function() { + return this._strokeStyle; + }, + set: function(style) { this._strokeStyle = style; this.record('setStrokeStyle', [style]); } @@ -70,33 +84,35 @@ fill: function() {}, fillRect: function() {}, fillText: function() {}, - lineTo: function(x, y) {}, + lineTo: function() {}, measureText: function(text) { // return the number of characters * fixed size - return text ? { width: text.length * 10 } : {width: 0}; + return text ? {width: text.length * 10} : {width: 0}; }, - moveTo: function(x, y) {}, + moveTo: function() {}, quadraticCurveTo: function() {}, restore: function() {}, rotate: function() {}, save: function() {}, setLineDash: function() {}, stroke: function() {}, - strokeRect: function(x, y, w, h) {}, - setTransform: function(a, b, c, d, e, f) {}, - translate: function(x, y) {}, + strokeRect: function() {}, + setTransform: function() {}, + translate: function() {}, }; // attach methods to the class itself - var scope = this; + var me = this; + var methodName; + var addMethod = function(name, method) { - scope[methodName] = function() { - scope.record(name, arguments); - return method.apply(scope, arguments); + me[methodName] = function() { + me.record(name, arguments); + return method.apply(me, arguments); }; - } + }; - for (var methodName in methods) { + for (methodName in methods) { var method = methods[methodName]; addMethod(methodName, method); @@ -108,11 +124,11 @@ name: methodName, args: Array.prototype.slice.call(args) }); - }, + }; Context.prototype.getCalls = function() { return this._calls; - } + }; Context.prototype.resetCalls = function() { this._calls = []; @@ -136,10 +152,10 @@ result = (diff <= (A > B ? A : B) * percentDiff) || diff < 2; // 2 pixels is fine } - return { pass: result }; + return {pass: result}; } - } - }; + }; + } function toEqualOneOf() { return { @@ -251,13 +267,13 @@ * @param {boolean} options.persistent - If true, the chart will not be released after the spec. */ function acquireChart(config, options) { - var wrapper = document.createElement("div"); - var canvas = document.createElement("canvas"); + var wrapper = document.createElement('div'); + var canvas = document.createElement('canvas'); var chart, key; options = options || {}; - options.canvas = options.canvas || { height: 512, width: 512 }; - options.wrapper = options.wrapper || { class: 'chartjs-wrapper' }; + options.canvas = options.canvas || {height: 512, width: 512}; + options.wrapper = options.wrapper || {class: 'chartjs-wrapper'}; for (key in options.canvas) { if (options.canvas.hasOwnProperty(key)) { @@ -280,7 +296,7 @@ wrapper.appendChild(canvas); window.document.body.appendChild(wrapper); - chart = new Chart(canvas.getContext("2d"), config); + chart = new Chart(canvas.getContext('2d'), config); chart._test_persistent = options.persistent; chart._test_wrapper = wrapper; charts[chart.id] = chart; @@ -329,4 +345,4 @@ '.chartjs-wrapper {' + 'position: absolute' + '}'); -})(); +}()); diff --git a/test/scale.category.tests.js b/test/scale.category.tests.js index 5307ba6527f..13955d35be4 100644 --- a/test/scale.category.tests.js +++ b/test/scale.category.tests.js @@ -13,7 +13,7 @@ describe('Category scale tests', function() { display: true, gridLines: { - color: "rgba(0, 0, 0, 0.1)", + color: 'rgba(0, 0, 0, 0.1)', drawBorder: true, drawOnChartArea: true, drawTicks: true, // draw ticks extending towards the label @@ -21,12 +21,12 @@ describe('Category scale tests', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: "rgba(0,0,0,0.25)", + zeroLineColor: 'rgba(0,0,0,0.25)', zeroLineWidth: 1, borderDash: [], borderDashOffset: 0.0 }, - position: "bottom", + position: 'bottom', scaleLabel: { labelString: '', display: false @@ -287,8 +287,8 @@ describe('Category scale tests', function() { var mockContext = window.createMockContext(); var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category')); config.gridLines.offsetGridLines = true; - config.ticks.min = "tick2"; - config.ticks.max = "tick4"; + config.ticks.min = 'tick2'; + config.ticks.max = 'tick4'; var Constructor = Chart.scaleService.getScaleConstructor('category'); var scale = new Constructor({ @@ -349,7 +349,7 @@ describe('Category scale tests', function() { var mockContext = window.createMockContext(); var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category')); config.gridLines.offsetGridLines = true; - config.position = "left"; + config.position = 'left'; var Constructor = Chart.scaleService.getScaleConstructor('category'); var scale = new Constructor({ ctx: mockContext, @@ -414,9 +414,9 @@ describe('Category scale tests', function() { var mockContext = window.createMockContext(); var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category')); config.gridLines.offsetGridLines = true; - config.ticks.min = "tick2"; - config.ticks.max = "tick4"; - config.position = "left"; + config.ticks.min = 'tick2'; + config.ticks.max = 'tick4'; + config.position = 'left'; var Constructor = Chart.scaleService.getScaleConstructor('category'); var scale = new Constructor({ diff --git a/test/scale.linear.tests.js b/test/scale.linear.tests.js index 4eb585a7b66..7102a6f4a8c 100644 --- a/test/scale.linear.tests.js +++ b/test/scale.linear.tests.js @@ -11,7 +11,7 @@ describe('Linear Scale', function() { display: true, gridLines: { - color: "rgba(0, 0, 0, 0.1)", + color: 'rgba(0, 0, 0, 0.1)', drawBorder: true, drawOnChartArea: true, drawTicks: true, // draw ticks extending towards the label @@ -19,12 +19,12 @@ describe('Linear Scale', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: "rgba(0,0,0,0.25)", + zeroLineColor: 'rgba(0,0,0,0.25)', zeroLineWidth: 1, borderDash: [], borderDashOffset: 0.0 }, - position: "left", + position: 'left', scaleLabel: { labelString: '', display: false, diff --git a/test/scale.logarithmic.tests.js b/test/scale.logarithmic.tests.js index 221e61c4bd2..9636a0b375c 100644 --- a/test/scale.logarithmic.tests.js +++ b/test/scale.logarithmic.tests.js @@ -10,7 +10,7 @@ describe('Logarithmic Scale tests', function() { expect(defaultConfig).toEqual({ display: true, gridLines: { - color: "rgba(0, 0, 0, 0.1)", + color: 'rgba(0, 0, 0, 0.1)', drawBorder: true, drawOnChartArea: true, drawTicks: true, @@ -18,12 +18,12 @@ describe('Logarithmic Scale tests', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: "rgba(0,0,0,0.25)", + zeroLineColor: 'rgba(0,0,0,0.25)', zeroLineWidth: 1, borderDash: [], borderDashOffset: 0.0 }, - position: "left", + position: 'left', scaleLabel: { labelString: '', display: false, @@ -78,14 +78,14 @@ describe('Logarithmic Scale tests', function() { id: 'yScale1', type: 'logarithmic' }, - { - id: 'yScale2', - type: 'logarithmic' - }, - { - id: 'yScale3', - type: 'logarithmic' - }] + { + id: 'yScale2', + type: 'logarithmic' + }, + { + id: 'yScale3', + type: 'logarithmic' + }] } } }); @@ -125,7 +125,7 @@ describe('Logarithmic Scale tests', function() { data: ['20', '0', '150', '1800', '3040'] }, { yAxisID: 'yScale3', - data: ['67', '0.0004', '0', '820', '0.001'] + data: ['67', '0.0004', '0', '820', '0.001'] }], labels: ['a', 'b', 'c', 'd', 'e'] }, @@ -141,10 +141,10 @@ describe('Logarithmic Scale tests', function() { id: 'yScale2', type: 'logarithmic' }, - { - id: 'yScale3', - type: 'logarithmic' - }] + { + id: 'yScale3', + type: 'logarithmic' + }] } } }); @@ -185,8 +185,8 @@ describe('Logarithmic Scale tests', function() { data: [20, 0, 7400, 14, 291] }, { yAxisID: 'yScale2', - data: [6, 0.0007, 9, 890, 60000], - hidden: true + data: [6, 0.0007, 9, 890, 60000], + hidden: true }], labels: ['a', 'b', 'c', 'd', 'e'] }, @@ -232,7 +232,7 @@ describe('Logarithmic Scale tests', function() { yAxisID: 'yScale1', data: [undefined, 0, null, 800, 9, NaN, 894, 21] }], - labels: ['a', 'b', 'c', 'd', 'e', 'f' ,'g', 'h', 'i'] + labels: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'] }, options: { scales: { @@ -269,10 +269,10 @@ describe('Logarithmic Scale tests', function() { data: { datasets: [{ data: [ - { x: 10, y: 100 }, - { x: 2, y: 6 }, - { x: 65, y: 121 }, - { x: 99, y: 7 } + {x: 10, y: 100}, + {x: 2, y: 6}, + {x: 65, y: 121}, + {x: 99, y: 7} ] }] }, @@ -304,10 +304,10 @@ describe('Logarithmic Scale tests', function() { data: { datasets: [{ data: [ - { x: 7, y: 950 }, - { x: 289, y: 0 }, - { x: 0, y: 8 }, - { x: 23, y: 0.04 } + {x: 7, y: 950}, + {x: 289, y: 0}, + {x: 0, y: 8}, + {x: 23, y: 0.04} ] }] }, @@ -718,9 +718,9 @@ describe('Logarithmic Scale tests', function() { var xScale = chart.scales.xScale; expect(xScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(495); // right - paddingRight - expect(xScale.getPixelForValue( 1, 0, 0)).toBeCloseToPixel(48); // left + paddingLeft + expect(xScale.getPixelForValue(1, 0, 0)).toBeCloseToPixel(48); // left + paddingLeft expect(xScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(283); // halfway - expect(xScale.getPixelForValue( 0, 0, 0)).toBeCloseToPixel(48); // 0 is invalid, put it on the left. + expect(xScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(48); // 0 is invalid, put it on the left. expect(xScale.getValueForPixel(495)).toBeCloseTo(80, 1e-4); expect(xScale.getValueForPixel(48)).toBeCloseTo(1, 1e-4); @@ -728,9 +728,9 @@ describe('Logarithmic Scale tests', function() { var yScale = chart.scales.yScale; expect(yScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(32); // top + paddingTop - expect(yScale.getPixelForValue( 1, 0, 0)).toBeCloseToPixel(456); // bottom - paddingBottom + expect(yScale.getPixelForValue(1, 0, 0)).toBeCloseToPixel(456); // bottom - paddingBottom expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(234); // halfway - expect(yScale.getPixelForValue( 0, 0, 0)).toBeCloseToPixel(32); // 0 is invalid. force it on top + expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(32); // 0 is invalid. force it on top expect(yScale.getValueForPixel(32)).toBeCloseTo(80, 1e-4); expect(yScale.getValueForPixel(456)).toBeCloseTo(1, 1e-4); diff --git a/test/scale.radialLinear.tests.js b/test/scale.radialLinear.tests.js index dea9b1b0354..a47214f4fff 100644 --- a/test/scale.radialLinear.tests.js +++ b/test/scale.radialLinear.tests.js @@ -11,13 +11,13 @@ describe('Test the radial linear scale', function() { expect(defaultConfig).toEqual({ angleLines: { display: true, - color: "rgba(0, 0, 0, 0.1)", + color: 'rgba(0, 0, 0, 0.1)', lineWidth: 1 }, animate: true, display: true, gridLines: { - color: "rgba(0, 0, 0, 0.1)", + color: 'rgba(0, 0, 0, 0.1)', drawBorder: true, drawOnChartArea: true, drawTicks: true, @@ -25,7 +25,7 @@ describe('Test the radial linear scale', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: "rgba(0,0,0,0.25)", + zeroLineColor: 'rgba(0,0,0,0.25)', zeroLineWidth: 1, borderDash: [], borderDashOffset: 0.0 @@ -35,13 +35,13 @@ describe('Test the radial linear scale', function() { fontSize: 10, callback: defaultConfig.pointLabels.callback, // make this nicer, then check explicitly below }, - position: "chartArea", + position: 'chartArea', scaleLabel: { labelString: '', display: false, }, ticks: { - backdropColor: "rgba(255,255,255,0.75)", + backdropColor: 'rgba(255,255,255,0.75)', backdropPaddingY: 2, backdropPaddingX: 2, beginAtZero: false, @@ -426,19 +426,19 @@ describe('Test the radial linear scale', function() { var radToNearestDegree = function(rad) { return Math.round((360 * rad) / (2 * Math.PI)); - } + }; var slice = 72; // (360 / 5) - for(var i = 0; i < 5; i++) { + for (var i = 0; i < 5; i++) { expect(radToNearestDegree(chart.scale.getIndexAngle(i))).toBe(15 + (slice * i) - 90); } chart.options.startAngle = 0; chart.update(); - for(var i = 0; i < 5; i++) { - expect(radToNearestDegree(chart.scale.getIndexAngle(i))).toBe((slice * i) - 90); + for (var x = 0; x < 5; x++) { + expect(radToNearestDegree(chart.scale.getIndexAngle(x))).toBe((slice * x) - 90); } }); }); diff --git a/test/scale.time.tests.js b/test/scale.time.tests.js index 5179191bafa..896ff00d4f7 100755 --- a/test/scale.time.tests.js +++ b/test/scale.time.tests.js @@ -15,7 +15,7 @@ describe('Time scale tests', function() { pass: result }; } - } + }; } }); }); @@ -35,7 +35,7 @@ describe('Time scale tests', function() { expect(defaultConfig).toEqual({ display: true, gridLines: { - color: "rgba(0, 0, 0, 0.1)", + color: 'rgba(0, 0, 0, 0.1)', drawBorder: true, drawOnChartArea: true, drawTicks: true, @@ -43,12 +43,12 @@ describe('Time scale tests', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: "rgba(0,0,0,0.25)", + zeroLineColor: 'rgba(0,0,0,0.25)', zeroLineWidth: 1, borderDash: [], borderDashOffset: 0.0 }, - position: "bottom", + position: 'bottom', scaleLabel: { labelString: '', display: false @@ -75,15 +75,15 @@ describe('Time scale tests', function() { displayFormat: false, minUnit: 'millisecond', displayFormats: { - 'millisecond': 'h:mm:ss.SSS a', // 11:20:01.123 AM - 'second': 'h:mm:ss a', // 11:20:01 AM - 'minute': 'h:mm:ss a', // 11:20:01 AM - 'hour': 'MMM D, hA', // Sept 4, 5PM - 'day': 'll', // Sep 4 2015 - 'week': 'll', // Week 46, or maybe "[W]WW - YYYY" ? - 'month': 'MMM YYYY', // Sept 2015 - 'quarter': '[Q]Q - YYYY', // Q3 - 'year': 'YYYY' // 2015 + millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM + second: 'h:mm:ss a', // 11:20:01 AM + minute: 'h:mm:ss a', // 11:20:01 AM + hour: 'MMM D, hA', // Sept 4, 5PM + day: 'll', // Sep 4 2015 + week: 'll', // Week 46, or maybe "[W]WW - YYYY" ? + month: 'MMM YYYY', // Sept 2015 + quarter: '[Q]Q - YYYY', // Q3 + year: 'YYYY' // 2015 } } }); @@ -96,7 +96,7 @@ describe('Time scale tests', function() { var scaleID = 'myScale'; var mockData = { - labels: ["2015-01-01T20:00:00", "2015-01-02T21:00:00", "2015-01-03T22:00:00", "2015-01-05T23:00:00", "2015-01-07T03:00", "2015-01-08T10:00", "2015-01-10T12:00"], // days + labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00', '2015-01-03T22:00:00', '2015-01-05T23:00:00', '2015-01-07T03:00', '2015-01-08T10:00', '2015-01-10T12:00'], // days }; var mockContext = window.createMockContext(); @@ -110,11 +110,11 @@ describe('Time scale tests', function() { id: scaleID }); - //scale.buildTicks(); + // scale.buildTicks(); scale.update(400, 50); // Counts down because the lines are drawn top to bottom - expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015' ]); + expect(scale.ticks).toEqual(['Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015']); }); it('should build ticks using date objects', function() { @@ -142,7 +142,7 @@ describe('Time scale tests', function() { scale.update(400, 50); // Counts down because the lines are drawn top to bottom - expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015' ]); + expect(scale.ticks).toEqual(['Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015']); }); it('should build ticks when the data is xy points', function() { @@ -198,7 +198,7 @@ describe('Time scale tests', function() { // Counts down because the lines are drawn top to bottom var xScale = chart.scales.xScale0; - expect(xScale.ticks).toEqual([ 'Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015', 'Jan 7, 2015', 'Jan 9, 2015', 'Jan 11, 2015' ]); + expect(xScale.ticks).toEqual(['Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015', 'Jan 7, 2015', 'Jan 9, 2015', 'Jan 11, 2015']); }); it('should allow custom time parsers', function() { @@ -223,7 +223,7 @@ describe('Time scale tests', function() { time: { unit: 'day', round: true, - parser: function customTimeParser(label) { + parser: function(label) { return moment.unix(label); } } @@ -248,7 +248,7 @@ describe('Time scale tests', function() { var scaleID = 'myScale'; var mockData = { - labels: ["2015-01-01T20:00:00", "2015-01-02T21:00:00"], // days + labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00'], // days }; var mockContext = window.createMockContext(); @@ -264,7 +264,7 @@ describe('Time scale tests', function() { id: scaleID }); - //scale.buildTicks(); + // scale.buildTicks(); scale.update(400, 50); 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']); }); @@ -273,7 +273,7 @@ describe('Time scale tests', function() { var scaleID = 'myScale'; var mockData = { - labels: ["2015-01-01T20:00:00", "2015-01-02T21:00:00"], // days + labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00'], // days }; var mockContext = window.createMockContext(); @@ -289,7 +289,7 @@ describe('Time scale tests', function() { id: scaleID }); - //scale.buildTicks(); + // scale.buildTicks(); scale.update(400, 50); expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 2, 2015', 'Jan 3, 2015']); }); @@ -298,7 +298,7 @@ describe('Time scale tests', function() { var scaleID = 'myScale'; var mockData = { - labels: ["2015-01-01T20:00:00", "2015-02-02T21:00:00", "2015-02-21T01:00:00"], // days + labels: ['2015-01-01T20:00:00', '2015-02-02T21:00:00', '2015-02-21T01:00:00'], // days }; var mockContext = window.createMockContext(); @@ -315,7 +315,7 @@ describe('Time scale tests', function() { id: scaleID }); - //scale.buildTicks(); + // scale.buildTicks(); scale.update(400, 50); // last date is feb 15 because we round to start of week @@ -326,13 +326,13 @@ describe('Time scale tests', function() { var scaleID = 'myScale'; var mockData = { - labels: ["2015-01-01T20:00:00", "2015-01-02T20:00:00", "2015-01-03T20:00:00"], // days + labels: ['2015-01-01T20:00:00', '2015-01-02T20:00:00', '2015-01-03T20:00:00'], // days }; var mockContext = window.createMockContext(); var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('time')); - config.time.min = "2015-01-01T04:00:00"; - config.time.max = "2015-01-05T06:00:00" + config.time.min = '2015-01-01T04:00:00'; + config.time.max = '2015-01-05T06:00:00'; var Constructor = Chart.scaleService.getScaleConstructor('time'); var scale = new Constructor({ ctx: mockContext, @@ -344,7 +344,7 @@ describe('Time scale tests', function() { }); scale.update(400, 50); - expect(scale.ticks).toEqual([ 'Jan 1, 2015', 'Jan 5, 2015' ]); + expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 5, 2015']); }); it('Should use the isoWeekday option', function() { @@ -352,9 +352,9 @@ describe('Time scale tests', function() { var mockData = { labels: [ - "2015-01-01T20:00:00", // Thursday - "2015-01-02T20:00:00", // Friday - "2015-01-03T20:00:00" // Saturday + '2015-01-01T20:00:00', // Thursday + '2015-01-02T20:00:00', // Friday + '2015-01-03T20:00:00' // Saturday ] }; @@ -374,7 +374,7 @@ describe('Time scale tests', function() { }); scale.update(400, 50); - expect(scale.ticks).toEqual([ 'Dec 31, 2014', 'Jan 7, 2015' ]); + expect(scale.ticks).toEqual(['Dec 31, 2014', 'Jan 7, 2015']); }); it('should get the correct pixel for a value', function() { @@ -386,7 +386,7 @@ describe('Time scale tests', function() { yAxisID: 'yScale0', data: [] }], - labels: ["2015-01-01T20:00:00", "2015-01-02T21:00:00", "2015-01-03T22:00:00", "2015-01-05T23:00:00", "2015-01-07T03:00", "2015-01-08T10:00", "2015-01-10T12:00"], // days + labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00', '2015-01-03T22:00:00', '2015-01-05T23:00:00', '2015-01-07T03:00', '2015-01-08T10:00', '2015-01-10T12:00'], // days }, options: { scales: { @@ -430,7 +430,7 @@ describe('Time scale tests', function() { yAxisID: 'yScale0', data: [] }], - labels: ["2015-01-01T20:00:00", "2015-01-02T21:00:00", "2015-01-03T22:00:00", "2015-01-05T23:00:00", "2015-01-07T03:00", "2015-01-08T10:00", "2015-01-10T12:00"], // days + labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00', '2015-01-03T22:00:00', '2015-01-05T23:00:00', '2015-01-07T03:00', '2015-01-08T10:00', '2015-01-10T12:00'], // days }, options: { scales: { @@ -457,7 +457,7 @@ describe('Time scale tests', function() { var chart = window.acquireChart({ type: 'line', data: { - labels: ["2016-05-27"], + labels: ['2016-05-27'], datasets: [{ xAxisID: 'xScale0', data: [5] @@ -468,7 +468,7 @@ describe('Time scale tests', function() { xAxes: [{ id: 'xScale0', display: true, - type: "time" + type: 'time' }] } } @@ -485,11 +485,11 @@ describe('Time scale tests', function() { }); }); - it("should not throw an error if the datasetIndex is out of bounds", function() { + it('should not throw an error if the datasetIndex is out of bounds', function() { var chart = window.acquireChart({ type: 'line', data: { - labels: ["2016-06-26"], + labels: ['2016-06-26'], datasets: [{ xAxisID: 'xScale0', data: [5] @@ -500,7 +500,7 @@ describe('Time scale tests', function() { xAxes: [{ id: 'xScale0', display: true, - type: "time", + type: 'time', }] } } @@ -514,11 +514,11 @@ describe('Time scale tests', function() { expect(getOutOfBoundLabelMoment).not.toThrow(); }); - it("should not throw an error if the datasetIndex or index are null", function() { + it('should not throw an error if the datasetIndex or index are null', function() { var chart = window.acquireChart({ type: 'line', data: { - labels: ["2016-06-26"], + labels: ['2016-06-26'], datasets: [{ xAxisID: 'xScale0', data: [5] @@ -529,7 +529,7 @@ describe('Time scale tests', function() { xAxes: [{ id: 'xScale0', display: true, - type: "time", + type: 'time', }] } }