| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- ///<reference path="../../../../headers/common.d.ts" />
- import {describe, beforeEach, it, sinon, expect, angularMocks} from '../../../../../test/lib/common';
- import angular from 'angular';
- import helpers from '../../../../../test/specs/helpers';
- import {SingleStatCtrl} from '../module';
- describe('SingleStatCtrl', function() {
- var ctx = new helpers.ControllerTestContext();
- function singleStatScenario(desc, func) {
- describe(desc, function() {
- ctx.setup = function (setupFunc) {
- beforeEach(angularMocks.module('grafana.services'));
- beforeEach(angularMocks.module('grafana.controllers'));
- beforeEach(ctx.providePhase());
- beforeEach(ctx.createPanelController(SingleStatCtrl));
- beforeEach(function() {
- setupFunc();
- var data = [
- {target: 'test.cpu1', datapoints: ctx.datapoints}
- ];
- ctx.ctrl.onDataReceived(data);
- ctx.data = ctx.ctrl.data;
- });
- };
- func(ctx);
- });
- }
- singleStatScenario('with defaults', function(ctx) {
- ctx.setup(function() {
- ctx.datapoints = [[10,1], [20,2]];
- });
- it('Should use series avg as default main value', function() {
- expect(ctx.data.value).to.be(15);
- expect(ctx.data.valueRounded).to.be(15);
- });
- it('should set formated falue', function() {
- expect(ctx.data.valueFormated).to.be('15');
- });
- });
- singleStatScenario('MainValue should use same number for decimals as displayed when checking thresholds', function(ctx) {
- ctx.setup(function() {
- ctx.datapoints = [[99.999,1], [99.99999,2]];
- });
- it('Should be rounded', function() {
- expect(ctx.data.value).to.be(99.999495);
- expect(ctx.data.valueRounded).to.be(100);
- });
- it('should set formated falue', function() {
- expect(ctx.data.valueFormated).to.be('100');
- });
- });
- singleStatScenario('When value to text mapping is specified', function(ctx) {
- ctx.setup(function() {
- ctx.datapoints = [[9.9,1]];
- ctx.ctrl.panel.valueMaps = [{value: '10', text: 'OK'}];
- });
- it('value should remain', function() {
- expect(ctx.data.value).to.be(9.9);
- });
- it('round should be rounded up', function() {
- expect(ctx.data.valueRounded).to.be(10);
- });
- it('Should replace value with text', function() {
- expect(ctx.data.valueFormated).to.be('OK');
- });
- });
- singleStatScenario('When range to text mapping is specifiedfor first range', function(ctx) {
- ctx.setup(function() {
- ctx.datapoints = [[41,50]];
- ctx.ctrl.panel.mappingType = 2;
- ctx.ctrl.panel.rangeMaps = [{from: '10', to: '50', text: 'OK'},{from: '51', to: '100', text: 'NOT OK'}];
- });
- it('Should replace value with text OK', function() {
- expect(ctx.data.valueFormated).to.be('OK');
- });
- });
- singleStatScenario('When range to text mapping is specified for other ranges', function(ctx) {
- ctx.setup(function() {
- ctx.datapoints = [[65,75]];
- ctx.ctrl.panel.mappingType = 2;
- ctx.ctrl.panel.rangeMaps = [{from: '10', to: '50', text: 'OK'},{from: '51', to: '100', text: 'NOT OK'}];
- });
- it('Should replace value with text NOT OK', function() {
- expect(ctx.data.valueFormated).to.be('NOT OK');
- });
- });
- });
|