mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[metricVis] Fix html support (#11008)
* [metricVis] Fix html support * [metric_vis] add test to verify 42d11b021 * [ui/vis] fix import
This commit is contained in:
parent
059071e623
commit
34c33f3895
5 changed files with 76 additions and 27 deletions
60
src/core_plugins/metric_vis/public/__tests__/metric_vis.js
Normal file
60
src/core_plugins/metric_vis/public/__tests__/metric_vis.js
Normal file
|
@ -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}]`);
|
||||
});
|
||||
});
|
|
@ -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>
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
import _ from 'lodash';
|
||||
import sinon from 'sinon';
|
||||
import Promise from 'bluebird';
|
||||
import { IndexedArray } from 'ui/indexed_array';
|
||||
import { IndexPatternProvider } from 'ui/index_patterns/_index_pattern';
|
||||
import { formatHit } from 'ui/index_patterns/_format_hit';
|
||||
import { getComputedFields } from 'ui/index_patterns/_get_computed_fields';
|
||||
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
|
||||
import { IndexPatternsFlattenHitProvider } from 'ui/index_patterns/_flatten_hit';
|
||||
import { IndexPatternsFieldProvider } from 'ui/index_patterns/_field';
|
||||
import { IndexPatternsFieldListProvider } from 'ui/index_patterns/_field_list';
|
||||
|
||||
export default function (Private) {
|
||||
const fieldFormats = Private(RegistryFieldFormatsProvider);
|
||||
const flattenHit = Private(IndexPatternsFlattenHitProvider);
|
||||
|
||||
const Field = Private(IndexPatternsFieldProvider);
|
||||
const FieldList = Private(IndexPatternsFieldListProvider);
|
||||
|
||||
function StubIndexPattern(pattern, timeField, fields) {
|
||||
this.id = pattern;
|
||||
|
@ -39,17 +37,17 @@ export default function (Private) {
|
|||
this.formatHit = formatHit(this, fieldFormats.getDefaultInstance('string'));
|
||||
this.formatField = this.formatHit.formatField;
|
||||
|
||||
this._indexFields = function () {
|
||||
this.fields = new IndexedArray({
|
||||
index: ['name'],
|
||||
group: ['type'],
|
||||
initialSet: fields.map(function (field) {
|
||||
return new Field(this, field);
|
||||
}, this)
|
||||
});
|
||||
this._reindexFields = function () {
|
||||
this.fields = new FieldList(this, this.fields || fields);
|
||||
};
|
||||
|
||||
this._indexFields();
|
||||
this.stubSetFieldFormat = function (fieldName, id, params) {
|
||||
const FieldFormat = fieldFormats.byId[id];
|
||||
this.fieldFormatMap[fieldName] = new FieldFormat(params);
|
||||
this._reindexFields();
|
||||
};
|
||||
|
||||
this._reindexFields();
|
||||
}
|
||||
|
||||
return StubIndexPattern;
|
||||
|
|
|
@ -4,7 +4,7 @@ import expect from 'expect.js';
|
|||
import resp from 'fixtures/agg_resp/range';
|
||||
import { VisProvider } from 'ui/vis';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
|
||||
|
||||
describe('Range Agg', function () {
|
||||
const buckets = values(resp.aggregations[1].buckets);
|
||||
|
||||
|
@ -15,14 +15,9 @@ describe('Range Agg', function () {
|
|||
beforeEach(ngMock.inject(function (Private) {
|
||||
Vis = Private(VisProvider);
|
||||
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
|
||||
const BytesFormat = Private(RegistryFieldFormatsProvider).byId.bytes;
|
||||
|
||||
indexPattern.fieldFormatMap.bytes = new BytesFormat({
|
||||
indexPattern.stubSetFieldFormat('bytes', 'bytes', {
|
||||
pattern: '0,0.[000] b'
|
||||
});
|
||||
|
||||
indexPattern._indexFields();
|
||||
}));
|
||||
|
||||
describe('formating', function () {
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
import $ from 'jquery';
|
||||
import ngMock from 'ng_mock';
|
||||
import expect from 'expect.js';
|
||||
|
||||
import { IndexPatternsFieldProvider } from 'ui/index_patterns/_field';
|
||||
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
import _ from 'lodash';
|
||||
|
||||
describe('FieldEditor directive', function () {
|
||||
|
||||
let Field;
|
||||
let StringFormat;
|
||||
let $rootScope;
|
||||
|
||||
let compile;
|
||||
|
@ -27,12 +26,9 @@ describe('FieldEditor directive', function () {
|
|||
|
||||
$rootScope = $injector.get('$rootScope');
|
||||
Field = Private(IndexPatternsFieldProvider);
|
||||
StringFormat = Private(RegistryFieldFormatsProvider).getType('string');
|
||||
|
||||
$rootScope.indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
// set the field format for this field
|
||||
$rootScope.indexPattern.fieldFormatMap.time = new StringFormat({ foo: 1, bar: 2 });
|
||||
$rootScope.indexPattern._indexFields();
|
||||
$rootScope.indexPattern.stubSetFieldFormat('time', 'string', { foo: 1, bar: 2 });
|
||||
$rootScope.field = $rootScope.indexPattern.fields.byName.time;
|
||||
|
||||
compile = function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue