-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[metric_vis] add test to verify 42d11b021
- Loading branch information
Showing
5 changed files
with
77 additions
and
28 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
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