From 492ea455d937041ca98dc95b5a4e11da5e1f91d4 Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Fri, 30 Mar 2012 15:47:10 -0400 Subject: [PATCH] Add sanity test ensuring that creating annotations in a drawCallback results in a secondary draw, but initial parameter set to false. Also minor formatting corrections. --- auto_tests/tests/annotations.js | 44 ++++++++++++++++++++++++++++++++++------- auto_tests/tests/callback.js | 2 +- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/auto_tests/tests/annotations.js b/auto_tests/tests/annotations.js index 939c83f..857dd60 100644 --- a/auto_tests/tests/annotations.js +++ b/auto_tests/tests/annotations.js @@ -3,16 +3,16 @@ * * @author danvk@google.com (Dan Vanderkam) */ -var annotationsTestCase = TestCase("annotations"); +var AnnotationsTestCase = TestCase("annotations"); -annotationsTestCase.prototype.setUp = function() { +AnnotationsTestCase.prototype.setUp = function() { document.body.innerHTML = "
"; }; -annotationsTestCase.prototype.tearDown = function() { +AnnotationsTestCase.prototype.tearDown = function() { }; -annotationsTestCase.prototype.testAnnotationsDrawn = function() { +AnnotationsTestCase.prototype.testAnnotationsDrawn = function() { var opts = { width: 480, height: 320 @@ -59,7 +59,7 @@ annotationsTestCase.prototype.testAnnotationsDrawn = function() { // 1. Invalid series name (e.g. 'X' or 'non-existent') // 2. Passing a string as 'x' instead of a number (e.g. x: '1') -annotationsTestCase.prototype.testAnnotationsDontDisappearOnResize = function() { +AnnotationsTestCase.prototype.testAnnotationsDontDisappearOnResize = function() { var opts = { }; var data = "X,Y\n" + @@ -98,7 +98,7 @@ annotationsTestCase.prototype.testAnnotationsDontDisappearOnResize = function() }; // Verify that annotations outside of the visible x-range are not shown. -annotationsTestCase.prototype.testAnnotationsOutOfRangeX = function() { +AnnotationsTestCase.prototype.testAnnotationsOutOfRangeX = function() { var opts = { }; var data = "X,Y\n" + @@ -141,7 +141,7 @@ annotationsTestCase.prototype.testAnnotationsOutOfRangeX = function() { }; // Verify that annotations outside of the visible y-range are not shown. -annotationsTestCase.prototype.testAnnotationsOutOfRangeY = function() { +AnnotationsTestCase.prototype.testAnnotationsOutOfRangeY = function() { var opts = { }; var data = "X,Y\n" + @@ -175,3 +175,33 @@ annotationsTestCase.prototype.testAnnotationsOutOfRangeY = function() { a1 = document.getElementsByClassName('ann1'); assertEquals(1, a1.length); }; + +AnnotationsTestCase.prototype.testAnnotationsDrawnInDrawCallback = function() { + var data = "X,Y\n" + + "0,-1\n" + + "1,0\n" + + "2,1\n"; + + var graph = document.getElementById("graph"); + + var calls = []; + var g = new Dygraph(graph, data, { + width: 480, + height: 320, + drawCallback: function(g, initial) { + calls.push(initial); + if (initial) { + g.setAnnotations([ + { + series: 'Y', + x: 1, + shortText: 'A', + text: 'Long A', + }, + ]); + } + } + }); + + assertEquals([true, false], calls); +}; diff --git a/auto_tests/tests/callback.js b/auto_tests/tests/callback.js index 8c054a9..4d0b172 100644 --- a/auto_tests/tests/callback.js +++ b/auto_tests/tests/callback.js @@ -375,7 +375,7 @@ CallbackTestCase.prototype.testNaNDataStack = function() { }; CallbackTestCase.prototype.testGapHighlight = function() { -var dataGap = [ + var dataGap = [ [1, null, 3], [2, 2, null], [3, null, 5], -- 2.7.4