2016-01-14 20:21:05 +08:00
|
|
|
///<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';
|
2016-02-04 21:36:19 +08:00
|
|
|
import {GraphCtrl} from '../module';
|
2016-01-14 20:21:05 +08:00
|
|
|
import helpers from '../../../../../test/specs/helpers';
|
|
|
|
|
|
|
|
|
|
describe('GraphCtrl', function() {
|
|
|
|
|
var ctx = new helpers.ControllerTestContext();
|
|
|
|
|
|
|
|
|
|
beforeEach(angularMocks.module('grafana.services'));
|
|
|
|
|
beforeEach(angularMocks.module('grafana.controllers'));
|
2017-01-17 05:27:35 +08:00
|
|
|
beforeEach(angularMocks.module(function($compileProvider) {
|
|
|
|
|
$compileProvider.preAssignBindingsEnabled(true);
|
|
|
|
|
}));
|
2016-01-14 20:21:05 +08:00
|
|
|
|
|
|
|
|
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-01-14 20:21:05 +08:00
|
|
|
});
|
2016-03-01 17:09:14 +08:00
|
|
|
|
2016-09-27 20:39:51 +08:00
|
|
|
describe('when time series are outside range', function() {
|
2016-03-01 17:09:14 +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]]},
|
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-03-01 17:09:14 +08:00
|
|
|
});
|
|
|
|
|
|
2016-09-27 20:39:51 +08:00
|
|
|
it('should set datapointsOutside', function() {
|
|
|
|
|
expect(ctx.ctrl.datapointsOutside).to.be(true);
|
2016-03-01 17:09:14 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-09-27 20:39:51 +08:00
|
|
|
describe('when time series are inside range', function() {
|
2016-03-01 17:09:14 +08:00
|
|
|
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-03-01 17:09:14 +08:00
|
|
|
});
|
|
|
|
|
|
2016-09-27 20:39:51 +08:00
|
|
|
it('should set datapointsOutside', function() {
|
|
|
|
|
expect(ctx.ctrl.datapointsOutside).to.be(false);
|
2016-03-01 17:09:14 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-14 20:21:05 +08:00
|
|
|
});
|