mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
fixing tests
This commit is contained in:
parent
ae7ef90f0a
commit
ef95a0305a
5 changed files with 447 additions and 216 deletions
|
@ -7,6 +7,9 @@ define(function () {
|
|||
div.selectAll('.x-axis-div')
|
||||
.append('div')
|
||||
.data(function (d) {
|
||||
if (!d) {
|
||||
console.log(selection[0].parentNode);
|
||||
}
|
||||
return d.columns ? d.columns : [d];
|
||||
})
|
||||
.enter()
|
||||
|
|
|
@ -95,6 +95,7 @@
|
|||
'specs/vislib/layout_types',
|
||||
'specs/vislib/vis_types',
|
||||
'specs/vislib/splits',
|
||||
'specs/vislib/layout',
|
||||
'specs/vislib/column_layout',
|
||||
'specs/utils/diff_time_picker_vals',
|
||||
'specs/factories/events',
|
||||
|
|
203
test/unit/specs/vislib/layout.js
Normal file
203
test/unit/specs/vislib/layout.js
Normal file
|
@ -0,0 +1,203 @@
|
|||
define(function (require) {
|
||||
var angular = require('angular');
|
||||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
|
||||
angular.module('LayoutFactory', ['kibana']);
|
||||
|
||||
describe('Vislib Layout Class Test Suite', function () {
|
||||
var Layout;
|
||||
var layout;
|
||||
var xAxisSplit;
|
||||
var el;
|
||||
var chartType = 'histogram';
|
||||
var data = {
|
||||
hits: 621,
|
||||
label: '',
|
||||
ordered: {
|
||||
date: true,
|
||||
interval: 30000,
|
||||
max: 1408734982458,
|
||||
min: 1408734082458
|
||||
},
|
||||
series: [
|
||||
{
|
||||
values: [
|
||||
{
|
||||
x: 1408734060000,
|
||||
y: 8
|
||||
},
|
||||
{
|
||||
x: 1408734090000,
|
||||
y: 23
|
||||
},
|
||||
{
|
||||
x: 1408734120000,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 1408734150000,
|
||||
y: 28
|
||||
},
|
||||
{
|
||||
x: 1408734180000,
|
||||
y: 36
|
||||
},
|
||||
{
|
||||
x: 1408734210000,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 1408734240000,
|
||||
y: 26
|
||||
},
|
||||
{
|
||||
x: 1408734270000,
|
||||
y: 22
|
||||
},
|
||||
{
|
||||
x: 1408734300000,
|
||||
y: 29
|
||||
},
|
||||
{
|
||||
x: 1408734330000,
|
||||
y: 24
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
xAxisLabel: 'Date Histogram',
|
||||
yAxisLabel: 'Count'
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
module('LayoutFactory');
|
||||
module('XAxisSplitFactory');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
Layout = Private(require('components/vislib/modules/Layout'));
|
||||
xAxisSplit = Private(require('components/vislib/components/layouts/splits/column_chart/x_axis_split'));
|
||||
|
||||
el = d3.select('body').append('div')
|
||||
.attr('class', 'visualize-chart');
|
||||
layout = new Layout(el[0][0], data, chartType);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
el.remove();
|
||||
});
|
||||
|
||||
describe('createLayout Method', function () {
|
||||
beforeEach(function () {
|
||||
layout.createLayout(layout.layoutType);
|
||||
});
|
||||
|
||||
it('should append all the divs', function () {
|
||||
expect(el.selectAll('.vis-wrapper').length).to.be(1);
|
||||
expect(el.selectAll('.y-axis-col-wrapper').length).to.be(1);
|
||||
expect(el.selectAll('.vis-col-wrapper').length).to.be(1);
|
||||
expect(el.selectAll('.legend-col-wrapper').length).to.be(1);
|
||||
expect(el.selectAll('.k4tip').length).to.be(1);
|
||||
expect(el.selectAll('.y-axis-col').length).to.be(1);
|
||||
expect(el.selectAll('.y-axis-title').length).to.be(1);
|
||||
expect(el.selectAll('.y-axis-chart-title').length).to.be(1);
|
||||
expect(el.selectAll('.y-axis-div-wrapper').length).to.be(1);
|
||||
expect(el.selectAll('.y-axis-spacer-block').length).to.be(1);
|
||||
expect(el.selectAll('.chart-wrapper').length).to.be(1);
|
||||
expect(el.selectAll('.x-axis-wrapper').length).to.be(1);
|
||||
expect(el.selectAll('.x-axis-div-wrapper').length).to.be(1);
|
||||
expect(el.selectAll('.x-axis-chart-title').length).to.be(1);
|
||||
expect(el.selectAll('.x-axis-title').length).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('layout Method', function () {
|
||||
beforeEach(function () {
|
||||
layout.layout({
|
||||
parent: layout.el,
|
||||
type: 'div',
|
||||
class: 'chart',
|
||||
datum: layout.data,
|
||||
children: [
|
||||
{
|
||||
parent: 'chart',
|
||||
type: 'div',
|
||||
class: 'x-axis',
|
||||
splits: xAxisSplit
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it('should append a div with the correct class name', function () {
|
||||
expect(el.select('.chart').length).to.be(1);
|
||||
});
|
||||
|
||||
it('should bind data to the DOM element', function () {
|
||||
expect(!!el.select('.chart').data()).to.be(true);
|
||||
});
|
||||
|
||||
it('should create children', function () {
|
||||
expect(el.select('.x-axis').length).to.be(1);
|
||||
});
|
||||
|
||||
it('should call split function when provided', function () {
|
||||
expect(el.select('.x-axis-div').length).to.be(1);
|
||||
});
|
||||
|
||||
it('should throw an errors when incorrect arguments provided', function () {
|
||||
expect(function () {
|
||||
layout.layout({
|
||||
parent: null,
|
||||
type: 'div',
|
||||
class: 'chart'
|
||||
});
|
||||
}).to.throwError();
|
||||
|
||||
expect(function () {
|
||||
layout.layout({
|
||||
parent: layout.el,
|
||||
type: undefined,
|
||||
class: 'chart'
|
||||
});
|
||||
}).to.throwError();
|
||||
|
||||
expect(function () {
|
||||
layout.layout({
|
||||
parent: layout.el,
|
||||
type: xAxisSplit,
|
||||
class: 'chart'
|
||||
});
|
||||
}).to.throwError();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('appendElem Method', function () {
|
||||
beforeEach(function () {
|
||||
layout.appendElem(layout.el, 'svg', 'column');
|
||||
});
|
||||
|
||||
it('should append DOM element to el with a class name', function () {
|
||||
expect(el.select('svg').attr('class')).to.be('column');
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeAll Method', function () {
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
d3.select(layout.el).append('div').attr('class', 'visualize');
|
||||
layout.removeAll(layout.el);
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove all DOM elements from the el', function () {
|
||||
expect(el.selectAll(this.childNodes)[0].length).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
|
@ -1,6 +1,5 @@
|
|||
define(function (require) {
|
||||
var angular = require('angular');
|
||||
var _ = require('lodash');
|
||||
var $ = require('jquery');
|
||||
|
||||
angular.module('ChartSplitFactory', ['kibana']);
|
||||
|
@ -9,246 +8,269 @@ define(function (require) {
|
|||
angular.module('YAxisSplitFactory', ['kibana']);
|
||||
|
||||
describe('Vislib Split Function Test Suite', function () {
|
||||
var chartSplit;
|
||||
var chartTitleSplit;
|
||||
var xAxisSplit;
|
||||
var yAxisSplit;
|
||||
var el;
|
||||
var data = {
|
||||
rows : [
|
||||
{
|
||||
hits: 621,
|
||||
label: '',
|
||||
ordered: {
|
||||
date: true,
|
||||
interval: 30000,
|
||||
max: 1408734982458,
|
||||
min: 1408734082458
|
||||
describe('Column Chart', function () {
|
||||
var chartSplit;
|
||||
var chartTitleSplit;
|
||||
var xAxisSplit;
|
||||
var yAxisSplit;
|
||||
var el;
|
||||
var data = {
|
||||
rows: [
|
||||
{
|
||||
hits : 621,
|
||||
label : '',
|
||||
ordered : {
|
||||
date : true,
|
||||
interval: 30000,
|
||||
max : 1408734982458,
|
||||
min : 1408734082458
|
||||
},
|
||||
series : [
|
||||
{
|
||||
values: [
|
||||
{
|
||||
x: 1408734060000,
|
||||
y: 8
|
||||
},
|
||||
{
|
||||
x: 1408734090000,
|
||||
y: 23
|
||||
},
|
||||
{
|
||||
x: 1408734120000,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 1408734150000,
|
||||
y: 28
|
||||
},
|
||||
{
|
||||
x: 1408734180000,
|
||||
y: 36
|
||||
},
|
||||
{
|
||||
x: 1408734210000,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 1408734240000,
|
||||
y: 26
|
||||
},
|
||||
{
|
||||
x: 1408734270000,
|
||||
y: 22
|
||||
},
|
||||
{
|
||||
x: 1408734300000,
|
||||
y: 29
|
||||
},
|
||||
{
|
||||
x: 1408734330000,
|
||||
y: 24
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
xAxisLabel: 'Date Histogram',
|
||||
yAxisLabel: 'Count'
|
||||
},
|
||||
series: [
|
||||
{
|
||||
values: [
|
||||
{
|
||||
x: 1408734060000,
|
||||
y: 8
|
||||
},
|
||||
{
|
||||
x: 1408734090000,
|
||||
y: 23
|
||||
},
|
||||
{
|
||||
x: 1408734120000,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 1408734150000,
|
||||
y: 28
|
||||
},
|
||||
{
|
||||
x: 1408734180000,
|
||||
y: 36
|
||||
},
|
||||
{
|
||||
x: 1408734210000,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 1408734240000,
|
||||
y: 26
|
||||
},
|
||||
{
|
||||
x: 1408734270000,
|
||||
y: 22
|
||||
},
|
||||
{
|
||||
x: 1408734300000,
|
||||
y: 29
|
||||
},
|
||||
{
|
||||
x: 1408734330000,
|
||||
y: 24
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
xAxisLabel: 'Date Histogram',
|
||||
yAxisLabel: 'Count'
|
||||
},
|
||||
{
|
||||
hits: 621,
|
||||
label: '',
|
||||
ordered: {
|
||||
date: true,
|
||||
interval: 30000,
|
||||
max: 1408734982458,
|
||||
min: 1408734082458
|
||||
},
|
||||
series: [
|
||||
{
|
||||
values: [
|
||||
{
|
||||
x: 1408734060000,
|
||||
y: 8
|
||||
},
|
||||
{
|
||||
x: 1408734090000,
|
||||
y: 23
|
||||
},
|
||||
{
|
||||
x: 1408734120000,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 1408734150000,
|
||||
y: 28
|
||||
},
|
||||
{
|
||||
x: 1408734180000,
|
||||
y: 36
|
||||
},
|
||||
{
|
||||
x: 1408734210000,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 1408734240000,
|
||||
y: 26
|
||||
},
|
||||
{
|
||||
x: 1408734270000,
|
||||
y: 22
|
||||
},
|
||||
{
|
||||
x: 1408734300000,
|
||||
y: 29
|
||||
},
|
||||
{
|
||||
x: 1408734330000,
|
||||
y: 24
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
xAxisLabel: 'Date Histogram',
|
||||
yAxisLabel: 'Count'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
module('ChartSplitFactory');
|
||||
module('ChartTitleSplitFactory');
|
||||
module('XAxisSplitFactory');
|
||||
module('YAxisSplitFactory');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
chartSplit = Private(require('components/vislib/components/layouts/splits/column_chart/chart_split'));
|
||||
chartTitleSplit = Private(require('components/vislib/components/layouts/splits/column_chart/chart_title_split'));
|
||||
xAxisSplit = Private(require('components/vislib/components/layouts/splits/column_chart/x_axis_split'));
|
||||
yAxisSplit = Private(require('components/vislib/components/layouts/splits/column_chart/y_axis_split'));
|
||||
|
||||
el = d3.select('body').append('div')
|
||||
.attr('class', 'visualization')
|
||||
.datum(data);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
el.remove();
|
||||
});
|
||||
|
||||
describe('chart split function', function () {
|
||||
var fixture;
|
||||
{
|
||||
hits : 621,
|
||||
label : '',
|
||||
ordered : {
|
||||
date : true,
|
||||
interval: 30000,
|
||||
max : 1408734982458,
|
||||
min : 1408734082458
|
||||
},
|
||||
series : [
|
||||
{
|
||||
values: [
|
||||
{
|
||||
x: 1408734060000,
|
||||
y: 8
|
||||
},
|
||||
{
|
||||
x: 1408734090000,
|
||||
y: 23
|
||||
},
|
||||
{
|
||||
x: 1408734120000,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 1408734150000,
|
||||
y: 28
|
||||
},
|
||||
{
|
||||
x: 1408734180000,
|
||||
y: 36
|
||||
},
|
||||
{
|
||||
x: 1408734210000,
|
||||
y: 30
|
||||
},
|
||||
{
|
||||
x: 1408734240000,
|
||||
y: 26
|
||||
},
|
||||
{
|
||||
x: 1408734270000,
|
||||
y: 22
|
||||
},
|
||||
{
|
||||
x: 1408734300000,
|
||||
y: 29
|
||||
},
|
||||
{
|
||||
x: 1408734330000,
|
||||
y: 24
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
xAxisLabel: 'Date Histogram',
|
||||
yAxisLabel: 'Count'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
fixture = d3.select('.visualization').call(chartSplit);
|
||||
module('ChartSplitFactory');
|
||||
module('ChartTitleSplitFactory');
|
||||
module('XAxisSplitFactory');
|
||||
module('YAxisSplitFactory');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
chartSplit = Private(require('components/vislib/components/layouts/splits/column_chart/chart_split'));
|
||||
chartTitleSplit = Private(require('components/vislib/components/layouts/splits/column_chart/chart_title_split'));
|
||||
xAxisSplit = Private(require('components/vislib/components/layouts/splits/column_chart/x_axis_split'));
|
||||
yAxisSplit = Private(require('components/vislib/components/layouts/splits/column_chart/y_axis_split'));
|
||||
|
||||
el = d3.select('body').append('div')
|
||||
.attr('class', 'visualization')
|
||||
.datum(data);
|
||||
});
|
||||
});
|
||||
|
||||
it('should append the correct number of divs', function () {
|
||||
expect($('.chart').length).to.be(2);
|
||||
afterEach(function () {
|
||||
el.remove();
|
||||
});
|
||||
|
||||
it('should add the correct class name', function () {
|
||||
expect(!!$('.chart-wrapper-row').length).to.be(true);
|
||||
});
|
||||
});
|
||||
describe('chart split function', function () {
|
||||
var fixture;
|
||||
|
||||
describe('chart title split function', function () {
|
||||
var newEl;
|
||||
var fixture;
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
fixture = d3.select('.visualization').call(chartSplit);
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
el.append('div').attr('class', 'x-axis-chart-title');
|
||||
el.append('div').attr('class', 'y-axis-chart-title');
|
||||
d3.select('.x-axis-chart-title').call(chartTitleSplit);
|
||||
d3.select('.y-axis-chart-title').call(chartTitleSplit);
|
||||
afterEach(function () {
|
||||
fixture.remove();
|
||||
el.remove();
|
||||
});
|
||||
|
||||
newEl = d3.select('body').append('div')
|
||||
.attr('class', 'series')
|
||||
.datum({ series: []});
|
||||
newEl.append('div').attr('class', 'x-axis-chart-title');
|
||||
newEl.append('div').attr('class', 'y-axis-chart-title');
|
||||
newEl.select('.x-axis-chart-title').call(chartTitleSplit);
|
||||
newEl.select('.y-axis-chart-title').call(chartTitleSplit);
|
||||
fixture = newEl.selectAll(this.childNodes)[0].length;
|
||||
it('should append the correct number of divs', function () {
|
||||
expect($('.chart').length).to.be(2);
|
||||
});
|
||||
|
||||
it('should add the correct class name', function () {
|
||||
expect(!!$('.chart-wrapper-row').length).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should append the correct number of divs', function () {
|
||||
expect($('.chart-title').length).to.be(2);
|
||||
});
|
||||
describe('chart title split function', function () {
|
||||
var newEl;
|
||||
var fixture;
|
||||
|
||||
it('should remove the correct div', function () {
|
||||
expect($('.y-axis-chart-title').length).to.be(1);
|
||||
expect($('.x-axis-chart-title').length).to.be(0);
|
||||
});
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
el.append('div').attr('class', 'x-axis-chart-title');
|
||||
el.append('div').attr('class', 'y-axis-chart-title');
|
||||
d3.select('.x-axis-chart-title').call(chartTitleSplit);
|
||||
d3.select('.y-axis-chart-title').call(chartTitleSplit);
|
||||
|
||||
it('should remove all chart title divs when only one chart is rendered', function () {
|
||||
expect(fixture).to.be(0);
|
||||
});
|
||||
});
|
||||
newEl = d3.select('body').append('div')
|
||||
.attr('class', 'series')
|
||||
.datum({ series: []});
|
||||
newEl.append('div').attr('class', 'x-axis-chart-title');
|
||||
newEl.append('div').attr('class', 'y-axis-chart-title');
|
||||
newEl.select('.x-axis-chart-title').call(chartTitleSplit);
|
||||
newEl.select('.y-axis-chart-title').call(chartTitleSplit);
|
||||
fixture = newEl.selectAll(this.childNodes)[0].length;
|
||||
});
|
||||
});
|
||||
|
||||
describe('x axis split function', function () {
|
||||
var fixture;
|
||||
var divs;
|
||||
afterEach(function () {
|
||||
el.remove();
|
||||
newEl.remove();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
fixture = d3.select('body').append('div')
|
||||
.attr('class', 'columns')
|
||||
.datum({ columns: [{}, {}] });
|
||||
d3.select('.columns').call(xAxisSplit);
|
||||
divs = d3.selectAll('.x-axis-div')[0];
|
||||
it('should append the correct number of divs', function () {
|
||||
expect($('.chart-title').length).to.be(2);
|
||||
});
|
||||
|
||||
it('should remove the correct div', function () {
|
||||
expect($('.y-axis-chart-title').length).to.be(1);
|
||||
expect($('.x-axis-chart-title').length).to.be(0);
|
||||
});
|
||||
|
||||
it('should remove all chart title divs when only one chart is rendered', function () {
|
||||
expect(fixture).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should append the correct number of divs', function () {
|
||||
expect(divs.length).to.be(2);
|
||||
});
|
||||
});
|
||||
describe('x axis split function', function () {
|
||||
var fixture;
|
||||
var divs;
|
||||
|
||||
describe('y axis split function', function () {
|
||||
var fixture;
|
||||
var divs;
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
fixture = d3.select('body').append('div')
|
||||
.attr('class', 'columns')
|
||||
.datum({ columns: [{}, {}] });
|
||||
d3.select('.columns').call(xAxisSplit);
|
||||
divs = d3.selectAll('.x-axis-div')[0];
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
fixture = d3.select('body').append('div')
|
||||
.attr('class', 'rows')
|
||||
.datum({ rows: [{}, {}] });
|
||||
d3.select('.rows').call(yAxisSplit);
|
||||
divs = d3.selectAll('.y-axis-div')[0];
|
||||
afterEach(function () {
|
||||
fixture.remove();
|
||||
el.remove();
|
||||
});
|
||||
|
||||
it('should append the correct number of divs', function () {
|
||||
expect(divs.length).to.be(2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should append the correct number of divs', function () {
|
||||
expect(divs.length).to.be(2);
|
||||
describe('y axis split function', function () {
|
||||
var fixture;
|
||||
var divs;
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3) {
|
||||
fixture = d3.select('body').append('div')
|
||||
.attr('class', 'rows')
|
||||
.datum( { rows: [{}, {}] });
|
||||
d3.select('.rows').call(yAxisSplit);
|
||||
divs = d3.selectAll('.y-axis-div')[0];
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
fixture.remove();
|
||||
el.remove();
|
||||
});
|
||||
|
||||
it('should append the correct number of divs', function () {
|
||||
expect(divs.length).to.be(2);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,6 +10,7 @@ define(function (require) {
|
|||
var Data;
|
||||
var xAxis;
|
||||
var el;
|
||||
var fixture;
|
||||
var dataObj;
|
||||
var data = {
|
||||
hits: 621,
|
||||
|
@ -83,8 +84,9 @@ define(function (require) {
|
|||
Data = Private(require('components/vislib/modules/Data'));
|
||||
|
||||
el = d3.select('body').append('div')
|
||||
.attr('class', 'x-axis-wrapper')
|
||||
.append('div')
|
||||
.attr('class', 'x-axis-wrapper');
|
||||
|
||||
fixture = el.append('div')
|
||||
.attr('class', 'x-axis-div')
|
||||
.style('height', '20px');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue