mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Singlestat: threshold checks are now done on a rounded value, rounded to same number of decimals as is shown, Fixes #1983
This commit is contained in:
85
public/test/specs/singlestat-specs.js
Normal file
85
public/test/specs/singlestat-specs.js
Normal file
@@ -0,0 +1,85 @@
|
||||
define([
|
||||
'helpers',
|
||||
'features/panel/panelSrv',
|
||||
'features/panel/panelHelper',
|
||||
'panels/singlestat/module'
|
||||
], function(helpers) {
|
||||
'use strict';
|
||||
|
||||
describe('SingleStatCtrl', function() {
|
||||
var ctx = new helpers.ControllerTestContext();
|
||||
|
||||
function singleStatScenario(desc, func) {
|
||||
|
||||
describe(desc, function() {
|
||||
|
||||
ctx.setup = function (setupFunc) {
|
||||
|
||||
beforeEach(module('grafana.services'));
|
||||
beforeEach(module('grafana.panels.singlestat'));
|
||||
|
||||
beforeEach(ctx.providePhase());
|
||||
beforeEach(ctx.createControllerPhase('SingleStatCtrl'));
|
||||
|
||||
beforeEach(function() {
|
||||
setupFunc();
|
||||
ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
|
||||
data: [ { target: 'test.cpu1', datapoints: ctx.datapoints } ]
|
||||
}));
|
||||
|
||||
ctx.scope.refreshData(ctx.datasource);
|
||||
ctx.scope.$digest();
|
||||
ctx.data = ctx.scope.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 = [[10,1]];
|
||||
ctx.scope.panel.valueMaps = [{value: '10', text: 'OK'}];
|
||||
});
|
||||
|
||||
it('Should replace value with text', function() {
|
||||
expect(ctx.data.value).to.be(10);
|
||||
expect(ctx.data.valueFormated).to.be('OK');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -140,6 +140,7 @@ require([
|
||||
'specs/dashboardSrv-specs',
|
||||
'specs/dashboardViewStateSrv-specs',
|
||||
'specs/soloPanelCtrl-specs',
|
||||
'specs/singlestat-specs',
|
||||
'specs/dynamicDashboardSrv-specs',
|
||||
'specs/unsavedChangesSrv-specs',
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user