Skip to content

Commit

Permalink
Extend eslint to test files (#3473)
Browse files Browse the repository at this point in the history
* Add eslint to test files

* Fix mockContext for tests

* Make formatting look better for nested objects
  • Loading branch information
panzarino authored Oct 16, 2016
1 parent 4a5b5a0 commit 766ca49
Show file tree
Hide file tree
Showing 27 changed files with 518 additions and 443 deletions.
18 changes: 17 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var package = require('./package.json');

var srcDir = './src/';
var outDir = './dist/';
var testDir = './test/';

var header = "/*!\n" +
" * Chart.js\n" +
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
69 changes: 37 additions & 32 deletions test/controller.bar.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ describe('Bar controller tests', function() {
type: 'bar',
data: {
datasets: [
{ data: [] },
{ data: [] }
{data: []},
{data: []}
],
labels: []
}
Expand All @@ -30,8 +30,8 @@ describe('Bar controller tests', function() {
type: 'bar',
data: {
datasets: [
{ data: [] },
{ data: [] }
{data: []},
{data: []}
],
labels: []
},
Expand All @@ -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: []
}
Expand All @@ -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: []
}
Expand All @@ -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: []
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions test/controller.bubble.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 17 additions & 14 deletions test/controller.doughnut.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit 766ca49

Please sign in to comment.