Add tests for doc_viewer

This commit is contained in:
Rashid Khan 2014-12-03 12:04:16 -07:00
parent 4a6a59d0b9
commit 98e40d2a50
4 changed files with 31 additions and 12 deletions

View file

@ -12,7 +12,7 @@
width="1%"
class="discover-table-details-field">
</td>
<td width="1%" class="discover-table-details-buttons" ng-show="filter">
<td width="1%" class="discover-table-details-buttons" ng-if="filter">
<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>

View file

@ -10,7 +10,7 @@ define(function (require) {
stack.push(key);
var flattenKey = stack.join('.');
if (self.fields.byName[flattenKey] || _.isArray(obj[key])) {
if ((self.fields.byName[flattenKey] || _.isArray(obj[key]) || !_.isObject(obj[key]))) {
flatObj[flattenKey] = obj[key];
} else if (_.isObject(obj[key])) {
flattenObj(obj[key]);

View file

@ -12,7 +12,8 @@ define(function (require) {
'extension': 'html',
'bytes': 100,
'point': {lat: 7, lon: 7},
'noMapping': 'hasNoMapping'
'noMapping': 'hasNoMapping',
'objectArray': [{foo: true}, {bar: false}]
}
};
@ -82,25 +83,37 @@ define(function (require) {
describe('filtering', function () {
it('should apply a filter when clicking filterable fields', function () {
var filterCell = $elem.find('td[title="bytes"]').next();
var cell = $elem.find('td[title="bytes"]').next();
filterCell.find('.fa-search-plus').first().click();
cell.find('.fa-search-plus').first().click();
expect($scope.filter.calledOnce).to.be(true);
filterCell.find('.fa-search-minus').first().click();
cell.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();
var cell = $elem.find('td[title="point"]').next();
filterCell.find('.fa-search-plus').first().click();
cell.find('.fa-search-plus').first().click();
expect($scope.filter.calledOnce).to.be(false);
filterCell.find('.fa-search-minus').first().click();
cell.find('.fa-search-minus').first().click();
expect($scope.filter.calledTwice).to.be(false);
});
});
describe('warnings', function () {
it('displays a warning about missing mappings', function () {
var cells = $elem.find('td[title="noMapping"]').siblings();
expect(cells.find('.doc-viewer-no-mapping').length).to.be(1);
expect(cells.find('.doc-viewer-object-array').length).to.be(0);
});
it('displays a warning about objects in arrays', function () {
var cells = $elem.find('td[title="objectArray"]').siblings();
expect(cells.find('.doc-viewer-no-mapping').length).to.be(0);
expect(cells.find('.doc-viewer-object-array').length).to.be(1);
});
});
});

View file

@ -27,10 +27,11 @@ define(function (require) {
},
bytes: 10039103,
'@timestamp': (new Date()).toString(),
tags: [{ text: 'foo' }, { text: 'bar' }]
tags: [{ text: 'foo' }, { text: 'bar' }],
noMapping: true
};
it('should only flatten keys as far as the mapping', function () {
it('should flatten keys as far down as the mapping goes', function () {
var obj = indexPattern.flattenSearchResponse(fixture);
expect(obj).to.have.property('geo.coordinates', fixture.geo.coordinates);
expect(obj).to.not.have.property('geo.coordinates.lat');
@ -42,6 +43,11 @@ define(function (require) {
expect(obj).to.have.property('bytes', 10039103);
});
it('should flatten keys not in the mapping', function () {
var obj = indexPattern.flattenSearchResponse(fixture);
expect(obj).to.have.property('noMapping', true);
});
it('should preserve objects in arrays', function () {
var obj = indexPattern.flattenSearchResponse(fixture);
expect(obj).to.have.property('tags', fixture['tags']);