Newer
Older
import {select, selectAll} from 'd3-selection';
Bucknell, Mary S.
committed
import sinon from 'sinon';
Bucknell, Mary S.
committed
import * as utils from 'ui/utils';
Bucknell, Mary S.
committed
import {configureStore} from 'ml/store';
import {Actions} from 'ml/store/instantaneous-value-time-series-state';
Bucknell, Mary S.
committed
import {drawTimeSeriesLegend} from './legend';
Bucknell, Mary S.
committed
describe('monitoring-location/components/hydrograph/legend module', () => {
Bucknell, Mary S.
committed
utils.mediaQuery = jest.fn().mockReturnValue(true);
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'),
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
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'
}]
}
}
},
ivTimeSeriesState: {
currentIVVariableID: '45807197',
Briggs, Aaron Shane
committed
currentIVDateRange: 'P7D',
current: true,
compare: true,
median: true
}
floodData: {
floodLevels: {
site_no: '07144100',
action_stage: '20',
flood_stage: '22',
moderate_flood_stage: '25',
major_flood_stage: '26'
}
};
describe('legends should render', () => {
let graphNode;
Bucknell, Mary S.
committed
let store;
Bucknell, Mary S.
committed
let fakeServer;
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');
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
Bucknell, Mary S.
committed
fakeServer = sinon.createFakeServer();
Bucknell, Mary S.
committed
fakeServer.restore();
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.setIVTimeSeriesVisibility('median', false));
Bucknell, Mary S.
committed
window.requestAnimationFrame(() => {
expect(selectAll('.legend g').size()).toBe(4);
done();
});