-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [fieldFormat] make formatted output non-bindable (#11911) * [fieldFormat] make formatted output non-bindable * [aggTable] totals are consumed as text, produce text * [tests] fix existing tests * [fieldFormat/contentType] add tests for non-bindable wrapper (cherry picked from commit 1d2341f) (cherry picked from commit f85570d) * fix import statement * [metricVis] Fix html support (#11008) * [metricVis] Fix html support * [metric_vis] add test to verify 42d11b0 * [ui/vis] fix import (cherry picked from commit 34c33f3) (cherry picked from commit eea7622) * fix import statement (cherry picked from commit 07d9a3b)
- Loading branch information
Showing
11 changed files
with
225 additions
and
52 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/core_plugins/metric_vis/public/__tests__/metric_vis.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import $ from 'jquery'; | ||
import ngMock from 'ng_mock'; | ||
import expect from 'expect.js'; | ||
|
||
import VisProvider from 'ui/vis'; | ||
import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern'; | ||
import MetricVisProvider from '../metric_vis'; | ||
|
||
describe('metric_vis', () => { | ||
let setup = null; | ||
|
||
beforeEach(ngMock.module('kibana')); | ||
beforeEach(ngMock.inject((Private, $rootScope) => { | ||
setup = () => { | ||
const Vis = Private(VisProvider); | ||
const metricVisType = Private(MetricVisProvider); | ||
const indexPattern = Private(LogstashIndexPatternStubProvider); | ||
|
||
indexPattern.stubSetFieldFormat('ip', 'url', { | ||
urlTemplate: 'http://ip.info?address={{value}}', | ||
labelTemplate: 'ip[{{value}}]' | ||
}); | ||
|
||
const vis = new Vis(indexPattern, { | ||
type: 'metric', | ||
aggs: [{ id: '1', type: 'top_hits', schema: 'metric', params: { field: 'ip' } }], | ||
}); | ||
|
||
const $el = $('<div>'); | ||
const renderbot = metricVisType.createRenderbot(vis, $el); | ||
const render = (esResponse) => { | ||
renderbot.render(esResponse); | ||
$rootScope.$digest(); | ||
}; | ||
|
||
return { $el, render }; | ||
}; | ||
})); | ||
|
||
it('renders html value from field formatter', () => { | ||
const { $el, render } = setup(); | ||
|
||
const ip = '235.195.237.208'; | ||
render({ | ||
hits: { total: 0, hits: [] }, | ||
aggregations: { | ||
'1': { | ||
hits: { total: 1, hits: [{ _source: { ip } }] } | ||
} | ||
} | ||
}); | ||
|
||
const $link = $el | ||
.find('a[href]') | ||
.filter(function () { return this.href.includes('ip.info'); }); | ||
|
||
expect($link).to.have.length(1); | ||
expect($link.text()).to.be(`ip[${ip}]`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<div ng-controller="KbnMetricVisController" class="metric-vis"> | ||
<div class="metric-container" ng-repeat="metric in metrics"> | ||
<div class="metric-value" ng-style="{'font-size': vis.params.fontSize+'pt'}">{{metric.value}}</div> | ||
<div class="metric-value" ng-bind-html="metric.value" ng-style="{'font-size': vis.params.fontSize+'pt'}"></div> | ||
<div>{{metric.label}}</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/ui/public/index_patterns/_field_format/__tests__/content_types.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import angular from 'angular'; | ||
import $ from 'jquery'; | ||
import ngMock from 'ng_mock'; | ||
import sinon from 'sinon'; | ||
import expect from 'expect.js'; | ||
import { escape } from 'lodash'; | ||
|
||
import IndexPatternsFieldFormatContentTypesProvider from '../content_types'; | ||
|
||
describe('index_patterns/_field_format/content_types', () => { | ||
|
||
let render; | ||
const callMe = sinon.stub(); | ||
afterEach(() => callMe.reset()); | ||
|
||
function getAllContents(node) { | ||
return [...node.childNodes].reduce((acc, child) => { | ||
return acc.concat(child, getAllContents(child)); | ||
}, []); | ||
} | ||
|
||
angular.module('testApp', []) | ||
.directive('testDirective', () => ({ | ||
restrict: 'EACM', | ||
link: callMe | ||
})); | ||
|
||
beforeEach(ngMock.module('testApp')); | ||
beforeEach(ngMock.inject(($injector) => { | ||
const contentTypes = new IndexPatternsFieldFormatContentTypesProvider(); | ||
const $rootScope = $injector.get('$rootScope'); | ||
const $compile = $injector.get('$compile'); | ||
|
||
$rootScope.callMe = callMe; | ||
|
||
render = (convert) => { | ||
const $el = $('<div>'); | ||
const { html } = contentTypes.setup({ _convert: { html: convert } }); | ||
$compile($el.html(html(` | ||
<!-- directive: test-directive --> | ||
<div></div> | ||
<test-directive>{{callMe()}}</test-directive> | ||
<span test-directive></span> | ||
<marquee class="test-directive"></marquee> | ||
`)))($rootScope); | ||
return $el; | ||
}; | ||
})); | ||
|
||
it('no element directive', () => { | ||
const $el = render(value => ` | ||
<test-directive>${escape(value)}</test-directive> | ||
`); | ||
|
||
expect($el.find('test-directive')).to.have.length(1); | ||
sinon.assert.notCalled(callMe); | ||
}); | ||
|
||
it('no attribute directive', () => { | ||
const $el = render(value => ` | ||
<div test-directive>${escape(value)}</div> | ||
`); | ||
|
||
expect($el.find('[test-directive]')).to.have.length(1); | ||
sinon.assert.notCalled(callMe); | ||
}); | ||
|
||
it('no comment directive', () => { | ||
const $el = render(value => ` | ||
<!-- directive: test-directive --> | ||
<div>${escape(value)}</div> | ||
`); | ||
|
||
const comments = getAllContents($el.get(0)) | ||
.filter(node => node.nodeType === 8); | ||
|
||
expect(comments).to.have.length(1); | ||
expect(comments[0].textContent).to.contain('test-directive'); | ||
sinon.assert.notCalled(callMe); | ||
}); | ||
|
||
it('no class directive', () => { | ||
const $el = render(value => ` | ||
<div class="test-directive">${escape(value)}</div> | ||
`); | ||
|
||
expect($el.find('.test-directive')).to.have.length(1); | ||
sinon.assert.notCalled(callMe); | ||
}); | ||
|
||
it('no interpolation', () => { | ||
const $el = render(value => ` | ||
<div class="foo {{callMe()}}">${escape(value)}</div> | ||
`); | ||
|
||
expect($el.find('.foo')).to.have.length(1); | ||
sinon.assert.notCalled(callMe); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.