Skip to content

Commit

Permalink
Fix _source formatting (#22800)
Browse files Browse the repository at this point in the history
* Fix _source formatting

* Update unit test

* Add functional test

* Fix CI error, move functional test to the end
  • Loading branch information
markov00 committed Sep 10, 2018
1 parent 012c601 commit 45e4791
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Expand Up @@ -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);
Expand Down
Expand Up @@ -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 () {
Expand Down
14 changes: 14 additions & 0 deletions test/functional/apps/visualize/_data_table.js
Expand Up @@ -178,5 +178,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);
});
});
}

0 comments on commit 45e4791

Please sign in to comment.