From e1a39c873e5ebc421819f5da3090893d53e7847b Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 14 Feb 2015 22:53:13 +0900 Subject: [PATCH] Fix specs --- .jshintrc | 2 ++ spec/api.data-spec.js | 4 +-- spec/api.focus-spec.js | 4 +-- spec/api.grid-spec.js | 23 ++++++++-------- spec/api.load-spec.js | 25 +++++++++--------- spec/api.zoom-spec.js | 43 +++++++++++++----------------- spec/axis-spec.js | 57 ++++++++++++++++++++++------------------ spec/c3-spec.js | 2 -- spec/class-spec.js | 4 +-- spec/core-spec.js | 4 +-- spec/data-spec.js | 4 +-- spec/domain-spec.js | 4 +-- spec/grid-spec.js | 45 +++++++++++++++---------------- spec/interaction-spec.js | 14 +--------- spec/legend-spec.js | 53 ++++++++++++++++++------------------- spec/shape.bar-spec.js | 35 ++++++++++++------------ spec/shape.line-spec.js | 29 ++++++++++---------- spec/tooltip-spec.js | 6 +---- spec/type-spec.js | 29 ++++++++++---------- spec/zoom-spec.js | 4 +-- 20 files changed, 182 insertions(+), 209 deletions(-) diff --git a/.jshintrc b/.jshintrc index d2a6541..9b4294c 100644 --- a/.jshintrc +++ b/.jshintrc @@ -19,8 +19,10 @@ "browser": true, "globals": { + "jasmine": false, "describe": false, "beforeEach": false, + "beforeAll": false, "it": false, "expect": false, "d3": false diff --git a/spec/api.data-spec.js b/spec/api.data-spec.js index ba26e6a..60881cb 100644 --- a/spec/api.data-spec.js +++ b/spec/api.data-spec.js @@ -1,8 +1,7 @@ - describe('c3 api data', function () { 'use strict'; - var chart, d3; + var chart; var args = { data: { @@ -32,7 +31,6 @@ describe('c3 api data', function () { beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('data()', function () { diff --git a/spec/api.focus-spec.js b/spec/api.focus-spec.js index b48a8c4..0f5fa0e 100644 --- a/spec/api.focus-spec.js +++ b/spec/api.focus-spec.js @@ -1,8 +1,7 @@ - describe('c3 api focus', function () { 'use strict'; - var chart, d3; + var chart; var args = { data: { @@ -16,7 +15,6 @@ describe('c3 api focus', function () { beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('focus', function () { diff --git a/spec/api.grid-spec.js b/spec/api.grid-spec.js index 70938e1..ebaeee6 100644 --- a/spec/api.grid-spec.js +++ b/spec/api.grid-spec.js @@ -1,24 +1,25 @@ - describe('c3 api grid', function () { 'use strict'; - var chart, d3; - - var args = { - data: { - columns: [ - ['data1', 30, 200, 100, 400, 150, 250] - ] - } - }; + var chart, args; beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('ygrid.add and ygrid.remove', function () { + it('should update args', function () { + args = { + data: { + columns: [ + ['data1', 30, 200, 100, 400, 150, 250] + ] + } + }; + expect(true).toBeTruthy(); + }); + it('should update y grids', function (done) { var main = chart.internal.main, expectedGrids = [ diff --git a/spec/api.load-spec.js b/spec/api.load-spec.js index 251c3a6..fbea981 100644 --- a/spec/api.load-spec.js +++ b/spec/api.load-spec.js @@ -1,27 +1,28 @@ - describe('c3 api load', function () { 'use strict'; - var chart, d3; - - var args = { - data: { - columns: [ - ['data1', 30, 200, 100, 400, 150, 250], - ['data2', 5000, 2000, 1000, 4000, 1500, 2500] - ] - } - }; + var chart, args; beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('indexed data', function () { describe('as column', function () { + it('should update args', function () { + args = { + data: { + columns: [ + ['data1', 30, 200, 100, 400, 150, 250], + ['data2', 5000, 2000, 1000, 4000, 1500, 2500] + ] + } + }; + expect(true).toBeTruthy(); + }); + it('should load additional data', function (done) { var main = chart.internal.main, legend = chart.internal.legend; diff --git a/spec/api.zoom-spec.js b/spec/api.zoom-spec.js index a315acc..4a65927 100644 --- a/spec/api.zoom-spec.js +++ b/spec/api.zoom-spec.js @@ -1,37 +1,30 @@ - describe('c3 api zoom', function () { 'use strict'; - var chart, d3; - - var args = { - data: { - columns: [ - ['data1', 30, 200, 100, 400, 150, 250], - ['data2', 50, 20, 10, 40, 15, 25], - ['data3', 150, 120, 110, 140, 115, 125] - ] - }, - zoom: { - enabled: true - } - }; + var chart, args; beforeEach(function (done) { - if (typeof chart === 'undefined') { - window.initDom(); - } - chart = window.c3.generate(args); - d3 = chart.internal.d3; -// chart.internal.d3.select('.jasmine_html-reporter').style('display', 'none'); - - window.setTimeout(function () { - done(); - }, 10); + chart = window.initChart(chart, args, done); }); describe('zoom', function () { + it('should update args', function () { + args = { + data: { + columns: [ + ['data1', 30, 200, 100, 400, 150, 250], + ['data2', 50, 20, 10, 40, 15, 25], + ['data3', 150, 120, 110, 140, 115, 125] + ] + }, + zoom: { + enabled: true + } + }; + expect(true).toBeTruthy(); + }); + it('should be zoomed properly', function () { var target = [3, 5], domain; chart.zoom(target); diff --git a/spec/axis-spec.js b/spec/axis-spec.js index f28fe69..86e7639 100644 --- a/spec/axis-spec.js +++ b/spec/axis-spec.js @@ -1,8 +1,7 @@ - describe('c3 chart axis', function () { 'use strict'; - var chart, d3; + var chart; var args = { data: { @@ -30,16 +29,13 @@ describe('c3 chart axis', function () { beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('axis.y.tick.count', function () { - var i = 1; - - beforeEach(function () { - args.axis.y.tick.count = i++; - chart = window.c3.generate(args); + it('should update args to have only 1 tick on y axis', function () { + args.axis.y.tick.count = 1; + expect(true).toBeTruthy(); }); it('should have only 1 tick on y axis', function () { @@ -47,11 +43,21 @@ describe('c3 chart axis', function () { expect(ticksSize).toBe(1); }); + it('should update args to have 2 ticks on y axis', function () { + args.axis.y.tick.count = 2; + expect(true).toBeTruthy(); + }); + it('should have 2 ticks on y axis', function () { var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size(); expect(ticksSize).toBe(2); }); + it('should update args to have 3 ticks on y axis', function () { + args.axis.y.tick.count = 3; + expect(true).toBeTruthy(); + }); + it('should have 3 ticks on y axis', function () { var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size(); expect(ticksSize).toBe(3); @@ -63,9 +69,9 @@ describe('c3 chart axis', function () { var values = [100, 500]; - beforeEach(function () { + it('should update args to have only 2 ticks on y axis', function () { args.axis.y.tick.values = values; - chart = window.c3.generate(args); + expect(true).toBeTruthy(); }); it('should have only 2 tick on y axis', function () { @@ -84,25 +90,24 @@ describe('c3 chart axis', function () { describe('axis y timeseries', function () { - var args = { - data: { - columns: [ - ["times", 60000, 120000, 180000, 240000] - ] - }, - axis: { - y: { - type : 'timeseries', - tick: { - time: { + it('should update args', function () { + args = { + data: { + columns: [ + ["times", 60000, 120000, 180000, 240000] + ] + }, + axis: { + y: { + type : 'timeseries', + tick: { + time: { + } } } } - } - }; - - beforeEach(function () { - chart = window.c3.generate(args); + }; + expect(true).toBeTruthy(); }); it('should have 7 ticks on y axis', function () { diff --git a/spec/c3-spec.js b/spec/c3-spec.js index 2567c7e..7be30b3 100644 --- a/spec/c3-spec.js +++ b/spec/c3-spec.js @@ -1,4 +1,3 @@ - describe('c3', function () { 'use strict'; @@ -9,4 +8,3 @@ describe('c3', function () { expect(typeof c3).toBe('object'); }); }); - diff --git a/spec/class-spec.js b/spec/class-spec.js index d53e17b..97d0e69 100644 --- a/spec/class-spec.js +++ b/spec/class-spec.js @@ -1,8 +1,7 @@ - describe('c3 chart class', function () { 'use strict'; - var chart, d3; + var chart; var args = { data: { @@ -16,7 +15,6 @@ describe('c3 chart class', function () { beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('internal.getTargetSelectorSuffix', function () { diff --git a/spec/core-spec.js b/spec/core-spec.js index 3a34906..048df38 100644 --- a/spec/core-spec.js +++ b/spec/core-spec.js @@ -1,8 +1,7 @@ - describe('c3 chart', function () { 'use strict'; - var chart, d3; + var chart; var args = { data: { @@ -16,7 +15,6 @@ describe('c3 chart', function () { beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('init', function () { diff --git a/spec/data-spec.js b/spec/data-spec.js index 4dca964..2c1ea4d 100644 --- a/spec/data-spec.js +++ b/spec/data-spec.js @@ -1,8 +1,7 @@ - describe('c3 chart data', function () { 'use strict'; - var chart, d3; + var chart; var args = { data: { @@ -19,7 +18,6 @@ describe('c3 chart data', function () { beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('function in data.order', function () { diff --git a/spec/domain-spec.js b/spec/domain-spec.js index 56ebd78..69f7995 100644 --- a/spec/domain-spec.js +++ b/spec/domain-spec.js @@ -1,8 +1,7 @@ - describe('c3 chart domain', function () { 'use strict'; - var chart, d3; + var chart; var args = { data: { @@ -19,7 +18,6 @@ describe('c3 chart domain', function () { beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('axis.y.min', function () { diff --git a/spec/grid-spec.js b/spec/grid-spec.js index 046b1e1..4f81f75 100644 --- a/spec/grid-spec.js +++ b/spec/grid-spec.js @@ -1,35 +1,36 @@ - describe('c3 chart grid', function () { 'use strict'; - var chart, d3; - - var args = { - data: { - columns: [ - ['data1', 30, 200, 100, 400, 150, 250] - ] - }, - axis: { - y: { - tick: { - } - } - }, - grid: { - y: { - show: false - } - } - }; + var chart, args; beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('y grid', function () { + it('should update args', function () { + args = { + data: { + columns: [ + ['data1', 30, 200, 100, 400, 150, 250] + ] + }, + axis: { + y: { + tick: { + } + } + }, + grid: { + y: { + show: false + } + } + }; + expect(true).toBeTruthy(); + }); + it('should not show y grids', function () { expect(chart.internal.main.select('.c3-ygrids').size()).toBe(0); }); diff --git a/spec/interaction-spec.js b/spec/interaction-spec.js index a5c07f1..4e62070 100644 --- a/spec/interaction-spec.js +++ b/spec/interaction-spec.js @@ -1,22 +1,10 @@ - describe('c3 chart interaction', function () { 'use strict'; - var chart, d3; - - var args = { - data: { - columns: [ - ['data1', 30, 200, 100, 400, 150, 250], - ['data2', 50, 20, 10, 40, 15, 25], - ['data3', 150, 120, 110, 140, 115, 125] - ] - } - }; + var chart, args; beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('generate event rects', function () { diff --git a/spec/legend-spec.js b/spec/legend-spec.js index 6272e42..1c77dbd 100644 --- a/spec/legend-spec.js +++ b/spec/legend-spec.js @@ -1,35 +1,26 @@ - describe('c3 chart legend', function () { 'use strict'; - var chart, d3; - - var args = { - data: { - columns: [ - ['data1', 30, 200, 100, 400, 150, 250], - ['data2', 50, 20, 10, 40, 15, 25] - ] - } - }; + var chart, args; beforeEach(function (done) { - if (typeof chart === 'undefined') { - window.initDom(); - } - chart = window.c3.generate(args); - d3 = chart.internal.d3; - chart.internal.d3.select('.jasmine_html-reporter') - .style('position', 'absolute') - .style('right', 0); - - window.setTimeout(function () { - done(); - }, 10); + chart = window.initChart(chart, args, done); }); describe('legend position', function () { + it('should update args', function () { + args = { + data: { + columns: [ + ['data1', 30, 200, 100, 400, 150, 250], + ['data2', 50, 20, 10, 40, 15, 25] + ] + } + }; + expect(true).toBeTruthy(); + }); + it('should be located on the center of chart', function () { var box = chart.internal.legend.node().getBoundingClientRect(); expect(box.left + box.right).toBe(640); @@ -40,10 +31,18 @@ describe('c3 chart legend', function () { describe('legend as inset', function () { it('should change the legend to "inset" successfully', function () { - args.legend = { - position: 'inset', - inset: { - step: null + args = { + data: { + columns: [ + ['data1', 30, 200, 100, 400, 150, 250], + ['data2', 50, 20, 10, 40, 15, 25] + ] + }, + legend: { + position: 'inset', + inset: { + step: null + } } }; expect(true).toBeTruthy(); diff --git a/spec/shape.bar-spec.js b/spec/shape.bar-spec.js index 9f15328..78f2971 100644 --- a/spec/shape.bar-spec.js +++ b/spec/shape.bar-spec.js @@ -1,34 +1,35 @@ - var setMouseEvent = window.setMouseEvent; describe('c3 chart shape bar', function () { 'use strict'; - var chart, d3; - - var args = { - data: { - columns: [ - ['data1', 30, 200, 100, 400, -150, 250], - ['data2', 50, 20, 10, 40, 15, 25], - ['data3', -150, 120, 110, 140, 115, 125] - ], - type: 'bar' - }, - axis: { - rotated: false - } - }; + var chart, args; beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('internal.isWithinBar', function () { describe('with normal axis', function () { + it('should update args', function () { + args = { + data: { + columns: [ + ['data1', 30, 200, 100, 400, -150, 250], + ['data2', 50, 20, 10, 40, 15, 25], + ['data3', -150, 120, 110, 140, 115, 125] + ], + type: 'bar' + }, + axis: { + rotated: false + } + }; + expect(true).toBeTruthy(); + }); + it('should not be within bar', function () { var bar = d3.select('.c3-target-data1 .c3-bar-0').node(); setMouseEvent(chart, 'click', 0, 0); diff --git a/spec/shape.line-spec.js b/spec/shape.line-spec.js index 65f6282..b4f5dc8 100644 --- a/spec/shape.line-spec.js +++ b/spec/shape.line-spec.js @@ -1,27 +1,28 @@ - describe('c3 chart shape line', function () { 'use strict'; - var chart, d3; - - var args = { - data: { - columns: [ - ['data1', 30, 200, 100, 400, -150, 250], - ['data2', 50, 20, 10, 40, 15, 25], - ['data3', -150, 120, 110, 140, 115, 125] - ], - type: 'line' - } - }; + var chart, args; beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('shape-rendering for line chart', function () { + it('should update args', function () { + args = { + data: { + columns: [ + ['data1', 30, 200, 100, 400, -150, 250], + ['data2', 50, 20, 10, 40, 15, 25], + ['data3', -150, 120, 110, 140, 115, 125] + ], + type: 'line' + } + }; + expect(true).toBeTruthy(); + }); + it("should not have shape-rendering when it's line chart", function () { d3.selectAll('.c3-line').each(function () { var style = d3.select(this).style('shape-rendering'); diff --git a/spec/tooltip-spec.js b/spec/tooltip-spec.js index 838496e..de3983f 100644 --- a/spec/tooltip-spec.js +++ b/spec/tooltip-spec.js @@ -1,10 +1,7 @@ -var jasmine = window.jasmine, - beforeAll = window.beforeAll; - describe('c3 chart tooltip', function () { 'use strict'; - var chart, d3; + var chart; var tooltipConfiguration; var args = function () { @@ -22,7 +19,6 @@ describe('c3 chart tooltip', function () { beforeEach(function (done) { chart = window.initChart(chart, args(), done); - d3 = chart.internal.d3; }); describe('tooltip position', function () { diff --git a/spec/type-spec.js b/spec/type-spec.js index c49a916..9210d50 100644 --- a/spec/type-spec.js +++ b/spec/type-spec.js @@ -1,29 +1,30 @@ - describe('c3 chart types', function () { 'use strict'; - var chart, d3; - - var args = { - data: { - columns: [ - ['data1', 30, 200, 100, 400, 150, 250], - ['data2', 50, 20, 10, 40, 15, 25], - ['data3', 150, 120, 110, 140, 115, 125] - ], - type: 'pie' - } - }; + var chart, args; beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('internal.hasArcType', function () { describe('with data', function () { + it('should update args', function () { + args = { + data: { + columns: [ + ['data1', 30, 200, 100, 400, 150, 250], + ['data2', 50, 20, 10, 40, 15, 25], + ['data3', 150, 120, 110, 140, 115, 125] + ], + type: 'pie' + } + }; + expect(true).toBeTruthy(); + }); + it('should return true', function () { expect(chart.internal.hasArcType()).toBeTruthy(); }); diff --git a/spec/zoom-spec.js b/spec/zoom-spec.js index 121add3..7f1490b 100644 --- a/spec/zoom-spec.js +++ b/spec/zoom-spec.js @@ -1,8 +1,7 @@ - describe('c3 chart zoom', function () { 'use strict'; - var chart, d3; + var chart; var args = { data: { @@ -26,7 +25,6 @@ describe('c3 chart zoom', function () { beforeEach(function (done) { chart = window.initChart(chart, args, done); - d3 = chart.internal.d3; }); describe('default extent', function () {