Newer
Older
import { select } from 'd3-selection';
import { Actions, configureStore } from '../../store';
import { createTooltipText, createTooltipFocus, tooltipPointsSelector } from './tooltip';
Naab, Daniel James
committed
describe('Hydrograph tooltip module', () => {
let data = [12, 13, 14, 15, 16].map(hour => {
return {
dateTime: new Date(`2018-01-03T${hour}:00:00.000Z`).getTime(),
Naab, Daniel James
committed
qualifiers: ['P'],
value: hour
};
});
dateTime: new Date('2018-01-03T17:00:00.000Z').getTime(),
qualifiers: ['Fld', 'P'],
value: null
},
{
dateTime: new Date('2018-01-03T18:00:00.000Z').getTime(),
qualifiers: ['Mnt', 'P'],
value: null
}
];
data = data.concat(maskedData);
Naab, Daniel James
committed
const testState = {
series: {
timeSeries: {
Bucknell, Mary S.
committed
'69928:current:P7D': {
Bucknell, Mary S.
committed
variable: '00060id',
methodID: 69928
Naab, Daniel James
committed
},
Bucknell, Mary S.
committed
'69928:compare:P7D': {
Bucknell, Mary S.
committed
variable: '00060id',
methodID: 69928
Bucknell, Mary S.
committed
'69929:current:P7D': {
points: data,
tsKey: 'current:P7D',
Bucknell, Mary S.
committed
variable: '00010id',
methodID: 69929
Bucknell, Mary S.
committed
'69929:compare:P7D': {
points: data,
tsKey: 'compare:P7D',
Bucknell, Mary S.
committed
variable: '00010id',
methodID: 69929
Naab, Daniel James
committed
}
},
timeSeriesCollections: {
Naab, Daniel James
committed
variable: '00060id',
timeSeries: ['00060:current']
},
Naab, Daniel James
committed
variable: '00060id',
timeSeries: ['00060:compare']
}
},
Bucknell, Mary S.
committed
methods: {
69928: {
methodDescription: '',
methodID: 69928
},
69929: {
methodDescription: '',
methodID: 69929
}
},
Naab, Daniel James
committed
variables: {
'00060id': {
oid: '00060id',
variableCode: {
value: '00060'
},
unit: {
unitCode: 'ft3/s'
}
},
'00010id': {
oid: '00010id',
variableCode: {
value: '00010'
},
unit: {
unitCode: 'deg C'
}
Naab, Daniel James
committed
}
},
requests: {
Naab, Daniel James
committed
timeSeriesCollections: ['current']
},
Naab, Daniel James
committed
timeSeriesCollections: ['compare']
}
},
Naab, Daniel James
committed
queryInfo: {
Naab, Daniel James
committed
notes: {
'filter:timeRange': {
mode: 'RANGE',
interval: {
start: new Date('2018-01-03T12:00:00.000Z').getTime(),
end: new Date('2018-01-03T16:00:00.000Z').getTime()
Naab, Daniel James
committed
}
}
}
},
Naab, Daniel James
committed
notes: {
'filter:timeRange': {
mode: 'RANGE',
interval: {
start: new Date('2018-01-03T12:00:00.000Z').getTime(),
end: new Date('2018-01-03T16:00:00.000Z').getTime()
Naab, Daniel James
committed
}
}
}
}
},
Naab, Daniel James
committed
qualifiers: {
'P': {
qualifierCode: 'P',
qualifierDescription: 'Provisional data subject to revision.',
qualifierID: 0,
network: 'NWIS',
vocabulary: 'uv_rmk_cd'
},
'Fld': {
qualifierCode: 'Fld',
qualifierDescription: 'Flood',
qualifierId: 0,
network: 'NWIS',
vocabulary: 'uv_rmk_cd'
},
'Mnt': {
qualifierCode: 'Mnt',
qualifierDescription: 'Maintenance',
qualifierId: 0,
network: 'NWIS',
vocabulary: 'uv_rmk_cd'
Naab, Daniel James
committed
}
}
},
showSeries: {
current: true,
compare: true
},
Bucknell, Mary S.
committed
currentMethodID: 69928,
currentDateRange: 'P7D',
customTimeRange: null
},
ui: {
windowWidth: 1300,
width: 990,
hydrographXRange: undefined
}
Naab, Daniel James
committed
};
Naab, Daniel James
committed
describe('tooltipPointsSelector', () => {
const id = (val) => val;
Bucknell, Mary S.
committed
it('should return the requested time series focus time', () => {
expect(tooltipPointsSelector('current').resultFunc(id, id, {
'00060:current': {
dateTime: '1date',
value: 1
},
'00060:compare': {
dateTime: '2date',
value: 2
}
})).toEqual([{
Naab, Daniel James
committed
x: '1date',
Bucknell, Mary S.
committed
y: 1
Naab, Daniel James
committed
}, {
x: '2date',
Bucknell, Mary S.
committed
y: 2
Naab, Daniel James
committed
}]);
Bucknell, Mary S.
committed
});
it('should exclude values that are infinite', () => {
expect(tooltipPointsSelector('current').resultFunc(id, id, {
'00060:current': {
dateTime: '1date',
value: Infinity
},
'00060:compare': {
dateTime: '2date',
value: 2
}
})).toEqual([{
Bucknell, Mary S.
committed
y: 2
Bucknell, Mary S.
committed
});
describe('createTooltipText', () => {
Naab, Daniel James
committed
let div;
beforeEach(() => {
Naab, Daniel James
committed
div = select('body').append('div');
Bucknell, Mary S.
committed
});
afterEach(() => {
Naab, Daniel James
committed
div.remove();
Bucknell, Mary S.
committed
});
Naab, Daniel James
committed
it('Creates the container for tooltips', () => {
Bucknell, Mary S.
committed
let store = configureStore({
cursorOffset: null,
showSeries: {
current: true
}
}
Bucknell, Mary S.
committed
});
Bucknell, Mary S.
committed
div.call(createTooltipText, store);
Naab, Daniel James
committed
Naab, Daniel James
committed
const textGroup = div.selectAll('.tooltip-text-group');
Naab, Daniel James
committed
expect(textGroup.size()).toBe(1);
Bucknell, Mary S.
committed
});
it('Creates the text elements with the label for the focus times', () => {
Naab, Daniel James
committed
let store = configureStore(Object.assign({}, testState, {
timeSeriesState: Object.assign({}, testState.timeSeriesState, {
cursorOffset: 2 * 60 * 60 * 1000
})
Naab, Daniel James
committed
}));
Bucknell, Mary S.
committed
Bucknell, Mary S.
committed
div.call(createTooltipText, store);
Bucknell, Mary S.
committed
Naab, Daniel James
committed
let value = div.select('.current-tooltip-text').text().split(' - ')[0];
Naab, Daniel James
committed
expect(value).toBe('14 ft3/s');
Naab, Daniel James
committed
value = div.select('.compare-tooltip-text').text().split(' - ')[0];
Naab, Daniel James
committed
expect(value).toBe('14 ft3/s');
Bucknell, Mary S.
committed
});
it('Creates the text elements with the label for the focus times when there is a second axis', () => {
let store = configureStore(Object.assign({}, testState, {
timeSeriesState: Object.assign({}, testState.timeSeriesState, {
cursorOffset: 2 * 60 * 60 * 1000,
Bucknell, Mary S.
committed
currentVariableID: '00010id',
currentMethodID: 69929
Bucknell, Mary S.
committed
div.call(createTooltipText, store);
let value = div.select('.current-tooltip-text').text().split(' - ')[0];
expect(value).toBe('14 deg C (57.2 deg F)');
value = div.select('.compare-tooltip-text').text().split(' - ')[0];
expect(value).toBe('14 deg C (57.2 deg F)');
});
Bucknell, Mary S.
committed
it('Text contents are updated when the store is provided with new focus times', (done) => {
Naab, Daniel James
committed
let store = configureStore(Object.assign({}, testState, {
timeSeriesState: Object.assign({}, testState.timeSeriesState, {
cursorOffset: 1
})
Naab, Daniel James
committed
}));
Bucknell, Mary S.
committed
Bucknell, Mary S.
committed
div.call(createTooltipText, store);
Bucknell, Mary S.
committed
Naab, Daniel James
committed
let value = div.select('.current-tooltip-text').text().split(' - ')[0];
Naab, Daniel James
committed
expect(value).toBe('12 ft3/s');
store.dispatch(Actions.setCursorOffset(3 * 60 * 60 * 1000));
Bucknell, Mary S.
committed
window.requestAnimationFrame(() => {
value = div.select('.current-tooltip-text').text().split(' - ')[0];
expect(value).toBe('15 ft3/s');
Naab, Daniel James
committed
Bucknell, Mary S.
committed
value = div.select('.compare-tooltip-text').text().split(' - ')[0];
expect(value).toBe('15 ft3/s');
done();
});
Bucknell, Mary S.
committed
});
Bucknell, Mary S.
committed
it('Shows the qualifier text if focus is near masked data points', (done) => {
Naab, Daniel James
committed
let store = configureStore(Object.assign({}, testState, {
timeSeriesState: Object.assign({}, testState.timeSeriesState, {
cursorOffset: 1
})
Naab, Daniel James
committed
}));
Bucknell, Mary S.
committed
div.call(createTooltipText, store);
Naab, Daniel James
committed
store.dispatch(Actions.setCursorOffset(299 * 60 * 1000)); // 2018-01-03T16:59:00.000Z
Bucknell, Mary S.
committed
window.requestAnimationFrame(() => {
expect(div.select('.current-tooltip-text').text()).toContain('Flood');
done();
});
Bucknell, Mary S.
committed
Bucknell, Mary S.
committed
it('Creates the correct text for values of zero', (done) => {
Bucknell, Mary S.
committed
const zeroData = [12, 13, 14, 15, 16].map(hour => {
return {
dateTime: new Date(`2018-01-03T${hour}:00:00.000Z`).getTime(),
Bucknell, Mary S.
committed
qualifiers: ['P'],
value: 0
};
});
let store = configureStore(Object.assign({}, testState, {
series: Object.assign({}, testState.series, {
timeSeries: Object.assign({}, testState.series.timeSeries, {
Bucknell, Mary S.
committed
'69928:current:P7D': Object.assign({}, testState.series.timeSeries['69928:current:P7D'], {
Bucknell, Mary S.
committed
points: zeroData
})
})
}),
timeSeriesState: Object.assign({}, testState.timeSeriesState, {
cursorOffset: 10
})
}));
Bucknell, Mary S.
committed
div.call(createTooltipText, store);
store.dispatch(Actions.setCursorOffset(119 * 60 * 1000));
Bucknell, Mary S.
committed
window.requestAnimationFrame(() => {
let value = div.select('.current-tooltip-text').text().split(' - ')[0];
Bucknell, Mary S.
committed
Bucknell, Mary S.
committed
expect(value).toBe('0 ft3/s');
done();
});
Bucknell, Mary S.
committed
});
Bucknell, Mary S.
committed
});
describe('createTooltipFocus', () => {
Naab, Daniel James
committed
let svg, currentTsData, compareTsData;
Bucknell, Mary S.
committed
beforeEach(() => {
svg = select('body').append('svg');
currentTsData = data;
compareTsData = [12, 13, 14, 15, 16].map(hour => {
return {
dateTime: new Date(`2017-01-03T${hour}:00:00.000Z`).getTime(),
value: hour + 1
};
});
});
afterEach(() => {
svg.remove();
});
it('Creates focus lines and focus circles when cursor not set', () => {
Naab, Daniel James
committed
let store = configureStore(Object.assign({}, testState, {
series: Object.assign({}, testState.series, {
timeSeries: Object.assign({}, testState.series.timeSeries, {
Bucknell, Mary S.
committed
'69928:current:P7D': {
Bucknell, Mary S.
committed
variable: '00060id',
methodID: 69928
Naab, Daniel James
committed
},
Bucknell, Mary S.
committed
'69928:compare:P7D': {
Bucknell, Mary S.
committed
variable: '00060id',
methodID: 69928
Naab, Daniel James
committed
}
Naab, Daniel James
committed
})
}),
timeSeriesState: Object.assign({}, testState.timeSeriesState, {
cursorOffset: null
})
Naab, Daniel James
committed
}));
Bucknell, Mary S.
committed
Bucknell, Mary S.
committed
svg.call(createTooltipFocus, store);
Bucknell, Mary S.
committed
expect(svg.selectAll('.focus-line').size()).toBe(1);
expect(svg.selectAll('.focus-circle').size()).toBe(2);
expect(svg.select('.focus-overlay').size()).toBe(1);
});
Naab, Daniel James
committed
it('Focus circles and line are displayed if cursor is set', () => {
let store = configureStore(Object.assign({}, testState, {
series: Object.assign({}, testState.series, {
timeSeries: Object.assign({}, testState.series.timeSeries, {
Bucknell, Mary S.
committed
'69928:current:P7D': {
Bucknell, Mary S.
committed
variable: '00060id',
methodID: 69928
Naab, Daniel James
committed
},
Bucknell, Mary S.
committed
'69928:compare:P7D': {
Bucknell, Mary S.
committed
variable: '00060id',
methodID: 69928
Naab, Daniel James
committed
})
}),
timeSeriesState: Object.assign({}, testState.timeSeriesState, {
cursorOffset: 39 * 60 * 1000
})
Naab, Daniel James
committed
}));
Bucknell, Mary S.
committed
Bucknell, Mary S.
committed
svg.call(createTooltipFocus, store);
expect(svg.selectAll('.focus-line').size()).toBe(1);
expect(svg.selectAll('.focus-circle').size()).toBe(2);
expect(svg.select('.focus-overlay').size()).toBe(1);
Bucknell, Mary S.
committed
});