X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fplugins.js;h=f339656040320398b7ff27d84517bd02fa4f95b8;hb=d97bf726ccc5645e60171f86b134fb29ac31b846;hp=565558523653e0bf743014eea0b8404671a37af3;hpb=c48464988da6eaee534f934c73f438e18eccf144;p=dygraphs.git diff --git a/auto_tests/tests/plugins.js b/auto_tests/tests/plugins.js index 5655585..f339656 100644 --- a/auto_tests/tests/plugins.js +++ b/auto_tests/tests/plugins.js @@ -3,23 +3,26 @@ * * @author konigsberg@google.com (Robert Konigsberg) */ -var pluginsTestCase = TestCase("plugins"); -pluginsTestCase.prototype.setUp = function() { - document.body.innerHTML = "
"; +import Dygraph from '../../src/dygraph'; +import DygraphOps from './DygraphOps'; - this.data = "X,Y1,Y2\n" + +describe("plugins", function() { + +cleanupAfterEach(); + +var data; + +beforeEach(function() { + data = "X,Y1,Y2\n" + "0,1,2\n" + "1,2,1\n" + "2,1,2\n" + "3,2,1\n" ; -}; +}); -pluginsTestCase.prototype.tearDown = function() { -}; - -pluginsTestCase.prototype.testWillDrawChart = function() { +it('testWillDrawChart', function() { var draw = 0; var plugin = (function() { @@ -40,12 +43,12 @@ pluginsTestCase.prototype.testWillDrawChart = function() { })(); var graph = document.getElementById("graph"); - var g = new Dygraph(graph, this.data, {plugins: [plugin]}); + var g = new Dygraph(graph, data, {plugins: [plugin]}); - assertEquals(1, draw); -}; + assert.equal(1, draw); +}); -pluginsTestCase.prototype.testPassingInstance = function() { +it('testPassingInstance', function() { // You can also pass an instance of a plugin instead of a Plugin class. var draw = 0; var p = { @@ -60,12 +63,12 @@ pluginsTestCase.prototype.testPassingInstance = function() { }; var graph = document.getElementById("graph"); - var g = new Dygraph(graph, this.data, {plugins: [p]}); + var g = new Dygraph(graph, data, {plugins: [p]}); - assertEquals(1, draw); -}; + assert.equal(1, draw); +}); -pluginsTestCase.prototype.testPreventDefault = function() { +it('testPreventDefault', function() { var data1 = "X,Y\n" + "20,-1\n" + "21,0\n" + @@ -119,7 +122,7 @@ pluginsTestCase.prototype.testPreventDefault = function() { p.pointClickPreventDefault = false; p.clickPreventDefault = false; clickOnPoint(); - assertEquals([ + assert.deepEqual([ ['plugin.pointClick', 20, -1], ['pointClickCallback', 20, -1], ['plugin.click', 20], @@ -130,7 +133,7 @@ pluginsTestCase.prototype.testPreventDefault = function() { p.pointClickPreventDefault = true; p.clickPreventDefault = false; clickOnPoint(); - assertEquals([ + assert.deepEqual([ ['plugin.pointClick', 20, -1] ], events); @@ -138,14 +141,14 @@ pluginsTestCase.prototype.testPreventDefault = function() { p.pointClickPreventDefault = false; p.clickPreventDefault = true; clickOnPoint(); - assertEquals([ + assert.deepEqual([ ['plugin.pointClick', 20, -1], ['pointClickCallback', 20, -1], ['plugin.click', 20] ], events); -}; +}); -pluginsTestCase.prototype.testEventSequence = function() { +it('testEventSequence', function() { var events = []; var eventLogger = function(name) { @@ -168,10 +171,10 @@ pluginsTestCase.prototype.testEventSequence = function() { }; var graph = document.getElementById("graph"); - var g = new Dygraph(graph, this.data, {plugins: [p]}); + var g = new Dygraph(graph, data, {plugins: [p]}); // Initial draw sequence - assertEquals([ + assert.deepEqual([ "dataDidUpdate", // should dataWillUpdate be called here, too? "predraw", "clearChart", @@ -182,7 +185,7 @@ pluginsTestCase.prototype.testEventSequence = function() { // An options change triggers a redraw, but doesn't change the data. events = []; g.updateOptions({series: {Y1: {color: 'blue'}}}); - assertEquals([ + assert.deepEqual([ "predraw", "clearChart", "willDrawChart", @@ -194,7 +197,7 @@ pluginsTestCase.prototype.testEventSequence = function() { DygraphOps.dispatchMouseDown_Point(g, 100, 100, {shiftKey: true}); DygraphOps.dispatchMouseMove_Point(g, 200, 100, {shiftKey: true}); DygraphOps.dispatchMouseUp_Point(g, 200, 100, {shiftKey: true}); - assertEquals([ + assert.deepEqual([ "clearChart", "willDrawChart", "didDrawChart" @@ -202,8 +205,8 @@ pluginsTestCase.prototype.testEventSequence = function() { // New data triggers the full sequence. events = []; - g.updateOptions({file: this.data + '\n4,1,2'}); - assertEquals([ + g.updateOptions({file: data + '\n4,1,2'}); + assert.deepEqual([ "dataWillUpdate", "dataDidUpdate", "predraw", @@ -211,4 +214,27 @@ pluginsTestCase.prototype.testEventSequence = function() { "willDrawChart", "didDrawChart" ], events); -}; +}); + +it('testDestroyCalledInOrder', function() { + var destructions = []; + var makePlugin = function(name) { + return { + activate: function(g) { return {} }, + destroy: function() { + destructions.push(name); + } + }; + }; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data, { + plugins: [makePlugin('p'), makePlugin('q')] + }); + + assert.deepEqual([], destructions); + g.destroy(); + assert.deepEqual(['q', 'p'], destructions); +}); + +});