Commit a17a9218 by Marcus Efraimsson Committed by GitHub

Merge pull request #12692 from dehrax/12224-graph-ctrl

Karma to Jest: graph_ctrl
parents 76bc02b3 47bec0fd
import { describe, beforeEach, it, expect, angularMocks } from '../../../../../test/lib/common';
import moment from 'moment'; import moment from 'moment';
import { GraphCtrl } from '../module'; import { GraphCtrl } from '../module';
import helpers from '../../../../../test/specs/helpers';
describe('GraphCtrl', function() { jest.mock('../graph', () => ({}));
var ctx = new helpers.ControllerTestContext();
describe('GraphCtrl', () => {
let injector = {
get: () => {
return {
timeRange: () => {
return {
from: '',
to: '',
};
},
};
},
};
let scope = {
$on: () => {},
};
GraphCtrl.prototype.panel = {
events: {
on: () => {},
},
gridPos: {
w: 100,
},
};
beforeEach(angularMocks.module('grafana.services')); let ctx = <any>{};
beforeEach(angularMocks.module('grafana.controllers'));
beforeEach(
angularMocks.module(function($compileProvider) {
$compileProvider.preAssignBindingsEnabled(true);
})
);
beforeEach(ctx.providePhase());
beforeEach(ctx.createPanelController(GraphCtrl));
beforeEach(() => { beforeEach(() => {
ctx.ctrl = new GraphCtrl(scope, injector, {});
ctx.ctrl.annotationsPromise = Promise.resolve({}); ctx.ctrl.annotationsPromise = Promise.resolve({});
ctx.ctrl.updateTimeRange(); ctx.ctrl.updateTimeRange();
}); });
describe('when time series are outside range', function() { describe('when time series are outside range', () => {
beforeEach(function() { beforeEach(() => {
var data = [ var data = [
{ {
target: 'test.cpu1', target: 'test.cpu1',
...@@ -35,13 +51,13 @@ describe('GraphCtrl', function() { ...@@ -35,13 +51,13 @@ describe('GraphCtrl', function() {
ctx.ctrl.onDataReceived(data); ctx.ctrl.onDataReceived(data);
}); });
it('should set datapointsOutside', function() { it('should set datapointsOutside', () => {
expect(ctx.ctrl.dataWarning.title).to.be('Data points outside time range'); expect(ctx.ctrl.dataWarning.title).toBe('Data points outside time range');
}); });
}); });
describe('when time series are inside range', function() { describe('when time series are inside range', () => {
beforeEach(function() { beforeEach(() => {
var range = { var range = {
from: moment() from: moment()
.subtract(1, 'days') .subtract(1, 'days')
...@@ -60,19 +76,19 @@ describe('GraphCtrl', function() { ...@@ -60,19 +76,19 @@ describe('GraphCtrl', function() {
ctx.ctrl.onDataReceived(data); ctx.ctrl.onDataReceived(data);
}); });
it('should set datapointsOutside', function() { it('should set datapointsOutside', () => {
expect(ctx.ctrl.dataWarning).to.be(null); expect(ctx.ctrl.dataWarning).toBe(null);
}); });
}); });
describe('datapointsCount given 2 series', function() { describe('datapointsCount given 2 series', () => {
beforeEach(function() { beforeEach(() => {
var data = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }]; var data = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }];
ctx.ctrl.onDataReceived(data); ctx.ctrl.onDataReceived(data);
}); });
it('should set datapointsCount warning', function() { it('should set datapointsCount warning', () => {
expect(ctx.ctrl.dataWarning.title).to.be('No data points'); expect(ctx.ctrl.dataWarning.title).toBe('No data points');
}); });
}); });
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment