Adding more tests and features for filter bar

- Add support for _previuos to _array_to_linked_list
- Add support for parent to _transform_aggregation
- Add tests for _array_to_linked_list
- Add test for setting the parent of the element for hierarchial data
This commit is contained in:
Chris Cowan 2014-10-17 11:49:42 -07:00
parent 1e29129ac3
commit 6069ca2e64
5 changed files with 42 additions and 3 deletions

View file

@ -4,6 +4,7 @@ define(function (require) {
var previous;
_.each(buckets, function (bucket) {
if (previous) {
bucket._previous = previous;
previous._next = bucket;
}
previous = bucket;

View file

@ -1,7 +1,7 @@
define(function (require) {
var _ = require('lodash');
var extractBuckets = require('components/visualize/_extract_buckets');
return function transformAggregation(agg, metric, aggData) {
return function transformAggregation(agg, metric, aggData, parent) {
return _.map(extractBuckets(aggData), function (bucket) {
// Pick the appropriate value, if the metric doesn't exist then we just
// use the count.
@ -14,12 +14,18 @@ define(function (require) {
aggConfig: agg
};
// if the parent is defined then we need to set the parent of the branch
// this will be used later for filters for waking up the parent path.
if (parent) {
branch.parent = parent;
}
// If the next bucket exists and it has children the we need to
// transform it as well. This is where the recursion happens.
if (agg._next) {
var nextBucket = bucket[agg._next.id];
if (nextBucket && nextBucket.buckets) {
branch.children = transformAggregation(agg._next, metric, nextBucket);
branch.children = transformAggregation(agg._next, metric, nextBucket, branch);
}
}

View file

@ -145,7 +145,8 @@
'specs/visualize/_build_hierarchial_data',
'specs/visualize/_extract_buckets',
'specs/visualize/_transform_aggregation',
'specs/visualize/_create_raw_data'
'specs/visualize/_create_raw_data',
'specs/visualize/_array_to_linked_list'
], function (kibana, sinon) {
kibana.load(function () {
var xhr = sinon.useFakeXMLHttpRequest();

View file

@ -0,0 +1,27 @@
define(function (require) {
var arrayToLinkedList = require('components/visualize/_array_to_linked_list');
describe('buildHierarchialData()', function () {
describe('arrayToLinkedList', function () {
var results;
beforeEach(function () {
results = arrayToLinkedList([
{ id: 1 },
{ id: 2 },
{ id: 3 }
]);
});
it('should set the next element', function () {
expect(results[0]).to.have.property('_next', results[1]);
expect(results[1]).to.have.property('_next', results[2]);
});
it('should set the previous element', function () {
expect(results[1]).to.have.property('_previous', results[0]);
expect(results[2]).to.have.property('_previous', results[1]);
});
});
});
});

View file

@ -63,14 +63,18 @@ define(function (require) {
expect(children[0].children[0]).to.have.property('aggConfig', fixture.agg.agg_3);
expect(children[0].children[0]).to.have.property('name', 'win');
expect(children[0].children[1]).to.have.property('size', 1);
expect(children[0].children[1]).to.have.property('parent', children[0]);
expect(children[0].children[1]).to.have.property('aggConfig', fixture.agg.agg_3);
expect(children[0].children[1]).to.have.property('name', 'mac');
expect(children[1].children[0]).to.have.property('size', 2);
expect(children[0].children[1]).to.have.property('parent', children[0]);
expect(children[1].children[0]).to.have.property('aggConfig', fixture.agg.agg_3);
expect(children[1].children[0]).to.have.property('name', 'win');
expect(children[1].children[1]).to.have.property('size', 2);
expect(children[1].children[1]).to.have.property('parent', children[1]);
expect(children[1].children[1]).to.have.property('aggConfig', fixture.agg.agg_3);
expect(children[1].children[1]).to.have.property('name', 'mac');
expect(children[1].children[1]).to.have.property('parent', children[1]);
});
});