[aggTable] added tests for the table portion

This commit is contained in:
Spencer Alger 2014-11-03 12:06:04 -07:00
parent 99a7a4964c
commit 66bacfaa3c
4 changed files with 116 additions and 16 deletions

View file

@ -1,21 +1,23 @@
define(function (require) {
return function stubbedLogstashIndexPatternService(Private) {
var StubIndexPattern = Private(require('test_utils/stub_index_pattern'));
var fieldFormats = Private(require('components/index_patterns/_field_formats'));
return new StubIndexPattern('logstash-*', 'time', [
{ type: 'number', indexed: true, analyzed: true, count: 10, name: 'bytes' },
{ type: 'boolean', indexed: true, analyzed: true, count: 20, name: 'ssl' },
{ type: 'date', indexed: true, analyzed: true, count: 30, name: '@timestamp' },
{ type: 'number', indexed: true, analyzed: true, count: 0, name: 'phpmemory' },
{ type: 'ip', indexed: true, analyzed: true, count: 0, name: 'ip' },
{ type: 'attachment', indexed: true, analyzed: true, count: 0, name: 'request_body' },
{ type: 'string', indexed: true, analyzed: true, count: 0, name: 'extension' },
{ type: 'geo_point', indexed: true, analyzed: true, count: 0, name: 'point' },
{ type: 'geo_shape', indexed: true, analyzed: true, count: 0, name: 'area' },
{ type: 'string', indexed: true, analyzed: true, count: 0, name: 'extension' },
{ type: 'string', indexed: true, analyzed: true, count: 0, name: 'machine.os' },
{ type: 'string', indexed: true, analyzed: true, count: 0, name: 'geo.src' },
{ type: 'string', indexed: true, analyzed: true, count: 0, name: '_type' },
{ type: 'conflict', indexed: false, analyzed: false, count: 0, name: 'custom_user_field' }
{ name: 'bytes', type: 'number', indexed: true, analyzed: true, count: 10 },
{ name: 'ssl', type: 'boolean', indexed: true, analyzed: true, count: 20 },
{ name: '@timestamp', type: 'date', indexed: true, analyzed: true, count: 30 },
{ name: 'phpmemory', type: 'number', indexed: true, analyzed: true, count: 0 },
{ name: 'ip', type: 'ip', indexed: true, analyzed: true, count: 0 },
{ name: 'request_body', type: 'attachment', indexed: true, analyzed: true, count: 0 },
{ name: 'extension', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'point', type: 'geo_point', indexed: true, analyzed: true, count: 0 },
{ name: 'area', type: 'geo_shape', indexed: true, analyzed: true, count: 0 },
{ name: 'extension', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'machine.os', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'geo.src', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: '_type', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'custom_user_field', type: 'conflict', indexed: false, analyzed: false, count: 0 }
]);
};
});

View file

@ -158,7 +158,8 @@
'specs/components/agg_response/hierarchical/_create_raw_data',
'specs/components/agg_response/hierarchical/_array_to_linked_list',
'specs/components/agg_response/hierarchical/_collect_branch',
'specs/components/agg_response/tabify/tabify_agg_response'
'specs/components/agg_response/tabify/tabify_agg_response',
'specs/components/agg_table/index'
], function () {
bootstrap(kibana, sinon);
});

View file

@ -0,0 +1,97 @@
define(function (require) {
describe('AggTable Directive', function () {
var _ = require('lodash');
var $ = require('jquery');
var fixtures = require('fixtures/fake_hierarchical_data');
var $rootScope;
var $compile;
var tabifyAggResponse;
var Vis;
var indexPattern;
beforeEach(module('kibana'));
beforeEach(inject(function ($injector, Private) {
tabifyAggResponse = Private(require('components/agg_response/tabify/tabify_agg_response'));
indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
Vis = Private(require('components/vis/vis'));
$rootScope = $injector.get('$rootScope');
$compile = $injector.get('$compile');
}));
var $scope;
beforeEach(function () {
$scope = $rootScope.$new();
});
afterEach(function () {
$scope.$destroy();
});
it('renders a simple response properly', function () {
var vis = new Vis(indexPattern, 'table');
$scope.table = tabifyAggResponse(vis, fixtures.metricOnly, { canSplit: false });
var $el = $('<kbn-agg-table table="table"></kbn-agg-table>');
$compile($el)($scope);
$scope.$digest();
expect($el.find('tbody').size()).to.be(1);
expect($el.find('td').size()).to.be(1);
expect($el.find('td').text()).to.eql(1000);
});
it('renders a complex response properly', function () {
var vis = new Vis(indexPattern, {
type: 'pie',
aggs: [
{ type: 'avg', schema: 'metric', params: { field: 'bytes' } },
{ type: 'terms', schema: 'split', params: { field: 'extension' } },
{ type: 'terms', schema: 'segment', params: { field: 'geo.src' } },
{ type: 'terms', schema: 'segment', params: { field: 'machine.os' } }
]
});
vis.aggs.forEach(function (agg, i) {
agg.id = 'agg_' + (i + 1);
});
$scope.table = tabifyAggResponse(vis, fixtures.threeTermBuckets, { canSplit: false });
var $el = $('<kbn-agg-table table="table"></kbn-agg-table>').appendTo(document.body);
$compile($el)($scope);
$scope.$digest();
expect($el.find('tbody').size()).to.be(1);
var $rows = $el.find('tbody tr');
expect($rows.size()).to.be.greaterThan(0);
$rows.each(function (i) {
// 4 cells in every row
var $cells = $(this).find('td');
expect($cells.size()).to.be(6);
var txts = $cells.map(function () {
return $(this).text().trim();
});
// two character country code
expect(txts[0]).to.match(/^(png|jpg|gif|html|css)$/);
// average bytes
expect(txts[1]).to.match(/^\d+$/);
var bytesAsNum = _.parseInt(txts[1]);
expect(bytesAsNum === 0 || bytesAsNum > 1000).to.be.ok();
// os
expect(txts[2]).to.match(/^(win|mac|linux)$/);
// average bytes
expect(txts[1]).to.match(/^\d+$/);
bytesAsNum = _.parseInt(txts[1]);
expect(bytesAsNum === 0 || bytesAsNum > 1000).to.be.ok();
});
});
});
});

View file

@ -16,7 +16,7 @@ define(function (require) {
Object.defineProperty(field, 'format', {
enumerable: false,
get: function () {
fieldFormats.defaultByType[field.type];
return fieldFormats.defaultByType[field.type];
}
});