Newer
Older
import {select, selectAll} from 'd3-selection';
Bucknell, Mary S.
committed
import {configureStore} from 'ml/store';
Bucknell, Mary S.
committed
import {drawGraphControls} from './graph-controls';
// Tests for the graph-controls module
describe('monitoring-location/components/dailyValueHydrograph/graphControls', () => {
const TEST_STATE = {
dailyValueTimeSeriesData: {
availableDVTimeSeries: [{
parameterCode: '72019',
statisticCode: '00001',
Bucknell, Mary S.
committed
id: '1122'
Bucknell, Mary S.
committed
}, {
parameterCode: '72019',
statisticCode: '00003',
Bucknell, Mary S.
committed
id: '1123'
Bucknell, Mary S.
committed
}, {
Bucknell, Mary S.
committed
parameterCode: '62610',
Bucknell, Mary S.
committed
id: '1124'
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
}],
dvTimeSeries: {
'1122' : {
type: 'Feature',
id: '1122',
properties: {
observationType: 'MeasureTimeseriesObservation',
phenomenonTimeStart: '2010-01-01',
phenomenonTimeEnd: '2010-01-04',
observedPropertyName: 'Water level, depth LSD',
observedPropertyReference: null,
samplingFeatureName: 'CT-SC 22 SCOTLAND',
statistic: 'MAXIMUM',
statisticReference: null,
unitOfMeasureName: 'ft',
unitOfMeasureReference: null,
timeStep: ['2010-01-01', '2010-01-02', '2010-01-03', '2010-01-04'],
result: ['4.5', '3.2', '4.6', '2.9'],
nilReason: [null, null, null, null],
approvals: [['Approved'], ['Approved'], ['Approved'], ['Approved']],
qualifiers: [null, null, null, null],
grades: [['50'], ['50'], ['50'], ['50']]
}
},
'1123' : {
type: 'Feature',
id: '1123',
properties: {
observationType: 'MeasureTimeseriesObservation',
phenomenonTimeStart: '2010-01-01',
phenomenonTimeEnd: '2010-01-04',
observedPropertyName: 'Water level, depth LSD',
observedPropertyReference: null,
samplingFeatureName: 'CT-SC 22 SCOTLAND',
statistic: 'MEAN',
statisticReference: null,
unitOfMeasureName: 'ft',
unitOfMeasureReference: null,
timeStep: ['2010-01-01', '2010-01-02', '2010-01-03', '2010-01-04'],
result: ['3.5', '2.2', '3.6', '1.9'],
nilReason: [null, null, null, null],
approvals: [['Approved'], ['Approved'], ['Approved'], ['Approved']],
qualifiers: [null, null, null, null],
grades: [['50'], ['50'], ['50'], ['50']]
}
}
}
},
dailyValueTimeSeriesState: {
currentDVTimeSeriesId: {
min: null,
mean: '1122',
Bucknell, Mary S.
committed
max: '1123'
},
dvGraphCursorOffset: 1262476800000
},
ui: {
windowWidth: 1024,
width: 800
}
};
const TEST_STATE_ONE_PARAM_CODE = {
...TEST_STATE,
dailyValueTimeSeriesData: {
...TEST_STATE.dailyValueTimeSeriesData,
availableDVTimeSeries: [{
parameterCode: '72019',
statisticCode: '00001',
Bucknell, Mary S.
committed
id: '1122'
}, {
parameterCode: '72019',
statisticCode: '00003',
Bucknell, Mary S.
committed
id: '1123'
}]
}
};
const TEST_STATE_NO_DATA = {
dailyValueTimeSeriesData: {
availableDVTimeSeries: [],
dvTimeSeries: {}
},
dailyValueTimeSeriesState: {
currentDVTimeSeriesId: {
min: null,
mean: null,
max: null
},
dvGraphCursorOffset: 0
},
ui: {
windowWidth: 1024,
width: 800
}
};
describe('drawGraphControls with data', () => {
let div;
let store;
beforeEach(() => {
div = select('body').append('div');
store = configureStore(TEST_STATE);
Bucknell, Mary S.
committed
div.call(drawGraphControls, store, '111111111', '72019');
});
afterEach(() => {
div.remove();
});
it('Should render the radio buttons', () => {
const radioButtons = selectAll('input[type="radio"]');
const firstRadioButton = select('#code-72019-radio');
expect(radioButtons.size()).toBe(2);
expect(firstRadioButton.property('checked')).toBe(true);
});
});
describe('drawGraphControls with one param code', () => {
let div;
let store;
beforeEach(() => {
div = select('body').append('div');
store = configureStore(TEST_STATE_ONE_PARAM_CODE);
Bucknell, Mary S.
committed
div.call(drawGraphControls, store, '111111111', '72019');
});
it('Should not render the radio buttons', () => {
const radioButtons = selectAll('input[type="radio"]');
expect(radioButtons.size()).toBe(0);
});
});
describe('drawGraphControls with no param code', () => {
let div;
let store;
beforeEach(() => {
div = select('body').append('div');
store = configureStore(TEST_STATE_NO_DATA);
Bucknell, Mary S.
committed
div.call(drawGraphControls, store, '111111111', '72019');
});
it('Should not render the radio buttons', () => {
const radioButtons = selectAll('input[type="radio"]');
expect(radioButtons.size()).toBe(0);
});
});
});