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

77 lines
2.2 KiB
TypeScript
Raw Normal View History

///<reference path="../../../../headers/common.d.ts" />
import {describe, beforeEach, it, sinon, expect, angularMocks} from '../../../../../test/lib/common';
import angular from 'angular';
2016-09-27 20:39:51 +08:00
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-28 01:51:01 +08:00
beforeEach(ctx.createPanelController(GraphCtrl));
2016-03-23 04:27:53 +08:00
beforeEach(() => {
ctx.ctrl.annotationsPromise = Promise.resolve({});
ctx.ctrl.updateTimeRange();
});
2016-09-27 20:39:51 +08:00
describe('when time series are outside range', function() {
beforeEach(function() {
2016-03-23 04:27:53 +08:00
var data = [
2016-09-27 20:39:51 +08:00
{target: 'test.cpu1', datapoints: [[45, 1234567890], [60, 1234567899]]},
2016-03-23 04:27:53 +08:00
];
2016-09-27 20:39:51 +08:00
ctx.ctrl.range = {from: moment().valueOf(), to: moment().valueOf()};
2016-03-23 04:27:53 +08:00
ctx.ctrl.onDataReceived(data);
});
2016-09-27 20:39:51 +08:00
it('should set datapointsOutside', function() {
expect(ctx.ctrl.datapointsOutside).to.be(true);
});
});
2016-09-27 20:39:51 +08:00
describe('when time series are inside range', function() {
beforeEach(function() {
2016-09-27 20:39:51 +08:00
var range = {
from: moment().subtract(1, 'days').valueOf(),
to: moment().valueOf()
};
2016-03-23 04:27:53 +08:00
var data = [
2016-09-27 20:39:51 +08:00
{target: 'test.cpu1', datapoints: [[45, range.from + 1000], [60, range.from + 10000]]},
2016-03-23 04:27:53 +08:00
];
2016-09-27 20:39:51 +08:00
ctx.ctrl.range = range;
2016-03-23 04:27:53 +08:00
ctx.ctrl.onDataReceived(data);
});
2016-09-27 20:39:51 +08:00
it('should set datapointsOutside', function() {
expect(ctx.ctrl.datapointsOutside).to.be(false);
});
});
2016-09-27 20:39:51 +08:00
describe('datapointsCount given 2 series', function() {
2016-03-01 17:15:29 +08:00
beforeEach(function() {
2016-03-23 04:27:53 +08:00
var data = [
2016-09-27 20:39:51 +08:00
{target: 'test.cpu1', datapoints: [[45, 1234567890], [60, 1234567899]]},
{target: 'test.cpu2', datapoints: [[45, 1234567890]]},
2016-03-23 04:27:53 +08:00
];
ctx.ctrl.onDataReceived(data);
2016-03-01 17:15:29 +08:00
});
2016-09-27 20:39:51 +08:00
it('should set datapointsCount to sum of datapoints', function() {
expect(ctx.ctrl.datapointsCount).to.be(3);
2016-03-01 17:15:29 +08:00
});
});
});