From f7c48c5a5fb04d3ec15872f1b5a989adc207353e Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Thu, 8 Jun 2017 11:06:37 +0200 Subject: [PATCH] singlestat: fix ignoring zero value for table data When table data returns a column with the value 0, it should not ignore it. This change checks for undefined instead of if the value is truthy. Fixes #8531 --- public/app/plugins/panel/singlestat/module.ts | 2 +- .../panel/singlestat/specs/singlestat_specs.ts | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 3b3fb928b74..dce82f17ce2 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -165,7 +165,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { return; } - if (tableData[0].length === 0 || !tableData[0][0][this.panel.tableColumn]) { + if (tableData[0].length === 0 || tableData[0][0][this.panel.tableColumn] === undefined) { return; } diff --git a/public/app/plugins/panel/singlestat/specs/singlestat_specs.ts b/public/app/plugins/panel/singlestat/specs/singlestat_specs.ts index 6e05266b8fe..210196a24cc 100644 --- a/public/app/plugins/panel/singlestat/specs/singlestat_specs.ts +++ b/public/app/plugins/panel/singlestat/specs/singlestat_specs.ts @@ -65,7 +65,7 @@ describe('SingleStatCtrl', function() { expect(ctx.data.valueRounded).to.be(0); }); - it('should set formatted falue', function() { + it('should set formatted value', function() { expect(ctx.data.valueFormatted).to.be('test.cpu1'); }); }); @@ -82,7 +82,7 @@ describe('SingleStatCtrl', function() { expect(ctx.data.valueRounded).to.be(100); }); - it('should set formatted falue', function() { + it('should set formatted value', function() { expect(ctx.data.valueFormatted).to.be('100'); }); }); @@ -254,6 +254,18 @@ describe('SingleStatCtrl', function() { expect(ctx.data.valueFormatted).to.be('ignore1'); }); }); + + singleStatScenario('When value is zero', function(ctx) { + ctx.setup(function() { + ctx.data = tableData; + ctx.data[0].rows[0] = [1492759673649, 'ignore1', 0, 'ignore2']; + ctx.ctrl.panel.tableColumn = 'mean'; + }); + + it('Should return zero', function() { + expect(ctx.data.value).to.be(0); + }); + }); }); });