From: Robert Konigsberg Date: Thu, 23 Feb 2012 00:01:06 +0000 (-0500) Subject: Add tests for drawPointCallback and drawHighlightCallback X-Git-Tag: v1.0.0~323^2~5 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=72c12eda172cf9f25ad4158f1962392d8c64da9e;p=dygraphs.git Add tests for drawPointCallback and drawHighlightCallback --- diff --git a/auto_tests/tests/callback.js b/auto_tests/tests/callback.js index 8bca592..a7266d1 100644 --- a/auto_tests/tests/callback.js +++ b/auto_tests/tests/callback.js @@ -13,11 +13,11 @@ CallbackTestCase.prototype.setUp = function() { CallbackTestCase.prototype.tearDown = function() { }; - var data = "X,a\,b,c\n" + - "10,-1,1,2\n" + - "11,0,3,1\n" + - "12,1,4,2\n" + - "13,0,2,3\n"; +var data = "X,a\,b,c\n" + + "10,-1,1,2\n" + + "11,0,3,1\n" + + "12,1,4,2\n" + + "13,0,2,3\n"; /** @@ -29,7 +29,7 @@ CallbackTestCase.prototype.testHighlightCallbackIsCalled = function() { var h_row; var h_pts; - var highlightCallback = function(e, x, pts, row) { + var highlightCallback = function(e, x, pts, row) { h_row = row; h_pts = pts; }; @@ -58,7 +58,7 @@ CallbackTestCase.prototype.testHighlightCallbackIsCalled = function() { CallbackTestCase.prototype.testDrawPointCallback_disabled = function() { var called = false; - var callback = function() { + var callback = function() { called = true; }; @@ -76,7 +76,7 @@ CallbackTestCase.prototype.testDrawPointCallback_disabled = function() { CallbackTestCase.prototype.testDrawPointCallback_enabled = function() { var called = false; - var callback = function() { + var callback = function() { called = true; }; @@ -88,4 +88,58 @@ CallbackTestCase.prototype.testDrawPointCallback_enabled = function() { assertTrue(called); }; -// TODO * @fileoverview Test cases for drawPointCallback and drawHighlightCallback + +/** + * Test that drawPointCallback is called when drawPoints is true + */ +CallbackTestCase.prototype.testDrawPointCallback_pointSize = function() { + var pointSize = 0; + var count = 0; + + var callback = function(g, seriesName, canvasContext, cx, cy, color, pointSizeParam) { + pointSize = pointSizeParam; + count++; + }; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data, { + drawPoints : true, + drawPointCallback : callback + }); + + assertEquals(1.5, pointSize); + assertEquals(12, count); // one call per data point. + + var g = new Dygraph(graph, data, { + drawPoints : true, + drawPointCallback : callback, + pointSize : 8 + }); + + assertEquals(8, pointSize); +}; + +/** + * This tests that when the function idxToRow_ returns the proper row and the onHiglightCallback + * is properly called when the first series is hidden (setVisibility = false) + * + */ +CallbackTestCase.prototype.testDrawHighlightCallbackIsCalled = function() { + var called = false; + + var drawHighlightCallback = function() { + called = true; + }; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data, + { + width: 100, + height : 100, + drawHighlightCallback : drawHighlightCallback + }); + + assertFalse(called); + DygraphOps.dispatchMouseMove(g, 13, 10); + assertTrue(called); +};