mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add jest test file
This commit is contained in:
parent
dde484be60
commit
ae935bf08b
81
public/app/plugins/panel/graph/specs/graph_ctrl.jest.ts
Normal file
81
public/app/plugins/panel/graph/specs/graph_ctrl.jest.ts
Normal file
@ -0,0 +1,81 @@
|
||||
// import { describe, beforeEach, it, expect, angularMocks } from '../../../../../test/lib/common';
|
||||
|
||||
import moment from 'moment';
|
||||
import { GraphCtrl } from '../module';
|
||||
|
||||
describe('GraphCtrl', function() {
|
||||
let ctx = <any>{};
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.ctrl = new GraphCtrl({}, {}, {});
|
||||
});
|
||||
|
||||
// beforeEach(angularMocks.module('grafana.services'));
|
||||
// beforeEach(angularMocks.module('grafana.controllers'));
|
||||
// beforeEach(
|
||||
// angularMocks.module(function($compileProvider) {
|
||||
// $compileProvider.preAssignBindingsEnabled(true);
|
||||
// })
|
||||
// );
|
||||
|
||||
// beforeEach(ctx.providePhase());
|
||||
// beforeEach(ctx.createPanelController(GraphCtrl));
|
||||
beforeEach(() => {
|
||||
ctx.ctrl.annotationsPromise = Promise.resolve({});
|
||||
ctx.ctrl.updateTimeRange();
|
||||
});
|
||||
|
||||
describe('when time series are outside range', function() {
|
||||
beforeEach(function() {
|
||||
var data = [
|
||||
{
|
||||
target: 'test.cpu1',
|
||||
datapoints: [[45, 1234567890], [60, 1234567899]],
|
||||
},
|
||||
];
|
||||
|
||||
ctx.ctrl.range = { from: moment().valueOf(), to: moment().valueOf() };
|
||||
ctx.ctrl.onDataReceived(data);
|
||||
});
|
||||
|
||||
it('should set datapointsOutside', function() {
|
||||
expect(ctx.ctrl.dataWarning.title).toBe('Data points outside time range');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when time series are inside range', function() {
|
||||
beforeEach(function() {
|
||||
var range = {
|
||||
from: moment()
|
||||
.subtract(1, 'days')
|
||||
.valueOf(),
|
||||
to: moment().valueOf(),
|
||||
};
|
||||
|
||||
var data = [
|
||||
{
|
||||
target: 'test.cpu1',
|
||||
datapoints: [[45, range.from + 1000], [60, range.from + 10000]],
|
||||
},
|
||||
];
|
||||
|
||||
ctx.ctrl.range = range;
|
||||
ctx.ctrl.onDataReceived(data);
|
||||
});
|
||||
|
||||
it('should set datapointsOutside', function() {
|
||||
expect(ctx.ctrl.dataWarning).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('datapointsCount given 2 series', function() {
|
||||
beforeEach(function() {
|
||||
var data = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }];
|
||||
ctx.ctrl.onDataReceived(data);
|
||||
});
|
||||
|
||||
it('should set datapointsCount warning', function() {
|
||||
expect(ctx.ctrl.dataWarning.title).toBe('No data points');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user