mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
fixing tests in tooltip, added a fixture function to return a new Vis and added a data directory for testing
This commit is contained in:
parent
549b5f113a
commit
6d61958348
4 changed files with 463 additions and 85 deletions
|
@ -24,6 +24,7 @@
|
|||
config: '/config',
|
||||
test_utils: '../../test/utils',
|
||||
fixtures: '../../test/unit/fixtures',
|
||||
vislib_fixtures: '../../test/unit/specs/vislib/fixture',
|
||||
specs: '../../test/unit/specs',
|
||||
sinon: '../../test/utils/sinon',
|
||||
bluebird: 'bower_components/bluebird/js/browser/bluebird',
|
||||
|
|
412
test/unit/specs/vislib/fixture/mock_data/series/data0.js
Normal file
412
test/unit/specs/vislib/fixture/mock_data/series/data0.js
Normal file
|
@ -0,0 +1,412 @@
|
|||
define(function (require) {
|
||||
var moment = require('moment');
|
||||
|
||||
return {
|
||||
'label': '',
|
||||
'xAxisLabel': '@timestamp per 30 sec',
|
||||
'ordered': {
|
||||
'date': true,
|
||||
'min': 1411761457636,
|
||||
'max': 1411762357636,
|
||||
'interval': 30000
|
||||
},
|
||||
'yAxisLabel': 'Count of documents',
|
||||
'series': [
|
||||
{
|
||||
'values': [
|
||||
{
|
||||
'x': 1411761450000,
|
||||
'y': 21
|
||||
},
|
||||
{
|
||||
'x': 1411761480000,
|
||||
'y': 18
|
||||
},
|
||||
{
|
||||
'x': 1411761510000,
|
||||
'y': 22
|
||||
},
|
||||
{
|
||||
'x': 1411761540000,
|
||||
'y': 17
|
||||
},
|
||||
{
|
||||
'x': 1411761570000,
|
||||
'y': 17
|
||||
},
|
||||
{
|
||||
'x': 1411761600000,
|
||||
'y': 21
|
||||
},
|
||||
{
|
||||
'x': 1411761630000,
|
||||
'y': 16
|
||||
},
|
||||
{
|
||||
'x': 1411761660000,
|
||||
'y': 17
|
||||
},
|
||||
{
|
||||
'x': 1411761690000,
|
||||
'y': 15
|
||||
},
|
||||
{
|
||||
'x': 1411761720000,
|
||||
'y': 19
|
||||
},
|
||||
{
|
||||
'x': 1411761750000,
|
||||
'y': 11
|
||||
},
|
||||
{
|
||||
'x': 1411761780000,
|
||||
'y': 13
|
||||
},
|
||||
{
|
||||
'x': 1411761810000,
|
||||
'y': 24
|
||||
},
|
||||
{
|
||||
'x': 1411761840000,
|
||||
'y': 20
|
||||
},
|
||||
{
|
||||
'x': 1411761870000,
|
||||
'y': 20
|
||||
},
|
||||
{
|
||||
'x': 1411761900000,
|
||||
'y': 21
|
||||
},
|
||||
{
|
||||
'x': 1411761930000,
|
||||
'y': 17
|
||||
},
|
||||
{
|
||||
'x': 1411761960000,
|
||||
'y': 20
|
||||
},
|
||||
{
|
||||
'x': 1411761990000,
|
||||
'y': 13
|
||||
},
|
||||
{
|
||||
'x': 1411762020000,
|
||||
'y': 14
|
||||
},
|
||||
{
|
||||
'x': 1411762050000,
|
||||
'y': 25
|
||||
},
|
||||
{
|
||||
'x': 1411762080000,
|
||||
'y': 17
|
||||
},
|
||||
{
|
||||
'x': 1411762110000,
|
||||
'y': 14
|
||||
},
|
||||
{
|
||||
'x': 1411762140000,
|
||||
'y': 22
|
||||
},
|
||||
{
|
||||
'x': 1411762170000,
|
||||
'y': 14
|
||||
},
|
||||
{
|
||||
'x': 1411762200000,
|
||||
'y': 19
|
||||
},
|
||||
{
|
||||
'x': 1411762230000,
|
||||
'y': 22
|
||||
},
|
||||
{
|
||||
'x': 1411762260000,
|
||||
'y': 17
|
||||
},
|
||||
{
|
||||
'x': 1411762290000,
|
||||
'y': 8
|
||||
},
|
||||
{
|
||||
'x': 1411762320000,
|
||||
'y': 15
|
||||
},
|
||||
{
|
||||
'x': 1411762350000,
|
||||
'y': 4
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
'raw': {
|
||||
'splitColumns': [],
|
||||
'splitValStack': [],
|
||||
'columns': [
|
||||
{
|
||||
'categoryName': 'segment',
|
||||
'id': 'agg_12',
|
||||
'aggConfig': {
|
||||
'type': 'date_histogram',
|
||||
'schema': 'segment',
|
||||
'params': {
|
||||
'field': '@timestamp',
|
||||
'interval': 'auto',
|
||||
'min_doc_count': 1,
|
||||
'extended_bounds': {}
|
||||
}
|
||||
},
|
||||
'aggType': {
|
||||
'name': 'date_histogram',
|
||||
'title': 'Date Histogram',
|
||||
'ordered': {
|
||||
'date': true
|
||||
},
|
||||
'hasNoDsl': false,
|
||||
'params': [
|
||||
{
|
||||
'name': 'field',
|
||||
'filterFieldTypes': 'date'
|
||||
},
|
||||
{
|
||||
'name': 'interval',
|
||||
'default': 'auto',
|
||||
'options': [
|
||||
{
|
||||
'display': 'Auto',
|
||||
'val': 'auto'
|
||||
},
|
||||
{
|
||||
'display': 'Second',
|
||||
'val': 'second',
|
||||
'ms': 1000
|
||||
},
|
||||
{
|
||||
'display': 'Minute',
|
||||
'val': 'minute',
|
||||
'ms': 60000
|
||||
},
|
||||
{
|
||||
'display': 'Hourly',
|
||||
'val': 'hour',
|
||||
'ms': 3600000
|
||||
},
|
||||
{
|
||||
'display': 'Daily',
|
||||
'val': 'day',
|
||||
'ms': 86400000
|
||||
},
|
||||
{
|
||||
'display': 'Weekly',
|
||||
'val': 'week',
|
||||
'ms': 604800000
|
||||
},
|
||||
{
|
||||
'display': 'Monthly',
|
||||
'val': 'month',
|
||||
'ms': 2592000000
|
||||
},
|
||||
{
|
||||
'display': 'Yearly',
|
||||
'val': 'year',
|
||||
'ms': 31536000000
|
||||
}
|
||||
],
|
||||
'editor': '<div class=\'form-group\'>\n <label>Interval</label>\n <select\n ' +
|
||||
'ng-if=\'aggParam.options\'\n ng-model=\'params.interval\'\n required\n ' +
|
||||
'ng-options=\'opt as opt.display for opt in aggParam.options\'\n class=\'form-control\'\n ' +
|
||||
'name=\'interval\'>\n </select>\n <input\n ng-if=\'!aggParam.options\'\n ' +
|
||||
'ng-model=\'params.interval\'\n required\n type=\'number\'\n class=\'form-control\'\n ' +
|
||||
'name=\'interval\' />\n</div>\n'
|
||||
},
|
||||
{
|
||||
'name': 'format'
|
||||
},
|
||||
{
|
||||
'name': 'min_doc_count',
|
||||
'default': 1
|
||||
},
|
||||
{
|
||||
'name': 'extended_bounds',
|
||||
'default': {}
|
||||
}
|
||||
],
|
||||
'type': 'buckets'
|
||||
},
|
||||
'field': {
|
||||
'type': 'date',
|
||||
'indexed': true,
|
||||
'analyzed': false,
|
||||
'doc_values': false,
|
||||
'name': '@timestamp',
|
||||
'count': 0
|
||||
},
|
||||
'label': '@timestamp per 30 sec',
|
||||
'params': {
|
||||
'field': '@timestamp',
|
||||
'interval': '30000ms',
|
||||
'min_doc_count': 1,
|
||||
'extended_bounds': {
|
||||
'min': '2014-09-26T19:57:37.633Z',
|
||||
'max': '2014-09-26T20:12:37.633Z'
|
||||
}
|
||||
},
|
||||
'metricScaleText': '30 sec'
|
||||
},
|
||||
{
|
||||
'categoryName': 'metric',
|
||||
'id': 'agg_11',
|
||||
'aggConfig': {
|
||||
'type': 'count',
|
||||
'schema': 'metric',
|
||||
'params': {}
|
||||
},
|
||||
'aggType': {
|
||||
'name': 'count',
|
||||
'title': 'Count',
|
||||
'hasNoDsl': true,
|
||||
'params': [],
|
||||
'type': 'metrics'
|
||||
},
|
||||
'label': 'Count of documents',
|
||||
'params': {}
|
||||
}
|
||||
],
|
||||
'rows': [
|
||||
[
|
||||
1411761450000,
|
||||
21
|
||||
],
|
||||
[
|
||||
1411761480000,
|
||||
18
|
||||
],
|
||||
[
|
||||
1411761510000,
|
||||
22
|
||||
],
|
||||
[
|
||||
1411761540000,
|
||||
17
|
||||
],
|
||||
[
|
||||
1411761570000,
|
||||
17
|
||||
],
|
||||
[
|
||||
1411761600000,
|
||||
21
|
||||
],
|
||||
[
|
||||
1411761630000,
|
||||
16
|
||||
],
|
||||
[
|
||||
1411761660000,
|
||||
17
|
||||
],
|
||||
[
|
||||
1411761690000,
|
||||
15
|
||||
],
|
||||
[
|
||||
1411761720000,
|
||||
19
|
||||
],
|
||||
[
|
||||
1411761750000,
|
||||
11
|
||||
],
|
||||
[
|
||||
1411761780000,
|
||||
13
|
||||
],
|
||||
[
|
||||
1411761810000,
|
||||
24
|
||||
],
|
||||
[
|
||||
1411761840000,
|
||||
20
|
||||
],
|
||||
[
|
||||
1411761870000,
|
||||
20
|
||||
],
|
||||
[
|
||||
1411761900000,
|
||||
21
|
||||
],
|
||||
[
|
||||
1411761930000,
|
||||
17
|
||||
],
|
||||
[
|
||||
1411761960000,
|
||||
20
|
||||
],
|
||||
[
|
||||
1411761990000,
|
||||
13
|
||||
],
|
||||
[
|
||||
1411762020000,
|
||||
14
|
||||
],
|
||||
[
|
||||
1411762050000,
|
||||
25
|
||||
],
|
||||
[
|
||||
1411762080000,
|
||||
17
|
||||
],
|
||||
[
|
||||
1411762110000,
|
||||
14
|
||||
],
|
||||
[
|
||||
1411762140000,
|
||||
22
|
||||
],
|
||||
[
|
||||
1411762170000,
|
||||
14
|
||||
],
|
||||
[
|
||||
1411762200000,
|
||||
19
|
||||
],
|
||||
[
|
||||
1411762230000,
|
||||
22
|
||||
],
|
||||
[
|
||||
1411762260000,
|
||||
17
|
||||
],
|
||||
[
|
||||
1411762290000,
|
||||
8
|
||||
],
|
||||
[
|
||||
1411762320000,
|
||||
15
|
||||
],
|
||||
[
|
||||
1411762350000,
|
||||
4
|
||||
]
|
||||
]
|
||||
},
|
||||
'hits': 533,
|
||||
'xAxisFormatter': function (thing) {
|
||||
return moment(thing);
|
||||
},
|
||||
'tooltipFormatter': function (d) {
|
||||
return d;
|
||||
}
|
||||
};
|
||||
});
|
21
test/unit/specs/vislib/fixture/vis_fixture.js
Normal file
21
test/unit/specs/vislib/fixture/vis_fixture.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
define(function (require) {
|
||||
return function VisLibFixtures(Private) {
|
||||
var $ = require('jquery');
|
||||
|
||||
return function (type) {
|
||||
var Vis = Private(require('components/vislib/vis'));
|
||||
var visChart = $('body').append('<div class=visualize-chart></div>');
|
||||
var $el = $('.visualize-chart');
|
||||
var config = {
|
||||
shareYAxis: true,
|
||||
addTooltip: true,
|
||||
addLegend: true,
|
||||
addEvents: true,
|
||||
addBrushing: true,
|
||||
type: type
|
||||
};
|
||||
|
||||
return new Vis($el, config);
|
||||
};
|
||||
};
|
||||
});
|
|
@ -6,43 +6,9 @@ define(function (require) {
|
|||
angular.module('TooltipFactory', ['kibana']);
|
||||
|
||||
describe('Vislib Tooltip', function () {
|
||||
var Tooltip;
|
||||
var Vis;
|
||||
var Events;
|
||||
var vis;
|
||||
var events;
|
||||
var bars;
|
||||
var tip;
|
||||
var el;
|
||||
var chart;
|
||||
var config;
|
||||
|
||||
var data = [
|
||||
{
|
||||
x: 10,
|
||||
y: 8
|
||||
},
|
||||
{
|
||||
x: 11,
|
||||
y: 23
|
||||
},
|
||||
{
|
||||
x: 12,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 13,
|
||||
y: 28
|
||||
},
|
||||
{
|
||||
x: 14,
|
||||
y: 36
|
||||
},
|
||||
{
|
||||
x: 15,
|
||||
y: 30
|
||||
}
|
||||
];
|
||||
var data;
|
||||
var tooltips = [];
|
||||
|
||||
beforeEach(function () {
|
||||
module('TooltipFactory');
|
||||
|
@ -50,66 +16,44 @@ define(function (require) {
|
|||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
Vis = Private(require('components/vislib/vis'));
|
||||
Events = Private(require('components/vislib/lib/dispatch'));
|
||||
Tooltip = Private(require('components/vislib/lib/tooltip'));
|
||||
vis = Private(require('vislib_fixtures/vis_fixture'))('histogram');
|
||||
data = require('vislib_fixtures/mock_data/series/data0');
|
||||
require('css!components/vislib/styles/main');
|
||||
|
||||
el = d3.select('body')
|
||||
.append('div')
|
||||
.attr('class', 'vis-col-wrapper')
|
||||
.style('width', '40px')
|
||||
.style('height', '40px');
|
||||
|
||||
config = {
|
||||
shareYAxis: true,
|
||||
addTooltip: true,
|
||||
addLegend: true,
|
||||
addEvents: true,
|
||||
addBrushing: true
|
||||
};
|
||||
|
||||
vis = new Vis(el[0][0], config);
|
||||
vis.render(data);
|
||||
|
||||
tip = new Tooltip(el[0][0], function (d) {
|
||||
return 'd.x: ' + d.x + ', d.y: ' + d.y;
|
||||
vis.handler.charts.forEach(function (chart) {
|
||||
tooltips.push(chart.tooltip);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
chart = el.append('div').attr('class', 'chart');
|
||||
el.append('div').attr('class', 'y-axis-col-wrapper');
|
||||
el.append('div').attr('class', 'k4tip');
|
||||
// Placeholder until we know better regarding garbage collection
|
||||
afterEach(function () {
|
||||
$(vis.el).remove();
|
||||
vis = null;
|
||||
});
|
||||
|
||||
bars = chart.selectAll('div')
|
||||
.data(data)
|
||||
.enter()
|
||||
.append('div')
|
||||
.attr('class', 'bars')
|
||||
.style('width', function (d) {
|
||||
return d.y;
|
||||
})
|
||||
.style('height', '10px')
|
||||
.text(function (d) {
|
||||
return d.y;
|
||||
});
|
||||
describe('render Method', function () {
|
||||
var isObject;
|
||||
var isFunction;
|
||||
|
||||
bars.call(tip.render());
|
||||
beforeEach(function () {
|
||||
_.forEach(tooltips, function (tooltip) {
|
||||
isObject = _.isObject(tooltip);
|
||||
isFunction = _.isFunction(tooltip.render());
|
||||
});
|
||||
});
|
||||
|
||||
it('should be an object', function () {
|
||||
expect(isObject).to.be(true);
|
||||
});
|
||||
|
||||
|
||||
it('should return a function', function () {
|
||||
expect(isFunction).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
el.remove();
|
||||
});
|
||||
|
||||
it('should be an object', function () {
|
||||
expect(_.isObject(Tooltip)).to.be(true);
|
||||
});
|
||||
|
||||
it('should return a function', function () {
|
||||
expect(typeof Tooltip).to.be('function');
|
||||
});
|
||||
describe('getOffsets Method', function () {});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue