influxdb/ui/test/annotations/helpersSpec.js

102 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-02-27 03:23:40 +00:00
import {visibleAnnotations} from 'shared/annotations/helpers'
2018-01-16 18:30:13 +00:00
import Dygraph from 'src/external/dygraph'
2018-01-17 00:26:53 +00:00
const start = 1515628800000
const end = 1516060800000
2018-01-16 18:30:13 +00:00
const timeSeries = [
2018-01-17 00:26:53 +00:00
[start, 25],
2018-01-16 18:30:13 +00:00
[1515715200000, 13],
[1515801600000, 10],
[1515888000000, 5],
[1515974400000, null],
2018-01-17 00:26:53 +00:00
[end, 14],
2018-01-16 18:30:13 +00:00
]
const labels = ['time', 'test.label']
const div = document.createElement('div')
const graph = new Dygraph(div, timeSeries, {labels})
const a1 = {
group: '',
2018-01-17 00:26:53 +00:00
name: 'a1',
time: '1515716160000',
duration: '',
2018-01-16 18:30:13 +00:00
text: 'you have no swoggels',
}
const a2 = {
group: '',
2018-01-17 00:26:53 +00:00
name: 'a2',
2018-01-16 18:30:13 +00:00
time: '1515716169000',
duration: '3600000', // 1 hour
text: 'you have no swoggels',
}
const annotations = [a1]
2018-01-17 00:26:53 +00:00
describe('Shared.Annotations.Helpers', () => {
2018-02-27 03:23:40 +00:00
describe('visibleAnnotations', () => {
2018-01-16 18:30:13 +00:00
it('returns an empty array with no graph or annotations are provided', () => {
2018-02-27 03:23:40 +00:00
const actual = visibleAnnotations(undefined, annotations)
2018-01-16 18:30:13 +00:00
const expected = []
2018-03-05 15:37:46 +00:00
expect(actual).toEqual(expected)
2018-01-16 18:30:13 +00:00
})
it('returns an annotation if it is in the time range', () => {
2018-02-27 03:23:40 +00:00
const actual = visibleAnnotations(graph, annotations)
2018-01-16 18:30:13 +00:00
const expected = annotations
2018-03-05 15:37:46 +00:00
expect(actual).toEqual(expected)
2018-01-16 18:30:13 +00:00
})
2018-01-17 00:26:53 +00:00
it('removes an annotation if it is out of the time range', () => {
const outOfBounds = {
group: '',
name: 'not in time range',
time: '2515716169000',
duration: '',
}
const newAnnos = [...annotations, outOfBounds]
2018-02-27 03:23:40 +00:00
const actual = visibleAnnotations(graph, newAnnos)
2018-01-17 00:26:53 +00:00
const expected = annotations
2018-03-05 15:37:46 +00:00
expect(actual).toEqual(expected)
2018-01-17 00:26:53 +00:00
})
describe('with a duration', () => {
it('it adds an annotation', () => {
const withDurations = [...annotations, a2]
2018-02-27 03:23:40 +00:00
const actual = visibleAnnotations(graph, withDurations)
2018-01-17 00:26:53 +00:00
const expectedAnnotation = {
...a2,
time: `${Number(a2.time) + Number(a2.duration)}`,
duration: '',
}
const expected = [...withDurations, expectedAnnotation]
2018-03-05 15:37:46 +00:00
expect(actual).toEqual(expected)
2018-01-17 00:26:53 +00:00
})
it('does not add a duration annotation if it is out of bounds', () => {
const annotationWithOutOfBoundsDuration = {
...a2,
duration: a2.time,
}
const withDurations = [
...annotations,
annotationWithOutOfBoundsDuration,
]
2018-02-27 03:23:40 +00:00
const actual = visibleAnnotations(graph, withDurations)
2018-01-17 00:26:53 +00:00
const expected = withDurations
2018-03-05 15:37:46 +00:00
expect(actual).toEqual(expected)
2018-01-17 00:26:53 +00:00
})
})
2018-01-16 18:30:13 +00:00
})
})