Add tests for doc_viewer
This commit is contained in:
parent
f5851b9566
commit
98dc7b0272
|
@ -13,26 +13,26 @@
|
|||
class="discover-table-details-field">
|
||||
</td>
|
||||
<td width="1%" class="discover-table-details-buttons" ng-show="filter">
|
||||
<span bo-show="showFilters(mapping[field])">
|
||||
<span bo-if="showFilters(mapping[field])">
|
||||
<i ng-click="filter(field, flattened[field], '+')" class="fa fa-search-plus"></i>
|
||||
<i ng-click="filter(field, flattened[field],'-')" class="fa fa-search-minus"></i>
|
||||
</span>
|
||||
<span bo-show="!showFilters(mapping[field])" tooltip="Unindexed fields can not be searched">
|
||||
<span bo-if="!showFilters(mapping[field])" tooltip="Unindexed fields can not be searched">
|
||||
<i class="fa fa-search-plus text-muted"></i>
|
||||
<i class="fa fa-search-minus text-muted"></i>
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<i bo-show="!mapping[field] && !showArrayInObjectsWarning(doc, field)"
|
||||
<i bo-if="!mapping[field] && !showArrayInObjectsWarning(doc, field)"
|
||||
tooltip-placement="top"
|
||||
tooltip="No cached mapping for this field. Refresh your mapping from the Settings > Indices page"
|
||||
class="fa fa-warning text-color-warning ng-scope"></i>
|
||||
<i bo-show="showArrayInObjectsWarning(doc, field)"
|
||||
class="fa fa-warning text-color-warning ng-scope doc-viewer-no-mapping"></i>
|
||||
<i bo-if="showArrayInObjectsWarning(doc, field)"
|
||||
tooltip-placement="top"
|
||||
tooltip="Objects in arrays are not well supported."
|
||||
class="fa fa-warning text-color-warning ng-scope"></i>
|
||||
<span class="discover-table-details-value" ng-bind-html="(formatted[field] || doc[field]) | highlight : hit.highlight[field] | trustAsHtml"></span>
|
||||
class="fa fa-warning text-color-warning ng-scope doc-viewer-object-array"></i>
|
||||
<span class="discover-table-details-value" ng-bind-html="(formatted[field] || hit[field]) | highlight : hit.highlight[field] | trustAsHtml"></span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -4,7 +4,9 @@ define(function (require) {
|
|||
var html = require('text!components/doc_viewer/doc_viewer.html');
|
||||
|
||||
require('modules').get('kibana')
|
||||
.directive('docViewer', function (config, courier) {
|
||||
.directive('docViewer', function (config, Private) {
|
||||
var formats = Private(require('components/index_patterns/_field_formats'));
|
||||
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: html,
|
||||
|
@ -16,9 +18,8 @@ define(function (require) {
|
|||
filter: '=?',
|
||||
},
|
||||
link: function ($scope, $el, attr) {
|
||||
|
||||
// If a field isn't in the mapping, use this
|
||||
var defaultFormat = courier.indexPatterns.fieldFormats.defaultByType.string;
|
||||
var defaultFormat = formats.defaultByType.string;
|
||||
|
||||
$scope.mode = 'table';
|
||||
$scope.mapping = $scope.indexPattern.fields.byName;
|
||||
|
@ -29,11 +30,12 @@ define(function (require) {
|
|||
return formatter.convert(value);
|
||||
});
|
||||
$scope.fields = _.keys($scope.flattened).sort();
|
||||
$scope.filterableTypes = ['string', 'number', 'date', 'ip'];
|
||||
|
||||
|
||||
$scope.showFilters = function (mapping) {
|
||||
var validTypes = ['string', 'number', 'date', 'ip'];
|
||||
if (!$scope.filter || !mapping || !mapping.indexed) return false;
|
||||
return _.contains(validTypes, mapping.type);
|
||||
return _.contains($scope.filterableTypes, mapping.type);
|
||||
};
|
||||
|
||||
$scope.showArrayInObjectsWarning = function (row, field) {
|
||||
|
|
|
@ -32,7 +32,7 @@ define(function (require) {
|
|||
restrict: 'A',
|
||||
scope: {
|
||||
columns: '=',
|
||||
filtering: '=',
|
||||
filter: '=',
|
||||
indexPattern: '=',
|
||||
timefield: '=?',
|
||||
row: '=kbnTableRow'
|
||||
|
@ -83,10 +83,6 @@ define(function (require) {
|
|||
$compile($detailsTr)($detailsScope);
|
||||
};
|
||||
|
||||
$scope.filter = function (field, value, operation) {
|
||||
$scope.filtering(field, value, operation);
|
||||
};
|
||||
|
||||
$scope.$watchCollection('columns', function () {
|
||||
createSummaryRow($scope.row, $scope.row._id);
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
columns="columns"
|
||||
sorting="sorting"
|
||||
timefield="timefield"
|
||||
filtering="filtering"
|
||||
filter="filtering"
|
||||
index-pattern="indexPattern"
|
||||
class="discover-table-row"></tr>
|
||||
</tbody>
|
||||
|
|
|
@ -25,7 +25,7 @@ define(function (require) {
|
|||
|
||||
indexPattern.flattenSearchResponse = _.bind(flattenSearchResponse, indexPattern);
|
||||
indexPattern.flattenHit = _.bind(flattenHit, indexPattern);
|
||||
|
||||
indexPattern.metaFields = ['_id', '_type', '_source'];
|
||||
|
||||
return indexPattern;
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ define(function (require) {
|
|||
'columns="columns" ' +
|
||||
'rows="rows" ' +
|
||||
'sorting="sorting"' +
|
||||
'filtering="filtering"' +
|
||||
'filter="filtering"' +
|
||||
'maxLength=maxLength ' +
|
||||
'index-pattern="indexPattern"' +
|
||||
'timefield="timefield" ' +
|
||||
|
@ -259,7 +259,7 @@ define(function (require) {
|
|||
'<tr kbn-table-row="row" ' +
|
||||
'columns="columns" ' +
|
||||
'sorting="sorting"' +
|
||||
'filtering="filtering"' +
|
||||
'filter="filter"' +
|
||||
'index-pattern="indexPattern"' +
|
||||
'timefield="timefield" ' +
|
||||
'></tr>'
|
||||
|
@ -271,7 +271,7 @@ define(function (require) {
|
|||
row: getFakeRow(0, mapping),
|
||||
columns: [],
|
||||
sorting: [],
|
||||
filtering: sinon.spy(),
|
||||
filter: sinon.spy(),
|
||||
maxLength: 50,
|
||||
});
|
||||
|
||||
|
@ -287,13 +287,6 @@ define(function (require) {
|
|||
columnTests('td', $elem);
|
||||
});
|
||||
|
||||
describe('details row', function () {
|
||||
it('should be an empty tr by default', function () {
|
||||
expect($elem.next().is('tr')).to.be(true);
|
||||
expect($elem.next().text()).to.be('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('details row', function () {
|
||||
it('should be an empty tr by default', function () {
|
||||
expect($elem.next().is('tr')).to.be(true);
|
||||
|
@ -333,9 +326,9 @@ define(function (require) {
|
|||
describe('filtering', function () {
|
||||
it('should filter when you click on the filter buttons', function () {
|
||||
$details.find('.fa-search-plus').first().click();
|
||||
expect($scope.filtering.calledOnce).to.be(true);
|
||||
expect($scope.filter.calledOnce).to.be(true);
|
||||
$details.find('.fa-search-minus').first().click();
|
||||
expect($scope.filtering.calledTwice).to.be(true);
|
||||
expect($scope.filter.calledTwice).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
108
test/unit/specs/components/doc_viewer/doc_viewer.js
Normal file
108
test/unit/specs/components/doc_viewer/doc_viewer.js
Normal file
|
@ -0,0 +1,108 @@
|
|||
define(function (require) {
|
||||
var angular = require('angular');
|
||||
var $ = require('jquery');
|
||||
var _ = require('lodash');
|
||||
var sinon = require('test_utils/auto_release_sinon');
|
||||
var hit = {
|
||||
'_index': 'logstash-2014.09.09',
|
||||
'_type': 'apache',
|
||||
'_id': '61',
|
||||
'_score': 1,
|
||||
'_source': {
|
||||
'extension': 'html',
|
||||
'bytes': 100,
|
||||
'point': {lat: 7, lon: 7},
|
||||
'noMapping': 'hasNoMapping'
|
||||
}
|
||||
};
|
||||
|
||||
// Load the kibana app dependencies.
|
||||
require('services/private');
|
||||
require('components/doc_viewer/doc_viewer');
|
||||
|
||||
|
||||
var $parentScope, $scope, indexPattern, flattened;
|
||||
|
||||
var init = function ($elem, props) {
|
||||
inject(function ($rootScope, $compile) {
|
||||
$parentScope = $rootScope;
|
||||
_.assign($parentScope, props);
|
||||
$compile($elem)($parentScope);
|
||||
$elem.scope().$digest();
|
||||
$scope = $elem.isolateScope();
|
||||
});
|
||||
};
|
||||
|
||||
var destroy = function () {
|
||||
$scope.$destroy();
|
||||
$parentScope.$destroy();
|
||||
};
|
||||
|
||||
describe('docViewer', function () {
|
||||
var $elem;
|
||||
|
||||
beforeEach(module('kibana'));
|
||||
beforeEach(function () {
|
||||
$elem = angular.element('<doc-viewer index-pattern="indexPattern" hit="hit" filter="filter"></doc-viewer>');
|
||||
inject(function (Private) {
|
||||
indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
|
||||
flattened = indexPattern.flattenHit(hit);
|
||||
});
|
||||
init($elem, {
|
||||
indexPattern: indexPattern,
|
||||
hit: hit,
|
||||
filter: sinon.spy()
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
destroy();
|
||||
});
|
||||
|
||||
describe('Table mode', function () {
|
||||
it('should have a row for each field', function () {
|
||||
var rows = $elem.find('tr');
|
||||
expect($elem.find('tr').length).to.be(_.keys(flattened).length);
|
||||
});
|
||||
|
||||
it('should have the field name in the first column', function () {
|
||||
_.each(_.keys(flattened), function (field) {
|
||||
expect($elem.find('td[title="' + field + '"]').length).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have the a value for each field', function () {
|
||||
_.each(_.keys(flattened), function (field) {
|
||||
var cellValue = $elem.find('td[title="' + field + '"]').siblings().find('.discover-table-details-value').text();
|
||||
|
||||
// This sucks, but testing the filter chain is too hairy ATM
|
||||
expect(cellValue.length).to.be.greaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('filtering', function () {
|
||||
|
||||
it('should apply a filter when clicking filterable fields', function () {
|
||||
var filterCell = $elem.find('td[title="bytes"]').next();
|
||||
|
||||
filterCell.find('.fa-search-plus').first().click();
|
||||
expect($scope.filter.calledOnce).to.be(true);
|
||||
filterCell.find('.fa-search-minus').first().click();
|
||||
expect($scope.filter.calledTwice).to.be(true);
|
||||
});
|
||||
|
||||
it('should NOT apply a filter when clicking non-filterable fields', function () {
|
||||
var filterCell = $elem.find('td[title="point"]').next();
|
||||
|
||||
filterCell.find('.fa-search-plus').first().click();
|
||||
expect($scope.filter.calledOnce).to.be(false);
|
||||
filterCell.find('.fa-search-minus').first().click();
|
||||
expect($scope.filter.calledTwice).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue