X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fcallback.js;h=a727fa5b16b06f0230a8b9324c4e340dfd971223;hb=b59d8eebfd61f9a249b4390a6c6ca171188a5282;hp=0e6b4fa78b63d2e9d54af3fb74b0008d3d86b60e;hpb=45df6dd0902ef39691f061a70f4702e606fb747e;p=dygraphs.git diff --git a/auto_tests/tests/callback.js b/auto_tests/tests/callback.js index 0e6b4fa..a727fa5 100644 --- a/auto_tests/tests/callback.js +++ b/auto_tests/tests/callback.js @@ -8,12 +8,14 @@ var CallbackTestCase = TestCase("callback"); CallbackTestCase.prototype.setUp = function() { document.body.innerHTML = "
"; + this.xhr = XMLHttpRequest; this.styleSheet = document.createElement("style"); this.styleSheet.type = "text/css"; document.getElementsByTagName("head")[0].appendChild(this.styleSheet); }; CallbackTestCase.prototype.tearDown = function() { + XMLHttpRequest = this.xhr; }; var data = "X,a\,b,c\n" + @@ -487,3 +489,125 @@ CallbackTestCase.prototype.testGapHighlight = function() { assertEquals(8, h_pts[0].yval); assertEquals('A', h_pts[0].name); }; + +CallbackTestCase.prototype.testFailedResponse = function() { + + // Fake out the XMLHttpRequest so it doesn't do anything. + XMLHttpRequest = function () {}; + XMLHttpRequest.prototype.open = function () {}; + XMLHttpRequest.prototype.send = function () {}; + + var highlightCallback = function(e, x, pts, row) { + fail("should not reach here"); + }; + + var graph = document.getElementById("graph"); + graph.style.border = "2px solid black"; + var g = new Dygraph(graph, "data.csv", { // fake name + width: 400, + height: 300, + highlightCallback : highlightCallback + }); + + DygraphOps.dispatchMouseOver_Point(g, 800, 800); + DygraphOps.dispatchMouseMove_Point(g, 100, 100); + DygraphOps.dispatchMouseMove_Point(g, 800, 800); + + var oldOnerror = window.onerror; + var failed = false; + window.onerror = function() { failed = true; return false; } + + DygraphOps.dispatchMouseOut_Point(g, 800, 800); // This call should not throw an exception. + + assertFalse("exception thrown during mouseout", failed); +}; + + +// Regression test for http://code.google.com/p/dygraphs/issues/detail?id=355 +CallbackTestCase.prototype.testHighlightCallbackRow = function() { + var highlightRow; + var highlightCallback = function(e, x, pts, row) { + highlightRow = row; + }; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, + "X,Y,Z\n" + + "0,1,2\n" + // 0 + "1,2,3\n" + // 100 + "2,3,4\n" + // 200 + "3,4,5\n" + // 300 + "4,5,6\n", // 400 + { // fake name + width: 400, + height: 300, + highlightCallback : highlightCallback + }); + + // Mouse over each of the points + DygraphOps.dispatchMouseOver_Point(g, 0, 0); + DygraphOps.dispatchMouseMove_Point(g, 0, 0); + assertEquals(0, highlightRow); + DygraphOps.dispatchMouseMove_Point(g, 100, 0); + assertEquals(1, highlightRow); + DygraphOps.dispatchMouseMove_Point(g, 200, 0); + assertEquals(2, highlightRow); + DygraphOps.dispatchMouseMove_Point(g, 300, 0); + assertEquals(3, highlightRow); + DygraphOps.dispatchMouseMove_Point(g, 400, 0); + assertEquals(4, highlightRow); + + // Now zoom and verify that the row numbers still refer to rows in the data + // array. + g.updateOptions({dateWindow: [2, 4]}); + DygraphOps.dispatchMouseOver_Point(g, 0, 0); + DygraphOps.dispatchMouseMove_Point(g, 0, 0); + assertEquals(2, highlightRow); + assertEquals('2: Y: 3 Z: 4', Util.getLegend()); +}; + +/** + * Test that underlay callback is called even when there are no series, + * and that the y axis ranges are not NaN. + */ +CallbackTestCase.prototype.underlayCallback_noSeries = function() { + var called = false; + var yMin, yMax; + + var callback = function(canvas, area, g) { + called = true; + yMin = g.yAxisRange(0)[0]; + yMax = g.yAxisRange(0)[1]; + }; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, "\n", { + underlayCallback: callback + }); + + assertTrue(called); + assertFalse(isNaN(yMin)); + assertFalse(isNaN(yMax)); +}; + +/** + * Test that underlay callback receives the correct y-axis range. + */ +CallbackTestCase.prototype.underlayCallback_yAxisRange = function() { + var called = false; + var yMin, yMax; + + var callback = function(canvas, area, g) { + yMin = g.yAxisRange(0)[0]; + yMax = g.yAxisRange(0)[1]; + }; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, "\n", { + valueRange: [0,10], + underlayCallback: callback + }); + + assertEquals(0, yMin); + assertEquals(10, yMax); +};