Add new test to verify that highlightCallback still works after graph resize.
authorRobert Konigsberg <konigsberg@google.com>
Sat, 2 Feb 2013 17:21:37 +0000 (09:21 -0800)
committerRobert Konigsberg <konigsberg@google.com>
Sat, 2 Feb 2013 17:21:37 +0000 (09:21 -0800)
auto_tests/misc/local.html
auto_tests/tests/resize.js [new file with mode: 0644]

index 9ef2aa2..ea529fe 100644 (file)
@@ -52,6 +52,7 @@
   <script type="text/javascript" src="../tests/tickers.js"></script>
   -->
   <script type="text/javascript" src="../tests/to_dom_coords.js"></script>
   <script type="text/javascript" src="../tests/tickers.js"></script>
   -->
   <script type="text/javascript" src="../tests/to_dom_coords.js"></script>
+  <script type="text/javascript" src="../tests/resize.js"></script>
   <script type="text/javascript" src="../tests/update_options.js"></script>
   <script type="text/javascript" src="../tests/update_while_panning.js"></script>
   <script type="text/javascript" src="../tests/utils_test.js"></script>
   <script type="text/javascript" src="../tests/update_options.js"></script>
   <script type="text/javascript" src="../tests/update_while_panning.js"></script>
   <script type="text/javascript" src="../tests/utils_test.js"></script>
diff --git a/auto_tests/tests/resize.js b/auto_tests/tests/resize.js
new file mode 100644 (file)
index 0000000..d9dbbfc
--- /dev/null
@@ -0,0 +1,54 @@
+/**
+ * @fileoverview Test cases for resizing.
+ *
+ * @author konigsberg@google.com (Robert Konigsberg)
+ */
+var ResizeTestCase = TestCase("resize");
+
+ResizeTestCase.prototype.setUp = function() {
+  document.body.innerHTML = "<div id='graph'></div>";
+};
+
+ResizeTestCase.prototype.tearDown = function() {
+};
+
+ResizeTestCase.prototype.testResizeMaintainsMouseOperations = function() {
+  document.body.innerHTML =
+      '<div id="graph" style="width: 640px; height: 480px;"></div>' +
+      '</div>';
+  var graph = document.getElementById("graph");
+
+  var callbackCount = 0;
+  var callback = function() {
+    callbackCount++;
+  }
+
+  // Strum the mouse along the y-coordinate y, from 0 to x2. These are DOM values.
+  var strum = function(g, y, x2) {
+    DygraphOps.dispatchMouseDown_Point(g, 0, y);
+    for (var x = 0; x < x2; x++) {
+      DygraphOps.dispatchMouseMove_Point(g, x, y);
+    }
+    DygraphOps.dispatchMouseUp_Point(g, x2 - 1, y);
+  }
+
+  g = new Dygraph(graph,
+      "Date,Y\n" +
+      "2010/01/01,100\n" +
+      "2010/02/01,200\n" +
+      "2010/03/01,300\n" +
+      "2010/04/01,400\n" +
+      "2010/05/01,300\n" +
+      "2010/06/01,100\n",
+      { highlightCallback : callback });
+
+  strum(g, 300, 640);
+  assertEquals(6, callbackCount);
+
+  document.getElementById("graph").style.width = "500px";
+  g.resize();
+
+  callbackCount = 0;
+  strum(g, 300, 500);
+  assertEquals(6, callbackCount);
+};