Fix _source formatting (#22800) (#22865)

* Fix _source formatting

* Update unit test

* Add functional test

* Fix CI error, move functional test to the end
This commit is contained in:
Marco Vettorello 2018-09-10 12:07:02 +02:00 committed by GitHub
parent 2dd01b6887
commit c74da9cac9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View file

@ -48,7 +48,7 @@ export function createSourceFormat(FieldFormat) {
SourceFormat.prototype._convert = {
text: (value) => toJson(value),
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

@ -43,8 +43,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

@ -175,5 +175,19 @@ export default function ({ getService, getPageObjects }) {
'2015-09-20', '4,757',
]);
});
it('should show correct data for a data table with top hits', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickDataTable();
await PageObjects.visualize.clickNewSearch();
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
await PageObjects.visualize.clickMetricEditor();
await PageObjects.visualize.selectAggregation('Top Hit', 'metrics');
await PageObjects.visualize.selectField('_source', 'metrics');
await PageObjects.visualize.clickGo();
const data = await PageObjects.visualize.getTableVisData();
log.debug(data);
expect(data.length).to.be.greaterThan(0);
});
});
}