Skip to content

Commit

Permalink
fixing bug and adding make_nested_label tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Feb 13, 2017
1 parent 40af4a3 commit 1d5e0c3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/ui/public/agg_types/__tests__/metrics/derivative.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Derivative metric', function () {
derivativeMetric = Private(DerivativeProvider);

const params = settings || {
buckets_path: '1',
metricAgg: '1',
customMetric: null
};

Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
34 changes: 34 additions & 0 deletions src/ui/public/agg_types/__tests__/metrics/lib/make_nested_label.js
Original file line number Diff line number Diff line change
@@ -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');
});

});
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/metrics/lib/make_nested_label.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
};

Expand Down

0 comments on commit 1d5e0c3

Please sign in to comment.