Newer
Older
import { select } from 'd3-selection';
import { attachToNode } from './index';
import { Actions, configureStore } from '../../store';
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': {
108
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
'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('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('empty graph displays warning', () => {
attachToNode({}, graphNode, {});
expect(graphNode.innerHTML).toContain('No data is available');
});
describe('hiding/showing provisional alert', () => {
Bucknell, Mary S.
committed
it('Expects the provisional alert to be visible when time series data is provided', () => {
let store = configureStore(TEST_STATE);
attachToNode(store, graphNode, {siteno: '12345678'});
expect(select(graphNode).select('.provisional-data-alert').attr('hidden')).toBeNull();
});
it('Expects the provisional alert to be hidden when no time series data is provided', () => {
let store = configureStore({
...TEST_STATE,
series: {},
timeSeriesState: {
...TEST_STATE.timeSeriesState,
Bucknell, Mary S.
committed
currentVariableID: ''
}
Bucknell, Mary S.
committed
});
attachToNode(store, graphNode, {siteno: '12345678'});
expect(select(graphNode).select('.provisional-data-alert').attr('hidden')).toBe('true');
});
});
Bucknell, Mary S.
committed
describe('Tests for loading indicators', () => {
it('Expects the graph loading indicator to be visible if the current 7 day data is being loaded', () => {
const newTestState = {
...TEST_STATE,
timeSeriesState: {
...TEST_STATE.timeSeriesState,
currentDateRange: 'P7D',
loadingTSKeys: ['current:P7D']
}
};
let store = configureStore(newTestState);
spyOn(store, 'dispatch').and.callThrough();
attachToNode(store, graphNode, {siteno: '12345678'});
expect(select(graphNode).select('.loading-indicator-container').select('.loading-indicator').size()).toBe(1);
});
it('Expects the graph loading indicator to not be visible if the current 7 day data is not being loaded', () => {
const newTestState = {
...TEST_STATE,
timeSeriesState: {
...TEST_STATE.timeSeriesState,
currentDateRange: 'P7D'
}
};
let store = configureStore(newTestState);
spyOn(store, 'dispatch').and.callThrough();
attachToNode(store, graphNode, {siteno: '12345678'});
store.dispatch(Actions.removeTimeSeriesLoading(['current:P7D']));
233
234
235
236
237
238
239
240
241
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
expect(select(graphNode).select('.loading-indicator-container').select('.loading-indicator').size()).toBe(0);
});
it('Expects the date range control loading indicator to be visible if loading is in progress for the selected date range', () => {
const newTestState = {
...TEST_STATE,
timeSeriesState: {
...TEST_STATE.timeSeriesState,
currentDateRange: 'P30D',
loadingTSKeys: ['current:P30D:00060']
}
};
let store = configureStore(newTestState);
attachToNode(store, graphNode, {siteno: '12345678'});
expect(select(graphNode).select('#ts-daterange-select-container').select('.loading-indicator').size()).toBe(1);
});
it('Expects the date range control loading indicator to notbe visible if not loading for the selected date range', () => {
const newTestState = {
...TEST_STATE,
timeSeriesState: {
...TEST_STATE.timeSeriesState,
currentDateRange: 'P30D',
loadingTSKeys: ['compare:P30D:00060']
}
};
let store = configureStore(newTestState);
attachToNode(store, graphNode, {siteno: '12345678'});
expect(select(graphNode).select('#ts-daterange-select-container').select('.loading-indicator').size()).toBe(0);
});
it('Expects that the no data alert will not be shown if there is data', () => {
let store = configureStore(TEST_STATE);
attachToNode(store, graphNode, {siteno: '12345678'});
expect(select(graphNode).select('#no-data-message').size()).toBe(0);
});
});