[5.6] Fix _source formatting (#22800) (#22867)

* Backport fix to 5.6 structure

* Fix CI error, update functional test to use 5.6 visualize page objects

* removed async and anon function
This commit is contained in:
Marco Vettorello 2018-09-10 17:49:44 +02:00 committed by Court Ewing
parent 2933998d14
commit a07347478b
3 changed files with 48 additions and 4 deletions

View file

@ -28,8 +28,9 @@ describe('_source formatting', function () {
}));
it('should use the text content type if a field is not passed', function () {
const hit = _.first(hits);
expect(convertHtml(hit._source)).to.be(`<span ng-non-bindable>${JSON.stringify(hit._source)}</span>`);
const hit = { 'foo': 'bar', 'number': 42, 'hello': '<h1>World</h1>', 'also': 'with "quotes" or \'single quotes\'' };
// eslint-disable-next-line
expect(convertHtml(hit)).to.be('<span ng-non-bindable>{&quot;foo&quot;:&quot;bar&quot;,&quot;number&quot;:42,&quot;hello&quot;:&quot;&lt;h1&gt;World&lt;/h1&gt;&quot;,&quot;also&quot;:&quot;with \\&quot;quotes\\&quot; or &#39;single quotes&#39;&quot;}</span>');
});
it('uses the _source, field, and hit to create a <dl>', function () {

View file

@ -19,7 +19,7 @@ export function stringifySource(Private, shortDotsFilter) {
Source.prototype._convert = {
text: angular.toJson,
html: function sourceToHtml(source, field, hit) {
if (!field) return this.getConverterFor('text')(source, field, hit);
if (!field) return _.escape(this.getConverterFor('text')(source));
const highlights = (hit && hit.highlight) || {};
const formatted = field.indexPattern.formatHit(hit);

View file

@ -84,7 +84,50 @@ export default function ({ getService, getPageObjects }) {
});
});
});
it('should show correct data for a data table with top hits', function () {
log.debug('navigateToApp visualize');
return PageObjects.common.navigateToUrl('visualize', 'new')
.then(function () {
log.debug('clickDataTable');
return PageObjects.visualize.clickDataTable();
})
.then(function clickNewSearch() {
log.debug('clickNewSearch');
return PageObjects.visualize.clickNewSearch();
})
.then(function setAbsoluteRange() {
log.debug('Set absolute time range from \"' + fromTime + '\" to \"' + toTime + '\"');
return PageObjects.header.setAbsoluteRange(fromTime, toTime);
})
.then(function clickMetricEditor() {
log.debug('clickMetricEditor');
return PageObjects.visualize.clickMetricEditor();
})
.then(function selectAggregation() {
log.debug('Select aggregation');
return PageObjects.visualize.selectAggregation('Top Hit');
})
.then(function selectField() {
log.debug('Field = _source');
return PageObjects.visualize.selectField('_source', 'metrics');
})
.then(function clickGo() {
return PageObjects.visualize.clickGo();
})
.then(function () {
return PageObjects.header.waitUntilLoadingHasFinished();
})
.then(function () {
return retry.try(function () {
return PageObjects.visualize.getDataTableData()
.then(function showData(data) {
const tableData = data.trim().split('\n');
log.debug(tableData);
expect(tableData.length).to.be(1);
});
});
});
});
});
});
}