grafana/public/app/plugins/panel/graph/specs/graph_ctrl_specs.ts

79 lines
2.2 KiB
TypeScript
Raw Normal View History

import { describe, beforeEach, it, expect, angularMocks } from '../../../../../test/lib/common';
import moment from 'moment';
import { GraphCtrl } from '../module';
import helpers from '../../../../../test/specs/helpers';
describe('GraphCtrl', function() {
var ctx = new helpers.ControllerTestContext();
beforeEach(angularMocks.module('grafana.services'));
beforeEach(angularMocks.module('grafana.controllers'));
beforeEach(
angularMocks.module(function($compileProvider) {
$compileProvider.preAssignBindingsEnabled(true);
})
);
beforeEach(ctx.providePhase());
2016-01-27 11:51:01 -06:00
beforeEach(ctx.createPanelController(GraphCtrl));
2016-03-22 15:27:53 -05:00
beforeEach(() => {
ctx.ctrl.annotationsPromise = Promise.resolve({});
ctx.ctrl.updateTimeRange();
});
describe('when time series are outside range', function() {
beforeEach(function() {
2016-03-22 15:27:53 -05:00
var data = [
{
target: 'test.cpu1',
datapoints: [[45, 1234567890], [60, 1234567899]],
},
2016-03-22 15:27:53 -05:00
];
2016-09-27 07:39:51 -05:00
ctx.ctrl.range = { from: moment().valueOf(), to: moment().valueOf() };
2016-03-22 15:27:53 -05:00
ctx.ctrl.onDataReceived(data);
});
it('should set datapointsOutside', function() {
expect(ctx.ctrl.dataWarning.title).to.be('Data points outside time range');
});
});
describe('when time series are inside range', function() {
beforeEach(function() {
2016-09-27 07:39:51 -05:00
var range = {
from: moment()
.subtract(1, 'days')
.valueOf(),
to: moment().valueOf(),
2016-09-27 07:39:51 -05:00
};
2016-03-22 15:27:53 -05:00
var data = [
{
target: 'test.cpu1',
datapoints: [[45, range.from + 1000], [60, range.from + 10000]],
},
2016-03-22 15:27:53 -05:00
];
2016-09-27 07:39:51 -05:00
ctx.ctrl.range = range;
2016-03-22 15:27:53 -05:00
ctx.ctrl.onDataReceived(data);
});
it('should set datapointsOutside', function() {
2017-02-23 08:56:37 -06:00
expect(ctx.ctrl.dataWarning).to.be(null);
});
});
describe('datapointsCount given 2 series', function() {
2016-03-01 03:15:29 -06:00
beforeEach(function() {
var data = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }];
2016-03-22 15:27:53 -05:00
ctx.ctrl.onDataReceived(data);
2016-03-01 03:15:29 -06:00
});
it('should set datapointsCount warning', function() {
expect(ctx.ctrl.dataWarning.title).to.be('No data points');
2016-03-01 03:15:29 -06:00
});
});
});