Import babel polyfill (#813)
[dygraphs.git] / auto_tests / tests / xhr.js
CommitLineData
36b7208a
DV
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
14import Dygraph from '../../src/dygraph';
15import Util from './Util';
16
627e054d
DV
17import 'core-js/es6/promise';
18
36b7208a
DV
19function dygraphPromise(div, data, opts) {
20 return new Promise((resolve, reject) => {
21 const g = new Dygraph(div, data, opts);
22 g.ready(() => resolve(g));
23 });
24}
25
26describe("xhr", () => {
27
28it('should issue XHRs for CSV data', () => {
29 return dygraphPromise('graph', 'data/sample.csv').then(g => {
30 assert.isNotNull(g);
31 assert.equal(g.numRows(), 4);
32 assert.equal(g.numColumns(), 3);
33 });
34});
35
36it('should warn on out-of-order CSV data', () => {
37 const calls = {};
38 const restore = Util.captureConsole(calls);
39 return dygraphPromise('graph', 'data/out-of-order.csv').then(g => {
40 restore();
41 assert.isNotNull(g);
42 assert.equal(g.numRows(), 4);
43 assert.equal(g.numColumns(), 3);
44 assert.equal(calls.warn.length, 1);
45 assert(/out of order/.exec(calls.warn[0]));
46 }, e => {
47 restore();
48 return Promise.reject(e);
49 });
50});
51
52it('should warn on out-of-order CSV data with dates', () => {
53 const calls = {};
54 const restore = Util.captureConsole(calls);
55 return dygraphPromise('graph', 'data/out-of-order-dates.csv').then(g => {
56 restore();
57 assert.isNotNull(g);
58 assert.equal(g.numRows(), 8);
59 assert.equal(g.numColumns(), 5);
60 assert.equal(calls.warn.length, 1);
61 assert(/out of order/.exec(calls.warn[0]));
62 }, e => {
63 restore();
64 return Promise.reject(e);
65 });
66});
67
68});