mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* WIP: initial commit * Fix: Fixed $timeout call when testing snapshots * Chore: reverts changes to metrics_panel_ctrl.ts * Chore: reverts changes to annotations_srv * Refactor: adds DashboardQueryRunner.run to initdashboard * Refactor: adds run to dashboard model start refresh * Refactor: move to own folder and split up into smaller files * Tests: adds tests for LegacyAnnotationQueryRunner * Tests: adds tests for AnnotationsQueryRunner * Tests: adds tests for SnapshotWorker * Refactor: renames from canRun|run to canWork|work * Tests: adds tests for AlertStatesWorker * Tests: adds tests for AnnotationsWorker * Refactor: renames operators * Refactor: renames operators * Tests: adds tests for DashboardQueryRunner * Refactor: adds mergePanelAndDashboardData function * Tests: fixes broken tests * Chore: Fixes errors after merge with master * Chore: Removes usage of AnnotationSrv from event_editor and initDashboard * WIP: getting annotations and alerts working in graph (snapshot not working) * Refactor: fixes snapshot data for React panels * Refactor: Fixes so snapshots work for Graph * Refactor: moves alert types to grafana-data * Refactor: changes to some for readability * Tests: skipping tests for now, needs rewrite * Refactor: refactors out common static functions to utils * Refactor: fixes resolving annotations from dataframes * Refactor: removes getRunners/Workers functions * Docs: fixes docs errors * Docs: trying to fix doc error * Refactor: changes after PR comments * Refactor: hides everything behind a factory instead * Refactor: adds cancellation between runs and explicitly
150 lines
3.2 KiB
TypeScript
150 lines
3.2 KiB
TypeScript
import { GraphCtrl } from '../module';
|
|
import { dateTime } from '@grafana/data';
|
|
import TimeSeries from 'app/core/time_series2';
|
|
|
|
jest.mock('../graph', () => ({}));
|
|
|
|
describe.skip('GraphCtrl', () => {
|
|
const injector = {
|
|
get: () => {
|
|
return {
|
|
timeRange: () => {
|
|
return {
|
|
from: '',
|
|
to: '',
|
|
};
|
|
},
|
|
};
|
|
},
|
|
};
|
|
|
|
GraphCtrl.prototype.panel = {
|
|
events: {
|
|
on: () => {},
|
|
emit: () => {},
|
|
},
|
|
gridPos: {
|
|
w: 100,
|
|
},
|
|
fieldConfig: {
|
|
defaults: {},
|
|
},
|
|
};
|
|
|
|
const scope: any = {
|
|
$on: () => {},
|
|
$parent: {
|
|
panel: GraphCtrl.prototype.panel,
|
|
dashboard: {},
|
|
},
|
|
};
|
|
|
|
const ctx = {} as any;
|
|
|
|
beforeEach(() => {
|
|
ctx.ctrl = new GraphCtrl(scope, injector as any);
|
|
ctx.ctrl.events = {
|
|
emit: () => {},
|
|
};
|
|
ctx.ctrl.panelData = {};
|
|
ctx.ctrl.updateTimeRange();
|
|
});
|
|
|
|
describe('when time series are outside range', () => {
|
|
beforeEach(() => {
|
|
const data = [
|
|
{
|
|
target: 'test.cpu1',
|
|
datapoints: [
|
|
[45, 1234567890],
|
|
[60, 1234567899],
|
|
],
|
|
},
|
|
];
|
|
|
|
ctx.ctrl.range = { from: dateTime().valueOf(), to: dateTime().valueOf() };
|
|
ctx.ctrl.onDataSnapshotLoad(data);
|
|
});
|
|
|
|
it('should set datapointsOutside', () => {
|
|
expect(ctx.ctrl.dataWarning.title).toBe('Data outside time range');
|
|
});
|
|
});
|
|
|
|
describe('when time series are inside range', () => {
|
|
beforeEach(() => {
|
|
const range = {
|
|
from: dateTime().subtract(1, 'days').valueOf(),
|
|
to: dateTime().valueOf(),
|
|
};
|
|
|
|
const data = [
|
|
{
|
|
target: 'test.cpu1',
|
|
datapoints: [
|
|
[45, range.from + 1000],
|
|
[60, range.from + 10000],
|
|
],
|
|
},
|
|
];
|
|
|
|
ctx.ctrl.range = range;
|
|
ctx.ctrl.onDataSnapshotLoad(data);
|
|
});
|
|
|
|
it('should set datapointsOutside', () => {
|
|
expect(ctx.ctrl.dataWarning).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('datapointsCount given 2 series', () => {
|
|
beforeEach(() => {
|
|
const data: any = [
|
|
{ target: 'test.cpu1', datapoints: [] },
|
|
{ target: 'test.cpu2', datapoints: [] },
|
|
];
|
|
ctx.ctrl.onDataSnapshotLoad(data);
|
|
});
|
|
|
|
it('should set datapointsCount warning', () => {
|
|
expect(ctx.ctrl.dataWarning.title).toBe('No data');
|
|
});
|
|
});
|
|
|
|
describe('when data is exported to CSV', () => {
|
|
const appEventMock = jest.fn();
|
|
|
|
beforeEach(() => {
|
|
appEventMock.mockReset();
|
|
scope.$root = { appEvent: appEventMock };
|
|
scope.$new = () => ({});
|
|
const data = [
|
|
{
|
|
target: 'test.normal',
|
|
datapoints: [
|
|
[10, 1],
|
|
[10, 2],
|
|
],
|
|
},
|
|
{
|
|
target: 'test.nulls',
|
|
datapoints: [
|
|
[null, 1],
|
|
[null, 2],
|
|
],
|
|
},
|
|
{
|
|
target: 'test.zeros',
|
|
datapoints: [
|
|
[0, 1],
|
|
[0, 2],
|
|
],
|
|
},
|
|
];
|
|
ctx.ctrl.onDataSnapshotLoad(data);
|
|
// allIsNull / allIsZero are set by getFlotPairs
|
|
ctx.ctrl.seriesList.forEach((series: TimeSeries) => series.getFlotPairs(''));
|
|
});
|
|
});
|
|
});
|