From 1d5e0c32e926d05714e807b31abe4d79bfb8955b Mon Sep 17 00:00:00 2001 From: ppisljar Date: Fri, 27 Jan 2017 10:55:22 +0100 Subject: [PATCH] fixing bug and adding make_nested_label tests --- .../agg_types/__tests__/metrics/derivative.js | 10 +++--- .../metrics/lib/make_nested_label.js | 34 +++++++++++++++++++ .../metrics/lib/make_nested_label.js | 2 +- .../lib/parent_pipeline_agg_writter.js | 8 ++--- 4 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 src/ui/public/agg_types/__tests__/metrics/lib/make_nested_label.js diff --git a/src/ui/public/agg_types/__tests__/metrics/derivative.js b/src/ui/public/agg_types/__tests__/metrics/derivative.js index 4ccaa8bd428e4d..257a4220fb6b5e 100644 --- a/src/ui/public/agg_types/__tests__/metrics/derivative.js +++ b/src/ui/public/agg_types/__tests__/metrics/derivative.js @@ -18,7 +18,7 @@ describe('Derivative metric', function () { derivativeMetric = Private(DerivativeProvider); const params = settings || { - buckets_path: '1', + metricAgg: '1', customMetric: null }; @@ -58,7 +58,7 @@ describe('Derivative metric', function () { it('should return a label Derivative of max bytes', function () { init({ - buckets_path: 'custom', + metricAgg: 'custom', customMetric: { id:'1-orderAgg', type: 'max', @@ -71,7 +71,7 @@ describe('Derivative metric', function () { it('should return a label prefixed with number of derivative', function () { init({ - buckets_path: 'custom', + metricAgg: 'custom', customMetric: { id:'2-orderAgg', type: 'derivative', @@ -91,7 +91,7 @@ describe('Derivative metric', function () { it('should set parent aggs', function () { init({ - buckets_path: 'custom', + metricAgg: 'custom', customMetric: { id:'2-orderAgg', type: 'max', @@ -104,7 +104,7 @@ describe('Derivative metric', function () { it('should set nested parent aggs', function () { init({ - buckets_path: 'custom', + metricAgg: 'custom', customMetric: { id:'2-orderAgg', type: 'derivative', diff --git a/src/ui/public/agg_types/__tests__/metrics/lib/make_nested_label.js b/src/ui/public/agg_types/__tests__/metrics/lib/make_nested_label.js new file mode 100644 index 00000000000000..3cacad944d9428 --- /dev/null +++ b/src/ui/public/agg_types/__tests__/metrics/lib/make_nested_label.js @@ -0,0 +1,34 @@ +import expect from 'expect.js'; +import makeNestedLabel from 'ui/agg_types/metrics/lib/make_nested_label'; + +describe('metric agg make_nested_label', function () { + + function generateAggConfig(metricLabel) { + return { + params: { + customMetric: { + makeLabel: () => { return metricLabel; } + } + } + }; + } + + it('should return a metric label with prefix', function () { + const aggConfig = generateAggConfig('Count'); + const label = makeNestedLabel(aggConfig, 'derivative of'); + expect(label).to.eql('Derivative of Count'); + }); + + it('should return a numbered prefix', function () { + const aggConfig = generateAggConfig('Derivative of Count'); + const label = makeNestedLabel(aggConfig, 'derivative of'); + expect(label).to.eql('2. derivative of Count'); + }); + + it('should return a prefix with correct order', function () { + const aggConfig = generateAggConfig('3. derivative of Count'); + const label = makeNestedLabel(aggConfig, 'derivative of'); + expect(label).to.eql('4. derivative of Count'); + }); + +}); diff --git a/src/ui/public/agg_types/metrics/lib/make_nested_label.js b/src/ui/public/agg_types/metrics/lib/make_nested_label.js index b400a81288f43b..85dcebf94dcfac 100644 --- a/src/ui/public/agg_types/metrics/lib/make_nested_label.js +++ b/src/ui/public/agg_types/metrics/lib/make_nested_label.js @@ -16,7 +16,7 @@ const makeNestedLabel = function (aggConfig, label) { } return metricLabel; } - const metric = aggConfig.vis.aggs.find(agg => agg.id === aggConfig.params.buckets_path); + const metric = aggConfig.vis.aggs.find(agg => agg.id === aggConfig.params.metricAgg); return `${uppercaseLabel} of ${metric.makeLabel()}`; }; diff --git a/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writter.js b/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writter.js index 5c5db8929df08c..b5e49b3373720c 100644 --- a/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writter.js +++ b/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writter.js @@ -1,16 +1,16 @@ const parentPipelineAggWritter = function (agg, output) { const vis = agg.vis; - const orderAgg = agg.params.customMetric || vis.aggs.getResponseAggById(agg.params.metricAgg); + const selectedMetric = agg.params.customMetric || vis.aggs.getResponseAggById(agg.params.metricAgg); if (agg.params.customMetric && agg.params.customMetric.type.name !== 'count') { - output.parentAggs = (output.parentAggs || []).concat(orderAgg); + output.parentAggs = (output.parentAggs || []).concat(selectedMetric); } output.params = {}; - if (orderAgg.type.name === 'count') { + if (selectedMetric.type.name === 'count') { output.params.buckets_path = '_count'; } else { - output.params.buckets_path = orderAgg.id; + output.params.buckets_path = selectedMetric.id; } };