Newer
Older
import {select, selectAll} from 'd3-selection';
import {legendMarkerRowsSelector, drawTimeSeriesLegend} from './legend';
import {lineMarker, rectangleMarker, textOnlyMarker} from '../../d3-rendering/markers';
import {Actions, configureStore} from '../../store';
describe('UV: Legend module', () => {
const TEST_DATA = {
series: {
timeSeries: {
'00060:current': {
tsKey: 'current:P7D',
startTime: new Date('2018-03-06T15:45:00.000Z'),
endTime: new Date('2018-03-13T13:45:00.000Z'),
variable: '45807197',
points: [{
value: 10,
qualifiers: ['P'],
approved: false,
estimated: false
}, {
value: null,
qualifiers: ['P', 'ICE'],
approved: false,
estimated: false
}, {
value: null,
qualifiers: ['P', 'FLD'],
approved: false,
estimated: false
}]
},
Bucknell, Mary S.
committed
'00060:compare': {
Bucknell, Mary S.
committed
startTime: new Date('2018-03-06T15:45:00.000Z'),
endTime: new Date('2018-03-06T15:45:00.000Z'),
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
variable: '45807202',
points: [{
value: 1,
qualifiers: ['A'],
approved: false,
estimated: false
}, {
value: 2,
qualifiers: ['A'],
approved: false,
estimated: false
}, {
value: 3,
qualifiers: ['E'],
approved: false,
estimated: false
}]
}
},
variables: {
'45807197': {
variableCode: {value: '00060'},
variableName: 'Streamflow',
variableDescription: 'Discharge, cubic feet per second',
oid: '45807197'
},
'45807202': {
variableCode: {value: '00065'},
variableName: 'Gage height',
oid: '45807202'
}
}
},
statisticsData: {
median: {
'00060': {
'1': [{
month_nu: '2',
day_nu: '25',
p50_va: '43',
begin_yr: '1970',
end_yr: '2017',
loc_web_ds: 'This method'
}]
}
}
},
timeSeriesState: {
currentVariableID: '45807197',
currentDateRange: 'P7D',
showSeries: {
current: true,
compare: true,
median: true
}
}
};
describe('legendMarkerRowSelector', () => {
it('Should return no markers if no time series to show', () => {
let newData = {
...TEST_DATA,
series: {
...TEST_DATA.series,
timeSeries: {}
},
statisticsData: {}
Bucknell, Mary S.
committed
};
expect(legendMarkerRowsSelector(newData)).toEqual([]);
});
it('Should return markers for the selected variable', () => {
const result = legendMarkerRowsSelector(TEST_DATA);
Bucknell, Mary S.
committed
expect(result.length).toBe(2);
expect(result[0].length).toBe(4);
expect(result[0][0].type).toEqual(textOnlyMarker);
expect(result[0][1].type).toEqual(lineMarker);
expect(result[0][2].type).toEqual(rectangleMarker);
expect(result[0][3].type).toEqual(rectangleMarker);
expect(result[1].length).toBe(2);
expect(result[1][0].type).toEqual(textOnlyMarker);
expect(result[1][1].type).toEqual(lineMarker);
});
it('Should return markers for a different selected variable', () => {
const newData = {
Bucknell, Mary S.
committed
...TEST_DATA,
timeSeriesState: {
...TEST_DATA.timeSeriesState,
currentVariableID: '45807202'
}
};
const result = legendMarkerRowsSelector(newData);
expect(result.length).toBe(1);
expect(result[0].length).toBe(3);
expect(result[0][0].type).toEqual(textOnlyMarker);
expect(result[0][1].type).toEqual(lineMarker);
expect(result[0][2].type).toEqual(lineMarker);
Bucknell, Mary S.
committed
});
it('Should return markers only for time series shown', () => {
const newData = {
...TEST_DATA,
timeSeriesState: {
...TEST_DATA.timeSeriesState,
showSeries: {
'current': true,
'compare': false,
'median': false
};
const result = legendMarkerRowsSelector(newData);
expect(result.length).toBe(1);
expect(result[0].length).toBe(4);
expect(result[0][0].type).toEqual(textOnlyMarker);
expect(result[0][2].type).toEqual(rectangleMarker);
expect(result[0][3].type).toEqual(rectangleMarker);
describe('legends should render', () => {
let graphNode;
Bucknell, Mary S.
committed
let store;
beforeEach(() => {
let body = select('body');
let component = body.append('div')
.attr('id', 'hydrograph');
component.append('div').attr('class', 'loading-indicator-container');
component.append('div').attr('class', 'graph-container');
component.append('div').attr('class', 'select-time-series-container');
component.append('div').attr('class', 'provisional-data-alert');
graphNode = document.getElementById('hydrograph');
Bucknell, Mary S.
committed
store = configureStore(TEST_DATA);
select(graphNode)
Bucknell, Mary S.
committed
.call(drawTimeSeriesLegend, store);
Bucknell, Mary S.
committed
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
select('#hydrograph').remove();
});
it('Should have 6 legend markers', () => {
expect(selectAll('.legend g').size()).toBe(6);
expect(selectAll('.legend g line.median-step').size()).toBe(1);
});
Bucknell, Mary S.
committed
it('Should have 4 legend marker after the median time series are removed', (done) => {
store.dispatch(Actions.toggleTimeSeries('median', false));
Bucknell, Mary S.
committed
window.requestAnimationFrame(() => {
expect(selectAll('.legend g').size()).toBe(4);
done();
});