90712fadb965a1752e5e35bbec89d43ca2ef90eb
[dygraphs.git] / auto_tests / tests / xhr.js
1 /**
2 * @fileoverview Tests involving issuing XHRs for data.
3 *
4 * Note that these tests must be run with an HTTP server.
5 * XHRs can't be issued from file:/// URLs.
6 * This can be done with
7 *
8 * npm install http-server
9 * http-server
10 * open http://localhost:8080/auto_tests/runner.html
11 *
12 */
13
14 import Dygraph from '../../src/dygraph';
15 import Util from './Util';
16
17 function dygraphPromise(div, data, opts) {
18 return new Promise((resolve, reject) => {
19 const g = new Dygraph(div, data, opts);
20 g.ready(() => resolve(g));
21 });
22 }
23
24 describe("xhr", () => {
25
26 it('should issue XHRs for CSV data', () => {
27 return dygraphPromise('graph', 'data/sample.csv').then(g => {
28 assert.isNotNull(g);
29 assert.equal(g.numRows(), 4);
30 assert.equal(g.numColumns(), 3);
31 });
32 });
33
34 it('should warn on out-of-order CSV data', () => {
35 const calls = {};
36 const restore = Util.captureConsole(calls);
37 return dygraphPromise('graph', 'data/out-of-order.csv').then(g => {
38 restore();
39 assert.isNotNull(g);
40 assert.equal(g.numRows(), 4);
41 assert.equal(g.numColumns(), 3);
42 assert.equal(calls.warn.length, 1);
43 assert(/out of order/.exec(calls.warn[0]));
44 }, e => {
45 restore();
46 return Promise.reject(e);
47 });
48 });
49
50 it('should warn on out-of-order CSV data with dates', () => {
51 const calls = {};
52 const restore = Util.captureConsole(calls);
53 return dygraphPromise('graph', 'data/out-of-order-dates.csv').then(g => {
54 restore();
55 assert.isNotNull(g);
56 assert.equal(g.numRows(), 8);
57 assert.equal(g.numColumns(), 5);
58 assert.equal(calls.warn.length, 1);
59 assert(/out of order/.exec(calls.warn[0]));
60 }, e => {
61 restore();
62 return Promise.reject(e);
63 });
64 });
65
66 });