From: Dan Vanderkam Date: Sat, 1 Oct 2016 21:30:52 +0000 (-0400) Subject: auto_tests for XHRs (#786) X-Git-Tag: v2.0.0~13 X-Git-Url: https://adrianiainlam.tk/git/?p=dygraphs.git;a=commitdiff_plain;h=36b7208a4cb1495492009ff1be0364c119816cec auto_tests for XHRs (#786) --- diff --git a/auto_tests/data/out-of-order-dates.csv b/auto_tests/data/out-of-order-dates.csv new file mode 100644 index 0000000..a05ef06 --- /dev/null +++ b/auto_tests/data/out-of-order-dates.csv @@ -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 index 0000000..51f40a6 --- /dev/null +++ b/auto_tests/data/out-of-order.csv @@ -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 index 0000000..5bae60e --- /dev/null +++ b/auto_tests/data/sample.csv @@ -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 index 0000000..90712fa --- /dev/null +++ b/auto_tests/tests/xhr.js @@ -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); + }); +}); + +});