From c30c12d36950fc9a21b0f5a8b5423454bab33721 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 29 Feb 2016 10:05:00 +0100 Subject: [PATCH] fix(single_stat): rounding bug in value => text --- public/app/plugins/panel/singlestat/editor.html | 4 ++-- public/app/plugins/panel/singlestat/module.ts | 2 +- .../panel/singlestat/specs/singlestat-specs.ts | 14 ++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/public/app/plugins/panel/singlestat/editor.html b/public/app/plugins/panel/singlestat/editor.html index bf3227f7582..6b0806133b8 100644 --- a/public/app/plugins/panel/singlestat/editor.html +++ b/public/app/plugins/panel/singlestat/editor.html @@ -167,13 +167,13 @@
  • - +
  • - +
  • diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 7f576cc3f2d..88e09937186 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -213,7 +213,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { // value/number to text mapping var value = parseFloat(map.value); - if (value === data.value) { + if (value === data.valueRounded) { data.valueFormated = map.text; return; } diff --git a/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts b/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts index 283389ee400..90bd5339737 100644 --- a/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts +++ b/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts @@ -69,14 +69,20 @@ describe('SingleStatCtrl', function() { singleStatScenario('When value to text mapping is specified', function(ctx) { ctx.setup(function() { - ctx.datapoints = [[10,1]]; + ctx.datapoints = [[9.9,1]]; ctx.ctrl.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'); + 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'); + }); }); });