mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[aggTable] added tests for the table portion
This commit is contained in:
parent
99a7a4964c
commit
66bacfaa3c
4 changed files with 116 additions and 16 deletions
|
@ -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 }
|
||||
]);
|
||||
};
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
97
test/unit/specs/components/agg_table/index.js
Normal file
97
test/unit/specs/components/agg_table/index.js
Normal 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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -16,7 +16,7 @@ define(function (require) {
|
|||
Object.defineProperty(field, 'format', {
|
||||
enumerable: false,
|
||||
get: function () {
|
||||
fieldFormats.defaultByType[field.type];
|
||||
return fieldFormats.defaultByType[field.type];
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue