X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fupdate_options.js;h=e5811101cf4d32168c3a389b40a6d4966e753ac0;hb=ce31caf22475e3e1fd6d9fea192d61ff4fcd7fac;hp=faf8f252a287d1ac8a343ad59c60103ae90ff735;hpb=c17e11738cb5603fafcdc84527114502312344c4;p=dygraphs.git diff --git a/auto_tests/tests/update_options.js b/auto_tests/tests/update_options.js index faf8f25..e581110 100644 --- a/auto_tests/tests/update_options.js +++ b/auto_tests/tests/update_options.js @@ -4,65 +4,63 @@ * @fileoverview Tests for the updateOptions function. * @author antrob@google.com (Anthony Robledo) */ -var UpdateOptionsTestCase = TestCase("update-options"); + +import Dygraph from '../../src/dygraph'; + +describe("update-options", function() { + +cleanupAfterEach(); -UpdateOptionsTestCase.prototype.opts = { +var opts = { width: 480, height: 320, }; -UpdateOptionsTestCase.prototype.data = "X,Y1,Y2\n" + +var data = "X,Y1,Y2\n" + "2011-01-01,2,3\n" + "2011-02-02,5,3\n" + "2011-03-03,6,1\n" + "2011-04-04,9,5\n" + "2011-05-05,8,3\n"; -UpdateOptionsTestCase.prototype.setUp = function() { - document.body.innerHTML = "
"; -}; - -UpdateOptionsTestCase.prototype.tearDown = function() { -}; - /* * Tweaks the dygraph so it sets g._testDrawCalled to true when internal method * drawGraph_ is called. Call unWrapDrawGraph when done with this. */ -UpdateOptionsTestCase.prototype.wrapDrawGraph = function(g) { +var wrapDrawGraph = function(g) { g._testDrawCalled = false; g._oldDrawGraph = g.drawGraph_; g.drawGraph_ = function() { g._testDrawCalled = true; g._oldDrawGraph.call(g); } -} +}; /* * See wrapDrawGraph */ -UpdateOptionsTestCase.prototype.unwrapDrawGraph = function(g) { +var unwrapDrawGraph = function(g) { g.drawGraph_ = g._oldDrawGraph; } -UpdateOptionsTestCase.prototype.testStrokeAll = function() { +it('testStrokeAll', function() { var graphDiv = document.getElementById("graph"); - var graph = new Dygraph(graphDiv, this.data, this.opts); + var graph = new Dygraph(graphDiv, data, opts); var updatedOptions = { }; updatedOptions['strokeWidth'] = 3; // These options will allow us to jump to renderGraph_() // drawGraph_() will be skipped. - this.wrapDrawGraph(graph); + wrapDrawGraph(graph); graph.updateOptions(updatedOptions); - this.unwrapDrawGraph(graph); - assertFalse(graph._testDrawCalled); -}; + unwrapDrawGraph(graph); + assert.isFalse(graph._testDrawCalled); +}); -UpdateOptionsTestCase.prototype.testStrokeSingleSeries = function() { +it('testStrokeSingleSeries', function() { var graphDiv = document.getElementById("graph"); - var graph = new Dygraph(graphDiv, this.data, this.opts); + var graph = new Dygraph(graphDiv, data, opts); var updatedOptions = { }; var optionsForY1 = { }; @@ -71,15 +69,15 @@ UpdateOptionsTestCase.prototype.testStrokeSingleSeries = function() { // These options will allow us to jump to renderGraph_() // drawGraph_() will be skipped. - this.wrapDrawGraph(graph); + wrapDrawGraph(graph); graph.updateOptions(updatedOptions); - this.unwrapDrawGraph(graph); - assertFalse(graph._testDrawCalled); -}; + unwrapDrawGraph(graph); + assert.isFalse(graph._testDrawCalled); +}); -UpdateOptionsTestCase.prototype.testSingleSeriesRequiresNewPoints = function() { +it('testSingleSeriesRequiresNewPoints', function() { var graphDiv = document.getElementById("graph"); - var graph = new Dygraph(graphDiv, this.data, this.opts); + var graph = new Dygraph(graphDiv, data, opts); var updatedOptions = { series: { Y1: { @@ -93,15 +91,15 @@ UpdateOptionsTestCase.prototype.testSingleSeriesRequiresNewPoints = function() { // These options will not allow us to jump to renderGraph_() // drawGraph_() must be called - this.wrapDrawGraph(graph); + wrapDrawGraph(graph); graph.updateOptions(updatedOptions); - this.unwrapDrawGraph(graph); - assertTrue(graph._testDrawCalled); -}; + unwrapDrawGraph(graph); + assert.isTrue(graph._testDrawCalled); +}); -UpdateOptionsTestCase.prototype.testWidthChangeNeedsNewPoints = function() { +it('testWidthChangeNeedsNewPoints', function() { var graphDiv = document.getElementById("graph"); - var graph = new Dygraph(graphDiv, this.data, this.opts); + var graph = new Dygraph(graphDiv, data, opts); var updatedOptions = { }; // This will require new points. @@ -109,65 +107,67 @@ UpdateOptionsTestCase.prototype.testWidthChangeNeedsNewPoints = function() { // These options will not allow us to jump to renderGraph_() // drawGraph_() must be called - this.wrapDrawGraph(graph); + wrapDrawGraph(graph); graph.updateOptions(updatedOptions); - this.unwrapDrawGraph(graph); - assertTrue(graph._testDrawCalled); -}; + unwrapDrawGraph(graph); + assert.isTrue(graph._testDrawCalled); +}); // Test https://github.com/danvk/dygraphs/issues/87 -UpdateOptionsTestCase.prototype.testUpdateLabelsDivDoesntInfiniteLoop = function() { +it('testUpdateLabelsDivDoesntInfiniteLoop', function() { var graphDiv = document.getElementById("graph"); var labelsDiv = document.getElementById("labels"); - var graph = new Dygraph(graphDiv, this.data, this.opts); + var graph = new Dygraph(graphDiv, data, opts); graph.updateOptions({labelsDiv : labelsDiv}); -} +}); // Test https://github.com/danvk/dygraphs/issues/247 -UpdateOptionsTestCase.prototype.testUpdateColors = function() { +it('testUpdateColors', function() { var graphDiv = document.getElementById("graph"); - var graph = new Dygraph(graphDiv, this.data, this.opts); + var graph = new Dygraph(graphDiv, data, opts); var defaultColors = ["rgb(0,128,0)", "rgb(0,0,128)"]; - assertEquals(["rgb(0,128,0)", "rgb(0,0,128)"], graph.getColors()); + assert.deepEqual(["rgb(0,128,0)", "rgb(0,0,128)"], graph.getColors()); var colors1 = [ "#aaa", "#bbb" ]; graph.updateOptions({ colors: colors1 }); - assertEquals(colors1, graph.getColors()); + assert.deepEqual(colors1, graph.getColors()); // extra colors are ignored until you add additional data series. var colors2 = [ "#ddd", "#eee", "#fff" ]; graph.updateOptions({ colors: colors2 }); - assertEquals(["#ddd", "#eee"], graph.getColors()); + assert.deepEqual(["#ddd", "#eee"], graph.getColors()); graph.updateOptions({ file: "X,Y1,Y2,Y3\n" + "2011-01-01,2,3,4\n" + "2011-02-02,5,3,2\n" }); - assertEquals(colors2, graph.getColors()); + assert.deepEqual(colors2, graph.getColors()); - graph.updateOptions({ colors: null, file: this.data }); - assertEquals(defaultColors, graph.getColors()); -} + graph.updateOptions({ colors: null, file: data }); + assert.deepEqual(defaultColors, graph.getColors()); +}); // Regression test for http://code.google.com/p/dygraphs/issues/detail?id=249 // Verifies that setting 'legend: always' via update immediately shows the // legend. -UpdateOptionsTestCase.prototype.testUpdateLegendAlways = function() { +it('testUpdateLegendAlways', function() { var graphDiv = document.getElementById("graph"); - var graph = new Dygraph(graphDiv, this.data, this.opts); + var graph = new Dygraph(graphDiv, data, opts); var legend = document.getElementsByClassName("dygraph-legend"); - assertEquals(1, legend.length); + assert.equal(1, legend.length); legend = legend[0]; - assertEquals("", legend.innerHTML); + assert.equal("", legend.innerHTML); graph.updateOptions({legend: 'always'}); legend = document.getElementsByClassName("dygraph-legend"); - assertEquals(1, legend.length); + assert.equal(1, legend.length); legend = legend[0]; - assertNotEquals(-1, legend.textContent.indexOf("Y1")); - assertNotEquals(-1, legend.textContent.indexOf("Y2")); -}; + assert.notEqual(-1, legend.textContent.indexOf("Y1")); + assert.notEqual(-1, legend.textContent.indexOf("Y2")); +}); + +});