grafana/public/app/plugins/panel/graph/specs/graph_ctrl.test.ts

98 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-07-23 04:06:30 -05:00
import { GraphCtrl } from '../module';
import { dateTime } from '@grafana/ui/src/utils/moment_wrapper';
2018-07-23 04:06:30 -05:00
2018-07-23 06:38:16 -05:00
jest.mock('../graph', () => ({}));
2018-07-23 08:42:47 -05:00
describe('GraphCtrl', () => {
const injector = {
2018-07-23 06:38:16 -05:00
get: () => {
return {
timeRange: () => {
return {
from: '',
to: '',
};
},
};
},
};
const scope = {
2018-07-23 06:39:32 -05:00
$on: () => {},
2018-07-23 06:38:16 -05:00
};
GraphCtrl.prototype.panel = {
events: {
2018-07-23 06:39:32 -05:00
on: () => {},
2018-07-23 06:38:16 -05:00
},
gridPos: {
w: 100,
},
};
const ctx = {} as any;
2018-07-23 04:06:30 -05:00
beforeEach(() => {
ctx.ctrl = new GraphCtrl(scope, injector as any, {} as any);
2018-07-27 08:16:19 -05:00
ctx.ctrl.events = {
emit: () => {},
};
2018-07-23 04:06:30 -05:00
ctx.ctrl.annotationsPromise = Promise.resolve({});
ctx.ctrl.updateTimeRange();
});
2018-07-23 08:42:47 -05:00
describe('when time series are outside range', () => {
beforeEach(() => {
const data = [
2018-07-23 04:06:30 -05:00
{
target: 'test.cpu1',
datapoints: [[45, 1234567890], [60, 1234567899]],
},
];
ctx.ctrl.range = { from: dateTime().valueOf(), to: dateTime().valueOf() };
2018-07-23 04:06:30 -05:00
ctx.ctrl.onDataReceived(data);
});
2018-07-23 08:42:47 -05:00
it('should set datapointsOutside', () => {
2018-07-23 04:06:30 -05:00
expect(ctx.ctrl.dataWarning.title).toBe('Data points outside time range');
});
});
2018-07-23 08:42:47 -05:00
describe('when time series are inside range', () => {
beforeEach(() => {
const range = {
from: dateTime()
2018-07-23 04:06:30 -05:00
.subtract(1, 'days')
.valueOf(),
to: dateTime().valueOf(),
2018-07-23 04:06:30 -05:00
};
const data = [
2018-07-23 04:06:30 -05:00
{
target: 'test.cpu1',
datapoints: [[45, range.from + 1000], [60, range.from + 10000]],
},
];
ctx.ctrl.range = range;
ctx.ctrl.onDataReceived(data);
});
2018-07-23 08:42:47 -05:00
it('should set datapointsOutside', () => {
2018-07-23 04:06:30 -05:00
expect(ctx.ctrl.dataWarning).toBe(null);
});
});
2018-07-23 08:42:47 -05:00
describe('datapointsCount given 2 series', () => {
beforeEach(() => {
const data: any = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }];
2018-07-23 04:06:30 -05:00
ctx.ctrl.onDataReceived(data);
});
2018-07-23 08:42:47 -05:00
it('should set datapointsCount warning', () => {
2018-07-23 04:06:30 -05:00
expect(ctx.ctrl.dataWarning.title).toBe('No data points');
});
});
});