-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
src/ui/public/agg_types/__tests__/metrics/sibling_pipeline.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import _ from 'lodash'; | ||
import expect from 'expect.js'; | ||
import ngMock from 'ng_mock'; | ||
import BucketSum from 'ui/agg_types/metrics/bucket_sum'; | ||
import BucketAvg from 'ui/agg_types/metrics/bucket_avg'; | ||
import BucketMin from 'ui/agg_types/metrics/bucket_min'; | ||
import BucketMax from 'ui/agg_types/metrics/bucket_max'; | ||
import VisProvider from 'ui/vis'; | ||
import StubbedIndexPattern from 'fixtures/stubbed_logstash_index_pattern'; | ||
|
||
const metrics = [ | ||
{ name: 'sum_bucket', title: 'Overall Sum', provider: BucketSum }, | ||
{ name: 'avg_bucket', title: 'Overall Average', provider: BucketAvg }, | ||
{ name: 'min_bucket', title: 'Overall Min', provider: BucketMin }, | ||
{ name: 'max_bucket', title: 'Overall Max', provider: BucketMax }, | ||
]; | ||
|
||
describe('sibling pipeline aggs', function () { | ||
metrics.forEach(metric => { | ||
describe(`${metric.title} metric`, function () { | ||
|
||
let aggDsl; | ||
let metricAgg; | ||
let aggConfig; | ||
|
||
function init(settings) { | ||
ngMock.module('kibana'); | ||
ngMock.inject(function (Private) { | ||
const Vis = Private(VisProvider); | ||
const indexPattern = Private(StubbedIndexPattern); | ||
metricAgg = Private(metric.provider); | ||
|
||
const params = settings || { | ||
customMetric: { | ||
id: '5', | ||
type: 'count', | ||
schema: 'metric' | ||
}, | ||
customBucket: { | ||
id: '6', | ||
type: 'date_histogram', | ||
schema: 'bucket', | ||
params: { field: '@timestamp' } | ||
} | ||
}; | ||
|
||
const vis = new Vis(indexPattern, { | ||
title: 'New Visualization', | ||
type: 'metric', | ||
params: { | ||
fontSize: 60, | ||
handleNoResults: true | ||
}, | ||
aggs: [ | ||
{ | ||
id: '1', | ||
type: 'count', | ||
schema: 'metric' | ||
}, | ||
{ | ||
id: '2', | ||
type: metric.name, | ||
schema: 'metric', | ||
params | ||
} | ||
], | ||
listeners: {} | ||
}); | ||
|
||
// Grab the aggConfig off the vis (we don't actually use the vis for anything else) | ||
aggConfig = vis.aggs[1]; | ||
aggDsl = aggConfig.toDsl(); | ||
}); | ||
} | ||
|
||
it(`should return a label prefixed with ${metric.title} of`, function () { | ||
init(); | ||
expect(metricAgg.makeLabel(aggConfig)).to.eql(`${metric.title} of Count`); | ||
}); | ||
|
||
it('should set parent aggs', function () { | ||
init(); | ||
expect(aggDsl[metric.name].buckets_path).to.be('2-bucket>_count'); | ||
expect(aggDsl.parentAggs['2-bucket'].date_histogram).to.not.be.undefined; | ||
}); | ||
|
||
it('should set nested parent aggs', function () { | ||
init({ | ||
customMetric: { | ||
id: '5', | ||
type: 'avg', | ||
schema: 'metric', | ||
params: { field: 'bytes' }, | ||
}, | ||
customBucket: { | ||
id: '6', | ||
type: 'date_histogram', | ||
schema: 'bucket', | ||
params: { field: '@timestamp' }, | ||
} | ||
}); | ||
expect(aggDsl[metric.name].buckets_path).to.be('2-bucket>2-metric'); | ||
expect(aggDsl.parentAggs['2-bucket'].date_histogram).to.not.be.undefined; | ||
expect(aggDsl.parentAggs['2-bucket'].aggs['2-metric'].avg.field).to.equal('bytes'); | ||
}); | ||
|
||
}); | ||
}); | ||
|
||
}); |