Newer
Older
import {select, selectAll} from 'd3-selection';
import {attachToNode} from './index';
import {Actions, configureStore} from '../../store';
import {Actions as statisticsDataActions} from '../../store/statistics-data';
Naab, Daniel James
committed
const TEST_STATE = {
series: {
timeSeries: {
'00010:current': {
points: [{
value: 4,
qualifiers: ['P']
}],
method: 'method1',
Naab, Daniel James
committed
'00060:current': {
points: [{
Naab, Daniel James
committed
value: 10,
qualifiers: ['P']
}],
method: 'method1',
variable: '45807197'
Naab, Daniel James
committed
},
'00060:compare': {
points: [{
Naab, Daniel James
committed
value: 10,
qualifiers: ['P']
}],
method: 'method1',
variable: '45807197'
Naab, Daniel James
committed
}
},
timeSeriesCollections: {
'coll1': {
variable: '45807197',
Naab, Daniel James
committed
timeSeries: ['00060:current']
},
'coll2': {
variable: '45807197',
Naab, Daniel James
committed
timeSeries: ['00060:compare']
},
'coll3': {
variable: '45807197',
timeSeries: ['00060:median']
},
'coll4': {
variable: '45807190',
timeSeries: ['00010:current']
Naab, Daniel James
committed
}
},
Bucknell, Mary S.
committed
queryInfo: {
Bucknell, Mary S.
committed
notes: {
'filter:timeRange': {
mode: 'PERIOD',
periodDays: 7
},
Bucknell, Mary S.
committed
}
}
},
Naab, Daniel James
committed
requests: {
Naab, Daniel James
committed
timeSeriesCollections: ['coll1']
},
timeSeriesCollections: ['coll2', 'col4']
Naab, Daniel James
committed
}
},
variables: {
'45807197': {
variableCode: {
value: '00060'
},
oid: '45807197',
variableDescription: 'Test description for 00060',
Naab, Daniel James
committed
unit: {
unitCode: 'unitCode'
}
},
'45807190': {
variableCode: {
value: '00010'
},
oid: '45807190',
unit: {
unitCode: 'unitCode'
}
Naab, Daniel James
committed
}
},
methods: {
'method1': {
methodDescription: 'method description'
}
Naab, Daniel James
committed
}
},
statisticsData : {
median: {
'00060': {
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'1234': [
{
month_nu: '2',
day_nu: '20',
p50_va: '40',
begin_yr: '1970',
end_yr: '2017',
loc_web_ds: 'This method'
}, {
month_nu: '2',
day_nu: '21',
p50_va: '41',
begin_yr: '1970',
end_yr: '2017',
loc_web_ds: 'This method'
}, {
month_nu: '2',
day_nu: '22',
p50_va: '42',
begin_yr: '1970',
end_yr: '2017',
loc_web_ds: 'This method'
}
]
}
}
},
Bucknell, Mary S.
committed
currentVariableID: '45807197',
requestedTimeRange: null,
Bucknell, Mary S.
committed
showSeries: {
current: true,
compare: true,
median: true
},
loadingTSKeys: []
Naab, Daniel James
committed
},
Bucknell, Mary S.
committed
ui: {
width: 400
}
Naab, Daniel James
committed
};
describe('Hydrograph charting and Loading indicators and data alerts', () => {
Bucknell, Mary S.
committed
let graphNode;
Bucknell, Mary S.
committed
beforeEach(() => {
let body = select('body');
Bucknell, Mary S.
committed
let component = body.append('div')
Bucknell, Mary S.
committed
.attr('id', 'hydrograph');
component.append('div').attr('class', 'loading-indicator-container');
Bucknell, Mary S.
committed
component.append('div').attr('class', 'graph-container');
component.append('div').attr('class', 'select-time-series-container');
Bucknell, Mary S.
committed
component.append('div').attr('class', 'provisional-data-alert');
Bucknell, Mary S.
committed
graphNode = document.getElementById('hydrograph');
jasmine.Ajax.install();
Bucknell, Mary S.
committed
});
afterEach(() => {
jasmine.Ajax.uninstall();
Bucknell, Mary S.
committed
select('#hydrograph').remove();
});
it('expect alert if no siteno defined', () => {
attachToNode({}, graphNode, {});
expect(graphNode.innerHTML).toContain('No data is available');
});
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
describe('Tests for initial data fetching when showOnlyGraph is false (the default)', () => {
let store;
beforeEach(() => {
store = configureStore({});
});
it('loading-indicator is shown until initial data has been retrieved', () => {
attachToNode(store, graphNode, {
siteno: '1234568'
});
expect(select(graphNode).select('.loading-indicator').size()).toBe(1);
});
it('Expects retrieveLocationTimeZone to be called', () => {
spyOn(Actions, 'retrieveLocationTimeZone').and.callThrough();
attachToNode(store, graphNode, {
siteno: '12345678'
});
expect(Actions.retrieveLocationTimeZone).toHaveBeenCalled();
});
describe('Always retrieve the 7 day data and median statistics', () => {
beforeEach(() => {
spyOn(Actions, 'retrieveTimeSeries').and.callThrough();
spyOn(statisticsDataActions, 'retrieveMedianStatistics').and.callThrough();
});
it('Retrieve if no date parameters are used', () => {
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065'
});
expect(Actions.retrieveTimeSeries).toHaveBeenCalledWith('12345678');
expect(statisticsDataActions.retrieveMedianStatistics).toHaveBeenCalledWith('12345678');
});
it('Retrieve if period parameters is used', () => {
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065',
period: 'P30D'
});
expect(Actions.retrieveTimeSeries).toHaveBeenCalledWith('12345678');
expect(statisticsDataActions.retrieveMedianStatistics).toHaveBeenCalledWith('12345678');
});
it('Retrieve if startDT and endDT parameters are used', () => {
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065',
startDT: '2010-01-01',
endDT: '2010-03-01'
});
expect(Actions.retrieveTimeSeries).toHaveBeenCalledWith('12345678');
expect(statisticsDataActions.retrieveMedianStatistics).toHaveBeenCalledWith('12345678');
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
});
});
describe('Retrieve additional data if indicated', () => {
beforeEach(() => {
spyOn(Actions, 'retrieveTimeSeries').and.returnValue(function() {
return Promise.resolve({});
});
spyOn(Actions, 'retrieveExtendedTimeSeries').and.callThrough();
spyOn(Actions, 'retrieveDataForDateRange').and.callThrough();
});
it('Expect to not retrieve additional time series if not indicated', (done) => {
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065'
});
window.requestAnimationFrame(() => {
expect(Actions.retrieveExtendedTimeSeries).not.toHaveBeenCalled();
expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled();
done();
});
});
it('should retrieve extend time series if period set', (done) => {
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065',
period: 'P30D'
});
window.requestAnimationFrame(() => {
expect(Actions.retrieveExtendedTimeSeries).toHaveBeenCalledWith('12345678', 'P30D', '00065');
expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled();
done();
});
});
it('should not retrieve data for date range if time zone has not been fetched', (done) => {
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065',
startDT: '2010-01-01',
endDT: '2010-03-01'
});
window.requestAnimationFrame(() => {
expect(Actions.retrieveExtendedTimeSeries).not. toHaveBeenCalled();
expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled();
done();
});
});
it('should retrieve data for date range if time zone has been fetched', (done) => {
spyOn(Actions, 'retrieveLocationTimeZone').and.returnValue(function() {
return Promise.resolve({});
});
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065',
startDT: '2010-01-01',
endDT: '2010-03-01'
});
window.requestAnimationFrame(() => {
expect(Actions.retrieveExtendedTimeSeries).not. toHaveBeenCalled();
expect(Actions.retrieveDataForDateRange).toHaveBeenCalledWith('12345678', '2010-01-01', '2010-03-01', '00065');
done();
});
});
});
});
describe('Tests for initial data fetching when showOnlyGraph is true ', () => {
let store;
beforeEach(() => {
store = configureStore({});
spyOn(Actions, 'retrieveTimeSeries').and.callThrough();
spyOn(Actions, 'retrieveCustomTimePeriodTimeSeries').and.callThrough();
spyOn(Actions, 'retrieveDataForDateRange');
});
it('should retrieve custom time period if period is specificed', (done) => {
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065',
period: 'P20D',
showOnlyGraph: true
});
window.requestAnimationFrame(() => {
expect(Actions.retrieveTimeSeries).not.toHaveBeenCalled();
expect(Actions.retrieveCustomTimePeriodTimeSeries).toHaveBeenCalledWith('12345678', '00065', 'P20D');
expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled();
done();
});
});
it('should not retrieve date range for date range parameters if time zone has not been fetched', (done) => {
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065',
startDT: '2010-01-01',
endDT: '2010-03-01',
showOnlyGraph: true
});
window.requestAnimationFrame(() => {
expect(Actions.retrieveTimeSeries).not.toHaveBeenCalled();
expect(Actions.retrieveCustomTimePeriodTimeSeries).not.toHaveBeenCalled();
expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled();
done();
});
});
it('should retrieve date range for date range parameters if time zone has been fetched', (done) => {
spyOn(Actions, 'retrieveLocationTimeZone').and.returnValue(function() {
return Promise.resolve({});
});
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065',
startDT: '2010-01-01',
endDT: '2010-03-01',
showOnlyGraph: true
});
window.requestAnimationFrame(() => {
expect(Actions.retrieveTimeSeries).not.toHaveBeenCalled();
expect(Actions.retrieveCustomTimePeriodTimeSeries).not.toHaveBeenCalled();
expect(Actions.retrieveDataForDateRange).toHaveBeenCalledWith('12345678', '2010-01-01', '2010-03-01', '00065');
done();
});
});
it('should retrieve time series if no custom period or date range', (done) => {
attachToNode(store, graphNode, {
siteno: '12345678',
parameterCode: '00065',
showOnlyGraph: true
});
window.requestAnimationFrame(() => {
expect(Actions.retrieveTimeSeries).toHaveBeenCalledWith('12345678', ['00065']);
expect(Actions.retrieveCustomTimePeriodTimeSeries).not.toHaveBeenCalled();
expect(Actions.retrieveDataForDateRange).not.toHaveBeenCalled();
done();
});
});
});
Bucknell, Mary S.
committed
describe('graphNode contains the expected elements when showOnlyGraph is false', () => {
/* eslint no-use-before-define: 0 */
let store;
beforeEach((done) => {
spyOn(Actions, 'retrieveTimeSeries').and.returnValue(function() {
return Promise.resolve({});
});
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
store = configureStore({
...TEST_STATE,
series: {
...TEST_STATE.series,
timeSeries: {
...TEST_STATE.series.timeSeries,
'00060:current': {
...TEST_STATE.series.timeSeries['00060:current'],
startTime: 1514926800000,
endTime: 1514930400000,
points: [{
dateTime: 1514926800000,
value: 10,
qualifiers: ['P']
}, {
dateTime: 1514930400000,
value: null,
qualifiers: ['P', 'FLD']
}]
}
}
},
timeSeriesState: {
showSeries: {
current: true,
compare: true,
median: true
},
currentVariableID: '45807197',
currentDateRange: 'P7D',
currentMethodID: 'method1',
loadingTSKeys: [],
hydrographBrushOffset: null
}
});
attachToNode(store, graphNode, {siteno: '123456788'});
window.requestAnimationFrame(() => {
done();
});
});
it('should render the correct number of svg nodes', () => {
// one main hydrograph, brush, slider, legend and two sparklines
expect(selectAll('svg').size()).toBe(6);
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
});
it('should have a title div', () => {
const titleDiv = selectAll('.time-series-graph-title');
expect(titleDiv.size()).toBe(1);
expect(titleDiv.text()).toEqual('Test title for 00060, method description');
});
it('should have a defs node', () => {
expect(selectAll('defs').size()).toBe(1);
expect(selectAll('defs mask').size()).toBe(1);
expect(selectAll('defs pattern').size()).toBe(2);
});
it('should render time series data as a line', () => {
// There should be one segment per time-series. Each is a single
// point, so should be a circle.
expect(selectAll('.hydrograph-svg .line-segment').size()).toBe(2);
});
it('should render a rectangle for masked data', () => {
expect(selectAll('.hydrograph-svg g.current-mask-group').size()).toBe(1);
});
it('should have a point for the median stat data with a label', () => {
expect(selectAll('#median-points path').size()).toBe(1);
expect(selectAll('#median-points text').size()).toBe(0);
});
Bucknell, Mary S.
committed
it('should have brush element for the hydrograph', () => {
expect(selectAll('.brush').size()).toBe(1);
});
it('should have .cursor-slider-svg element', () => {
expect(selectAll('.cursor-slider-svg').size()).toBe(1);
Bucknell, Mary S.
committed
});
it('should have date control elements', () => {
expect(selectAll('#ts-daterange-select-container').size()).toBe(1);
expect(selectAll('#ts-customdaterange-select-container').size()).toBe(1);
});
it('should have method select element', () => {
expect(selectAll('#ts-method-select-container').size()).toBe(1);
});
it('should have the select time series element', () => {
expect(selectAll('#select-time-series').size()).toBe(1);
});
it('should have tooltips for the select series table', () => {
// one for each of the two parameters
expect(selectAll('table .tooltip-item').size()).toBe(2);
Bucknell, Mary S.
committed
})
Bucknell, Mary S.
committed
describe('hide elements when showOnlyGraph is set to true', () => {
let store;
beforeEach(() => {
spyOn(Actions, 'retrieveTimeSeries').and.returnValue(function() {
return Promise.resolve({});
});
Bucknell, Mary S.
committed
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
store = configureStore({
...TEST_STATE,
series: {
...TEST_STATE.series,
timeSeries: {
...TEST_STATE.series.timeSeries,
'00060:current': {
...TEST_STATE.series.timeSeries['00060:current'],
startTime: 1514926800000,
endTime: 1514930400000,
points: [{
dateTime: 1514926800000,
value: 10,
qualifiers: ['P']
}, {
dateTime: 1514930400000,
value: null,
qualifiers: ['P', 'FLD']
}]
}
}
},
timeSeriesState: {
showSeries: {
current: true,
compare: true,
median: true
},
currentVariableID: '45807197',
currentDateRange: 'P7D',
currentMethodID: 'method1',
loadingTSKeys: [],
hydrographBrushOffset: null
Bucknell, Mary S.
committed
},
ui: {
windowWidth: 400,
Bucknell, Mary S.
committed
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
}
});
attachToNode(store, graphNode, {siteno: '123456788', showOnlyGraph: true});
});
it('should not have brush element for the hydrograph', () => {
expect(selectAll('.brush').size()).toBe(0);
});
it('should not have slider-wrapper element', () => {
expect(selectAll('.slider-wrapper').size()).toBe(0);
});
it('should not have date control elements', () => {
expect(selectAll('#ts-daterange-select-container').size()).toBe(0);
expect(selectAll('#ts-customdaterange-select-container').size()).toBe(0);
});
it('should not have method select element', () => {
expect(selectAll('#ts-method-select-container').size()).toBe(0);
});
it('should not have the select time series element', () => {
expect(selectAll('#select-time-series').size()).toBe(0);
});
});