2018-06-11 08:59:20 -05:00
|
|
|
jest.mock('app/core/core', () => ({}));
|
2017-12-19 09:06:54 -06:00
|
|
|
|
2017-12-21 01:39:31 -06:00
|
|
|
import $ from 'jquery';
|
|
|
|
import GraphTooltip from '../graph_tooltip';
|
2017-12-19 09:06:54 -06:00
|
|
|
|
2018-08-26 11:43:07 -05:00
|
|
|
const scope = {
|
2018-06-11 08:59:20 -05:00
|
|
|
appEvent: jest.fn(),
|
|
|
|
onAppEvent: jest.fn(),
|
2017-12-21 01:39:31 -06:00
|
|
|
ctrl: {},
|
2016-01-14 06:21:05 -06:00
|
|
|
};
|
|
|
|
|
2018-08-26 11:43:07 -05:00
|
|
|
const elem = $('<div></div>');
|
|
|
|
const dashboard = {};
|
|
|
|
const getSeriesFn = () => {};
|
2016-01-14 06:21:05 -06:00
|
|
|
|
2019-06-27 06:21:04 -05:00
|
|
|
function describeSharedTooltip(desc: string, fn: any) {
|
2018-08-26 11:43:07 -05:00
|
|
|
const ctx: any = {};
|
2016-01-27 11:51:01 -06:00
|
|
|
ctx.ctrl = scope.ctrl;
|
2017-12-19 09:06:54 -06:00
|
|
|
ctx.ctrl.panel = {
|
|
|
|
tooltip: {
|
2017-12-21 01:39:31 -06:00
|
|
|
shared: true,
|
2016-01-14 06:21:05 -06:00
|
|
|
},
|
2017-12-19 09:06:54 -06:00
|
|
|
legend: {},
|
2017-12-21 01:39:31 -06:00
|
|
|
stack: false,
|
2016-01-14 06:21:05 -06:00
|
|
|
};
|
|
|
|
|
2019-06-27 06:21:04 -05:00
|
|
|
ctx.setup = (setupFn: any) => {
|
2016-01-14 06:21:05 -06:00
|
|
|
ctx.setupFn = setupFn;
|
|
|
|
};
|
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
describe(desc, () => {
|
|
|
|
beforeEach(() => {
|
2016-01-14 06:21:05 -06:00
|
|
|
ctx.setupFn();
|
2019-06-27 06:21:04 -05:00
|
|
|
// @ts-ignore
|
2018-08-26 11:43:07 -05:00
|
|
|
const tooltip = new GraphTooltip(elem, dashboard, scope, getSeriesFn);
|
2016-01-14 06:21:05 -06:00
|
|
|
ctx.results = tooltip.getMultiSeriesPlotHoverInfo(ctx.data, ctx.pos);
|
|
|
|
});
|
|
|
|
|
|
|
|
fn(ctx);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
describe('findHoverIndexFromData', () => {
|
2019-06-27 06:21:04 -05:00
|
|
|
// @ts-ignore
|
2018-08-26 11:43:07 -05:00
|
|
|
const tooltip = new GraphTooltip(elem, dashboard, scope, getSeriesFn);
|
|
|
|
const series = {
|
2019-11-19 07:59:39 -06:00
|
|
|
data: [
|
|
|
|
[100, 0],
|
|
|
|
[101, 0],
|
|
|
|
[102, 0],
|
|
|
|
[103, 0],
|
|
|
|
[104, 0],
|
|
|
|
[105, 0],
|
|
|
|
[106, 0],
|
|
|
|
[107, 0],
|
|
|
|
],
|
2017-12-19 09:06:54 -06:00
|
|
|
};
|
2017-01-19 03:02:42 -06:00
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
it('should return 0 if posX out of lower bounds', () => {
|
2018-08-26 11:43:07 -05:00
|
|
|
const posX = 99;
|
2018-06-11 08:59:20 -05:00
|
|
|
expect(tooltip.findHoverIndexFromData(posX, series)).toBe(0);
|
2017-01-19 03:02:42 -06:00
|
|
|
});
|
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
it('should return n - 1 if posX out of upper bounds', () => {
|
2018-08-26 11:43:07 -05:00
|
|
|
const posX = 108;
|
2018-06-11 08:59:20 -05:00
|
|
|
expect(tooltip.findHoverIndexFromData(posX, series)).toBe(series.data.length - 1);
|
2017-01-19 03:02:42 -06:00
|
|
|
});
|
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
it('should return i if posX in series', () => {
|
2018-08-26 11:43:07 -05:00
|
|
|
const posX = 104;
|
2018-06-11 08:59:20 -05:00
|
|
|
expect(tooltip.findHoverIndexFromData(posX, series)).toBe(4);
|
2017-01-19 03:02:42 -06:00
|
|
|
});
|
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
it('should return i if posX not in series and i + 1 > posX', () => {
|
2018-08-26 11:43:07 -05:00
|
|
|
const posX = 104.9;
|
2018-06-11 08:59:20 -05:00
|
|
|
expect(tooltip.findHoverIndexFromData(posX, series)).toBe(4);
|
2017-01-19 03:02:42 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-27 06:21:04 -05:00
|
|
|
describeSharedTooltip('steppedLine false, stack false', (ctx: any) => {
|
2018-09-04 08:55:41 -05:00
|
|
|
ctx.setup(() => {
|
2018-08-02 04:49:40 -05:00
|
|
|
ctx.data = [
|
2019-11-19 07:59:39 -06:00
|
|
|
{
|
|
|
|
data: [
|
|
|
|
[10, 15],
|
|
|
|
[12, 20],
|
|
|
|
],
|
|
|
|
lines: {},
|
|
|
|
hideTooltip: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: [
|
|
|
|
[10, 2],
|
|
|
|
[12, 3],
|
|
|
|
],
|
|
|
|
lines: {},
|
|
|
|
hideTooltip: false,
|
|
|
|
},
|
2018-08-02 04:49:40 -05:00
|
|
|
];
|
2016-01-14 06:21:05 -06:00
|
|
|
ctx.pos = { x: 11 };
|
|
|
|
});
|
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
it('should return 2 series', () => {
|
2018-06-11 08:59:20 -05:00
|
|
|
expect(ctx.results.length).toBe(2);
|
2016-01-14 06:21:05 -06:00
|
|
|
});
|
2016-01-27 11:51:01 -06:00
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
it('should add time to results array', () => {
|
2018-06-11 08:59:20 -05:00
|
|
|
expect(ctx.results.time).toBe(10);
|
2016-01-14 06:21:05 -06:00
|
|
|
});
|
2016-01-27 11:51:01 -06:00
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
it('should set value and hoverIndex', () => {
|
2018-06-11 08:59:20 -05:00
|
|
|
expect(ctx.results[0].value).toBe(15);
|
|
|
|
expect(ctx.results[1].value).toBe(2);
|
|
|
|
expect(ctx.results[0].hoverIndex).toBe(0);
|
2016-01-14 06:21:05 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-27 06:21:04 -05:00
|
|
|
describeSharedTooltip('one series is hidden', (ctx: any) => {
|
2018-09-04 08:55:41 -05:00
|
|
|
ctx.setup(() => {
|
2019-11-19 07:59:39 -06:00
|
|
|
ctx.data = [
|
|
|
|
{
|
|
|
|
data: [
|
|
|
|
[10, 15],
|
|
|
|
[12, 20],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ data: [] },
|
|
|
|
];
|
2016-01-14 06:21:05 -06:00
|
|
|
ctx.pos = { x: 11 };
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-27 06:21:04 -05:00
|
|
|
describeSharedTooltip('steppedLine false, stack true, individual false', (ctx: any) => {
|
2018-09-04 08:55:41 -05:00
|
|
|
ctx.setup(() => {
|
2017-12-21 01:39:31 -06:00
|
|
|
ctx.data = [
|
|
|
|
{
|
2019-11-19 07:59:39 -06:00
|
|
|
data: [
|
|
|
|
[10, 15],
|
|
|
|
[12, 20],
|
|
|
|
],
|
2017-12-21 01:39:31 -06:00
|
|
|
lines: {},
|
|
|
|
datapoints: {
|
|
|
|
pointsize: 2,
|
2019-11-19 07:59:39 -06:00
|
|
|
points: [
|
|
|
|
[10, 15],
|
|
|
|
[12, 20],
|
|
|
|
],
|
2016-01-14 06:21:05 -06:00
|
|
|
},
|
2017-12-21 01:39:31 -06:00
|
|
|
stack: true,
|
2018-08-02 04:49:40 -05:00
|
|
|
hideTooltip: false,
|
2017-12-21 01:39:31 -06:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 07:59:39 -06:00
|
|
|
data: [
|
|
|
|
[10, 2],
|
|
|
|
[12, 3],
|
|
|
|
],
|
2017-12-21 01:39:31 -06:00
|
|
|
lines: {},
|
|
|
|
datapoints: {
|
|
|
|
pointsize: 2,
|
2019-11-19 07:59:39 -06:00
|
|
|
points: [
|
|
|
|
[10, 2],
|
|
|
|
[12, 3],
|
|
|
|
],
|
2017-12-21 01:39:31 -06:00
|
|
|
},
|
|
|
|
stack: true,
|
2018-08-02 04:49:40 -05:00
|
|
|
hideTooltip: false,
|
2017-12-21 01:39:31 -06:00
|
|
|
},
|
|
|
|
];
|
|
|
|
ctx.ctrl.panel.stack = true;
|
|
|
|
ctx.pos = { x: 11 };
|
|
|
|
});
|
2016-01-14 06:21:05 -06:00
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
it('should show stacked value', () => {
|
2018-06-11 08:59:20 -05:00
|
|
|
expect(ctx.results[1].value).toBe(17);
|
2017-12-21 01:39:31 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-27 06:21:04 -05:00
|
|
|
describeSharedTooltip('steppedLine false, stack true, individual false, series stack false', (ctx: any) => {
|
2018-09-04 08:55:41 -05:00
|
|
|
ctx.setup(() => {
|
2017-12-21 01:39:31 -06:00
|
|
|
ctx.data = [
|
|
|
|
{
|
2019-11-19 07:59:39 -06:00
|
|
|
data: [
|
|
|
|
[10, 15],
|
|
|
|
[12, 20],
|
|
|
|
],
|
2017-12-21 01:39:31 -06:00
|
|
|
lines: {},
|
|
|
|
datapoints: {
|
|
|
|
pointsize: 2,
|
2019-11-19 07:59:39 -06:00
|
|
|
points: [
|
|
|
|
[10, 15],
|
|
|
|
[12, 20],
|
|
|
|
],
|
2016-01-14 06:21:05 -06:00
|
|
|
},
|
2017-12-21 01:39:31 -06:00
|
|
|
stack: true,
|
2018-08-02 04:49:40 -05:00
|
|
|
hideTooltip: false,
|
2017-12-21 01:39:31 -06:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 07:59:39 -06:00
|
|
|
data: [
|
|
|
|
[10, 2],
|
|
|
|
[12, 3],
|
|
|
|
],
|
2017-12-21 01:39:31 -06:00
|
|
|
lines: {},
|
|
|
|
datapoints: {
|
|
|
|
pointsize: 2,
|
2019-11-19 07:59:39 -06:00
|
|
|
points: [
|
|
|
|
[10, 2],
|
|
|
|
[12, 3],
|
|
|
|
],
|
2017-12-21 01:39:31 -06:00
|
|
|
},
|
|
|
|
stack: false,
|
2018-08-02 04:49:40 -05:00
|
|
|
hideTooltip: false,
|
2017-12-21 01:39:31 -06:00
|
|
|
},
|
|
|
|
];
|
|
|
|
ctx.ctrl.panel.stack = true;
|
|
|
|
ctx.pos = { x: 11 };
|
|
|
|
});
|
2016-01-14 06:21:05 -06:00
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
it('should not show stacked value', () => {
|
2018-06-11 08:59:20 -05:00
|
|
|
expect(ctx.results[1].value).toBe(2);
|
2017-12-21 01:39:31 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-27 06:21:04 -05:00
|
|
|
describeSharedTooltip('steppedLine false, stack true, individual true', (ctx: any) => {
|
2018-09-04 08:55:41 -05:00
|
|
|
ctx.setup(() => {
|
2017-12-21 01:39:31 -06:00
|
|
|
ctx.data = [
|
|
|
|
{
|
2019-11-19 07:59:39 -06:00
|
|
|
data: [
|
|
|
|
[10, 15],
|
|
|
|
[12, 20],
|
|
|
|
],
|
2017-12-21 01:39:31 -06:00
|
|
|
lines: {},
|
|
|
|
datapoints: {
|
|
|
|
pointsize: 2,
|
2019-11-19 07:59:39 -06:00
|
|
|
points: [
|
|
|
|
[10, 15],
|
|
|
|
[12, 20],
|
|
|
|
],
|
2016-01-14 06:21:05 -06:00
|
|
|
},
|
2017-12-21 01:39:31 -06:00
|
|
|
stack: true,
|
2018-08-02 04:49:40 -05:00
|
|
|
hideTooltip: false,
|
2017-12-21 01:39:31 -06:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 07:59:39 -06:00
|
|
|
data: [
|
|
|
|
[10, 2],
|
|
|
|
[12, 3],
|
|
|
|
],
|
2017-12-21 01:39:31 -06:00
|
|
|
lines: {},
|
|
|
|
datapoints: {
|
|
|
|
pointsize: 2,
|
2019-11-19 07:59:39 -06:00
|
|
|
points: [
|
|
|
|
[10, 2],
|
|
|
|
[12, 3],
|
|
|
|
],
|
2017-12-21 01:39:31 -06:00
|
|
|
},
|
|
|
|
stack: false,
|
2018-08-02 04:49:40 -05:00
|
|
|
hideTooltip: false,
|
2017-12-21 01:39:31 -06:00
|
|
|
},
|
|
|
|
];
|
|
|
|
ctx.ctrl.panel.stack = true;
|
|
|
|
ctx.ctrl.panel.tooltip.value_type = 'individual';
|
|
|
|
ctx.pos = { x: 11 };
|
|
|
|
});
|
2016-01-14 06:21:05 -06:00
|
|
|
|
2018-09-04 08:55:41 -05:00
|
|
|
it('should not show stacked value', () => {
|
2018-06-11 08:59:20 -05:00
|
|
|
expect(ctx.results[1].value).toBe(2);
|
2017-12-21 01:39:31 -06:00
|
|
|
});
|
|
|
|
});
|