Convert tests from jstd to Mocha.
[dygraphs.git] / auto_tests / tests / Util.js
index 8a14e06..3436c15 100644 (file)
@@ -16,7 +16,7 @@ Util.getYLabels = function(axis_num, parent) {
   var y_labels = parent.getElementsByClassName("dygraph-axis-label-y" + axis_num);
   var ary = [];
   for (var i = 0; i < y_labels.length; i++) {
-    ary.push(y_labels[i].innerHTML);
+    ary.push(y_labels[i].innerHTML.replace(/&#160;|&nbsp;/g, ' '));
   }
   return ary;
 };
@@ -31,7 +31,7 @@ Util.getXLabels = function(parent) {
   var x_labels = parent.getElementsByClassName("dygraph-axis-label-x");
   var ary = [];
   for (var i = 0; i < x_labels.length; i++) {
-    ary.push(x_labels[i].innerHTML);
+    ary.push(x_labels[i].innerHTML.replace(/&#160;|&nbsp;/g, ' '));
   }
   return ary;
 };
@@ -62,9 +62,9 @@ Util.getLegend = function(parent) {
  * Assert that all elements have a certain style property.
  */
 Util.assertStyleOfChildren = function(selector, property, expectedValue) {
-  assertTrue(selector.length > 0);
+  assert.isTrue(selector.length > 0);
   $.each(selector, function(idx, child) {
-    assertEquals(expectedValue,  $(child).css(property));
+    assert.isEqual(expectedValue,  $(child).css(property));
   });
 };
 
@@ -91,7 +91,9 @@ Util.samplePixel = function(canvas, x, y) {
   // TODO(danvk): Any performance issues with this?
   var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
 
-  var i = 4 * (x + imageData.width * y);
+  var scale = Dygraph.getContextPixelRatio(ctx);
+
+  var i = 4 * (x * scale + imageData.width * y * scale);
   var d = imageData.data;
   return [d[i], d[i+1], d[i+2], d[i+3]];
 };
@@ -119,7 +121,7 @@ Util.overrideXMLHttpRequest = function(data) {
     this.responseText = data;
   };
   FakeXMLHttpRequest.restore = function() {
-    XMLHttpRequest = originalXMLHttpRequest;
+    window.XMLHttpRequest = originalXMLHttpRequest;
   };
   FakeXMLHttpRequest.respond = function() {
     for (var i = 0; i < requests.length; i++) {
@@ -127,7 +129,15 @@ Util.overrideXMLHttpRequest = function(data) {
     }
     FakeXMLHttpRequest.restore();
   };
-  XMLHttpRequest = FakeXMLHttpRequest;
+  window.XMLHttpRequest = FakeXMLHttpRequest;
   return FakeXMLHttpRequest;
 };
 
+/**
+ * Format a date as 2000/01/23
+ * @param {number} dateMillis Millis since epoch.
+ * @return {string} The date formatted as YYYY-MM-DD.
+ */
+Util.formatDate = function(dateMillis) {
+  return Dygraph.dateString_(dateMillis).slice(0, 10);  // 10 == "YYYY/MM/DD".length
+};