Browse Source

Fixes some test failures. Adds new jshint reporter.

This is a combination of 3 commits.
Doing build

Adding jshint stylish as reporter, fixing a few tests.

Linting spec files.
pull/1671/merge
Ændrew Rininsland 9 years ago
parent
commit
99e6f7cc89
  1. 1
      Gruntfile.coffee
  2. 3
      package.json
  3. 53
      spec/api.data-spec.js
  4. 4
      spec/arc-spec.js
  5. 8
      spec/shape.line-spec.js
  6. 10
      spec/svg-helper.js

1
Gruntfile.coffee

@ -83,6 +83,7 @@ module.exports = (grunt) ->
c3: 'c3.js' c3: 'c3.js'
spec: 'spec/*.js' spec: 'spec/*.js'
options: options:
reporter: require('jshint-stylish')
jshintrc: '.jshintrc' jshintrc: '.jshintrc'
karma: karma:

3
package.json

@ -29,12 +29,13 @@
"grunt": "^0.4.5", "grunt": "^0.4.5",
"grunt-contrib-concat": "~0.5.0", "grunt-contrib-concat": "~0.5.0",
"grunt-contrib-cssmin": "^0.10.0", "grunt-contrib-cssmin": "^0.10.0",
"grunt-contrib-jshint": "~0.10.0", "grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-uglify": "~0.4.0", "grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-watch": "^0.6.1", "grunt-contrib-watch": "^0.6.1",
"grunt-karma": "^0.12.1", "grunt-karma": "^0.12.1",
"grunt-sass": "^1.0.0", "grunt-sass": "^1.0.0",
"jasmine-core": "^2.3.4", "jasmine-core": "^2.3.4",
"jshint-stylish": "^2.1.0",
"karma": "^0.13.10", "karma": "^0.13.10",
"karma-coverage": "^0.5.2", "karma-coverage": "^0.5.2",
"karma-jasmine": "^0.3.6", "karma-jasmine": "^0.3.6",

53
spec/api.data-spec.js

@ -30,6 +30,7 @@ describe('c3 api data', function () {
}; };
beforeEach(function (done) { beforeEach(function (done) {
jasmine.addMatchers(customMatchers);
chart = window.initChart(chart, args, done); chart = window.initChart(chart, args, done);
}); });
@ -116,8 +117,8 @@ describe('c3 api data', function () {
it('should return data.colors specified as argument', function () { it('should return data.colors specified as argument', function () {
var results = chart.data.colors(); var results = chart.data.colors();
expect(results.data1).toBe('#FF0000'); expect(results.data1).toBeHexOrRGB('#FF0000');
expect(results.data2).toBe('#00FF00'); expect(results.data2).toBeHexOrRGB('#00FF00');
}); });
it('should return data.colors specified as api', function () { it('should return data.colors specified as api', function () {
@ -125,15 +126,15 @@ describe('c3 api data', function () {
data1: '#00FF00', data1: '#00FF00',
data2: '#FF0000' data2: '#FF0000'
}); });
expect(results.data1).toBe('#00FF00'); expect(results.data1).toBeHexOrRGB('#00FF00');
expect(results.data2).toBe('#FF0000'); expect(results.data2).toBeHexOrRGB('#FF0000');
}); });
it('should set data.colors specified as api', function () { it('should set data.colors specified as api', function () {
expect(d3.select('.c3-line-data1').style('stroke')).toBe("#00ff00"); expect(d3.select('.c3-line-data1').style('stroke')).toBeHexOrRGB("#00ff00");
expect(d3.select('.c3-line-data2').style('stroke')).toBe("#ff0000"); expect(d3.select('.c3-line-data2').style('stroke')).toBeHexOrRGB("#ff0000");
expect(d3.select('.c3-legend-item-data1 .c3-legend-item-tile').style('stroke')).toBe("#00ff00"); expect(d3.select('.c3-legend-item-data1 .c3-legend-item-tile').style('stroke')).toBeHexOrRGB("#00ff00");
expect(d3.select('.c3-legend-item-data2 .c3-legend-item-tile').style('stroke')).toBe("#ff0000"); expect(d3.select('.c3-legend-item-data2 .c3-legend-item-tile').style('stroke')).toBeHexOrRGB("#ff0000");
}); });
}); });
@ -162,3 +163,39 @@ describe('c3 api data', function () {
}); });
}); });
var customMatchers = {
toBeHexOrRGB: function(util, customEqualityTesters) {
'use strict';
function rgb2hex(rgb){
rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
return (rgb && rgb.length === 4) ? "#" +
("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : '';
}
return {
compare: function(actual, expected){
if (expected === undefined) {
expected = '';
}
var result = {};
actual = actual.match('rgb') ? rgb2hex(actual) : actual;
expected = expected.match('rgb') ? rgb2hex(expected) : expected;
result.pass = util.equals(actual, expected, customEqualityTesters);
if (result.pass) {
result.message = "Expected " + actual + " not to be quite so goofy";
} else {
result.message = "Expected " + actual + " to be goofy, but it was not very goofy";
}
return result;
}
};
}
};

4
spec/arc-spec.js

@ -122,7 +122,7 @@ describe('c3 chart arc', function () {
.select('g.c3-shapes.c3-shapes-data.c3-arcs.c3-arcs-data') .select('g.c3-shapes.c3-shapes-data.c3-arcs.c3-arcs-data')
.select('path.c3-shape.c3-shape.c3-arc.c3-arc-data'); .select('path.c3-shape.c3-shape.c3-arc.c3-arc-data');
expect(data.attr('d')).toMatch('M-304,-3.7229262694079536e-14A304,304 0 0,1 245.94116628998404,-178.68671669691184L237.85099634623455,-172.8088641739871A294,294 0 0,0 -294,-3.6004615894932184e-14Z'); expect(data.attr('d')).toMatch('M-304,-3.7229262694079536e-14A304,304 0 0,1 245.94116628998404,-178.68671669691184L237.85099634623455,-172.8088641739871A294,294 0 0,0 -294,-3.6004615894932184e-14Z'); //jshint ignore:line
}); });
it('should update args to have a 2 Pi radian gauge that starts at Pi/2', function() { it('should update args to have a 2 Pi radian gauge that starts at Pi/2', function() {
@ -151,7 +151,7 @@ describe('c3 chart arc', function () {
.select('g.c3-shapes.c3-shapes-data.c3-arcs.c3-arcs-data') .select('g.c3-shapes.c3-shapes-data.c3-arcs.c3-arcs-data')
.select('path.c3-shape.c3-shape.c3-arc.c3-arc-data'); .select('path.c3-shape.c3-shape.c3-arc.c3-arc-data');
expect(data.attr('d')).toMatch('M-304,-3.7229262694079536e-14A304,304 0 0,1 245.94116628998404,-178.68671669691184L237.85099634623455,-172.8088641739871A294,294 0 0,0 -294,-3.6004615894932184e-14Z'); expect(data.attr('d')).toMatch('M-304,-3.7229262694079536e-14A304,304 0 0,1 245.94116628998404,-178.68671669691184L237.85099634623455,-172.8088641739871A294,294 0 0,0 -294,-3.6004615894932184e-14Z'); //jshint ignore:line
}); });
}); });

8
spec/shape.line-spec.js

@ -1,14 +1,14 @@
describe('c3 chart shape line', function () { describe('c3 chart shape line', function () {
'use strict'; 'use strict';
var chart, args; var chart, args;
beforeEach(function (done) { beforeEach(function (done) {
chart = window.initChart(chart, args, done); chart = window.initChart(chart, args, done);
}); });
var parseSvgPath = window.parseSvgPath;
describe('shape-rendering for line chart', function () { describe('shape-rendering for line chart', function () {
it('should update args', function () { it('should update args', function () {
@ -49,7 +49,7 @@ describe('c3 chart shape line', function () {
it("should have shape-rendering = crispedges when it's step chart", function () { it("should have shape-rendering = crispedges when it's step chart", function () {
d3.selectAll('.c3-line').each(function () { d3.selectAll('.c3-line').each(function () {
var style = d3.select(this).style('shape-rendering'); var style = d3.select(this).style('shape-rendering').toLowerCase();
expect(style).toBe('crispedges'); expect(style).toBe('crispedges');
}); });
}); });
@ -97,7 +97,7 @@ describe('c3 chart shape line', function () {
var commands = parseSvgPath( target.select('.c3-line-data1').attr('d')); var commands = parseSvgPath( target.select('.c3-line-data1').attr('d'));
var segments = 0; var segments = 0;
for(var i = 0; i < commands.length; i++) { for(var i = 0; i < commands.length; i++) {
(commands[i].command == 'L') ? segments++ : null; (commands[i].command === 'L') ? segments++ : null;
} }
expect(segments).toBe(3); expect(segments).toBe(3);
done(); done();

10
spec/svg-helper.js

@ -1,10 +1,12 @@
/** /**
* Parse the d property of an SVG path into an array of drawing commands. * Parse the d property of an SVG path into an array of drawing commands.
* @param {String} d SvgPath d attribute.] * @param {String} d SvgPath d attribute.]
* @return {Array} an array of drawing commands. * @return {Array} an array of drawing commands.
*/ */
function parseSvgPath(d) {
function parseSvgPath(d) { //jshint ignore:line
'use strict';
var commands = []; var commands = [];
var commandTokens = ['M','L','I','H','V','C','S','Q','T','A']; var commandTokens = ['M','L','I','H','V','C','S','Q','T','A'];
var command; var command;
@ -24,7 +26,7 @@ function parseSvgPath(d) {
in_y = false; in_y = false;
} }
else { else {
if (d[i] == ',') { if (d[i] === ',') {
if (in_y) { if (in_y) {
commands.push({command: command, x: x, y: y}); commands.push({command: command, x: x, y: y});
x = ''; x = '';
@ -41,7 +43,7 @@ function parseSvgPath(d) {
} }
} }
} }
if (d[i] != ',' && in_y) { if (d[i] !== ',' && in_y) {
commands.push({command: command, x: x, y: y}); commands.push({command: command, x: x, y: y});
} }
return commands; return commands;

Loading…
Cancel
Save