Skip to content

Commit

Permalink
[5.6] Fix _source formatting (elastic#22800) (elastic#22867)
Browse files Browse the repository at this point in the history
* Backport fix to 5.6 structure

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

* removed async and anon function
  • Loading branch information
markov00 authored and epixa committed Sep 10, 2018
1 parent 2933998 commit a073474
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/ui/public/stringify/__tests__/_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/stringify/types/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 44 additions & 1 deletion test/functional/apps/visualize/_data_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
});
});
});
}

0 comments on commit a073474

Please sign in to comment.