| | 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 | import 'core-js/es6/promise'; |
| | 18 | |
| | 19 | function 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 | |
| | 26 | describe("xhr", () => { |
| | 27 | |
| | 28 | it('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 | |
| | 36 | it('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 | |
| | 52 | it('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 | }); |