auto_tests for XHRs csv-file-order
authorDan Vanderkam <danvdk@gmail.com>
Sat, 1 Oct 2016 21:23:10 +0000 (17:23 -0400)
committerDan Vanderkam <danvdk@gmail.com>
Sat, 1 Oct 2016 21:23:10 +0000 (17:23 -0400)
auto_tests/data/out-of-order-dates.csv [new file with mode: 0644]
auto_tests/data/out-of-order.csv [new file with mode: 0644]
auto_tests/data/sample.csv [new file with mode: 0644]
auto_tests/tests/xhr.js [new file with mode: 0644]

diff --git a/auto_tests/data/out-of-order-dates.csv b/auto_tests/data/out-of-order-dates.csv
new file mode 100644 (file)
index 0000000..a05ef06
--- /dev/null
@@ -0,0 +1,9 @@
+Date,r17,r82,r83,r9
+2013-10-17T21:00:00Z,,,,9
+2014-05-29T18:00:00Z,,,,9
+2013-10-17T21:00:00Z,17,,,
+2014-05-29T17:00:00Z,17,,,
+2014-05-29T18:00:00Z,,82,,
+2014-05-29T18:00:00Z,,,83,
+2014-10-11T04:00:00Z,,,83,
+2015-05-22T04:00:00Z,,82,,
diff --git a/auto_tests/data/out-of-order.csv b/auto_tests/data/out-of-order.csv
new file mode 100644 (file)
index 0000000..51f40a6
--- /dev/null
@@ -0,0 +1,5 @@
+X,Y1,Y2
+0,0,0
+1,1,1
+3,3,9
+2,2,4
diff --git a/auto_tests/data/sample.csv b/auto_tests/data/sample.csv
new file mode 100644 (file)
index 0000000..5bae60e
--- /dev/null
@@ -0,0 +1,5 @@
+X,Y1,Y2
+0,0,0
+1,1,1
+2,2,4
+3,3,9
diff --git a/auto_tests/tests/xhr.js b/auto_tests/tests/xhr.js
new file mode 100644 (file)
index 0000000..90712fa
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ * @fileoverview Tests involving issuing XHRs for data.
+ *
+ * Note that these tests must be run with an HTTP server.
+ * XHRs can't be issued from file:/// URLs.
+ * This can be done with
+ *
+ *     npm install http-server
+ *     http-server
+ *     open http://localhost:8080/auto_tests/runner.html
+ *
+ */
+
+import Dygraph from '../../src/dygraph';
+import Util from './Util';
+
+function dygraphPromise(div, data, opts) {
+  return new Promise((resolve, reject) => {
+    const g = new Dygraph(div, data, opts);
+    g.ready(() => resolve(g));
+  });
+}
+
+describe("xhr", () => {
+
+it('should issue XHRs for CSV data', () => {
+  return dygraphPromise('graph', 'data/sample.csv').then(g => {
+    assert.isNotNull(g);
+    assert.equal(g.numRows(), 4);
+    assert.equal(g.numColumns(), 3);
+  });
+});
+
+it('should warn on out-of-order CSV data', () => {
+  const calls = {};
+  const restore = Util.captureConsole(calls);
+  return dygraphPromise('graph', 'data/out-of-order.csv').then(g => {
+    restore();
+    assert.isNotNull(g);
+    assert.equal(g.numRows(), 4);
+    assert.equal(g.numColumns(), 3);
+    assert.equal(calls.warn.length, 1);
+    assert(/out of order/.exec(calls.warn[0]));
+  }, e => {
+    restore();
+    return Promise.reject(e);
+  });
+});
+
+it('should warn on out-of-order CSV data with dates', () => {
+  const calls = {};
+  const restore = Util.captureConsole(calls);
+  return dygraphPromise('graph', 'data/out-of-order-dates.csv').then(g => {
+    restore();
+    assert.isNotNull(g);
+    assert.equal(g.numRows(), 8);
+    assert.equal(g.numColumns(), 5);
+    assert.equal(calls.warn.length, 1);
+    assert(/out of order/.exec(calls.warn[0]));
+  }, e => {
+    restore();
+    return Promise.reject(e);
+  });
+});
+
+});