mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
adding labels test and update to color tests suite from Juan's repo
This commit is contained in:
parent
7940f92cf7
commit
181f3a4951
3 changed files with 301 additions and 1 deletions
|
@ -20,7 +20,7 @@ define(function (require) {
|
|||
return flattenSeries(obj);
|
||||
}
|
||||
|
||||
// Returns a kibana obj.series array
|
||||
// Returns a kibana obj.series array of objects with values array
|
||||
return obj.series;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -129,6 +129,11 @@ define(function (require) {
|
|||
it('should return an array of the same length as the input when input is greater than 72', function () {
|
||||
expect(createColorPalette(num3).length).to.be(num3);
|
||||
});
|
||||
|
||||
it('should create new darker colors when input is greater than 72', function () {
|
||||
expect(createColorPalette(num3)[72]).not.to.equal(seedColors[0]);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
295
test/unit/specs/vislib/labels.js
Normal file
295
test/unit/specs/vislib/labels.js
Normal file
|
@ -0,0 +1,295 @@
|
|||
define(function (require) {
|
||||
var angular = require('angular');
|
||||
var _ = require('lodash');
|
||||
|
||||
angular.module('LabelUtilService', ['kibana']);
|
||||
angular.module('GetArrayUtilService', ['kibana']);
|
||||
angular.module('UniqLabelUtilService', ['kibana']);
|
||||
angular.module('GetSeriesUtilService', ['kibana']);
|
||||
|
||||
var getLabels;
|
||||
var seriesLabels;
|
||||
var rowsLabels;
|
||||
var seriesArr;
|
||||
var rowsArr;
|
||||
var uniqLabels;
|
||||
var error;
|
||||
var seriesData = {
|
||||
'label': '',
|
||||
'series': [
|
||||
{
|
||||
'label': '100',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
};
|
||||
var rowsData = {
|
||||
'rows': [
|
||||
{
|
||||
'label': 'a',
|
||||
'series': [
|
||||
{
|
||||
'label': '100',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'b',
|
||||
'series': [
|
||||
{
|
||||
'label': '300',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'c',
|
||||
'series': [
|
||||
{
|
||||
'label': '100',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'd',
|
||||
'series': [
|
||||
{
|
||||
'label': '200',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
var columnsData = {
|
||||
'columns': [
|
||||
{
|
||||
'label': 'a',
|
||||
'series': [
|
||||
{
|
||||
'label': '100',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'b',
|
||||
'series': [
|
||||
{
|
||||
'label': '300',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'c',
|
||||
'series': [
|
||||
{
|
||||
'label': '100',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'label': 'd',
|
||||
'series': [
|
||||
{
|
||||
'label': '200',
|
||||
'values': [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
describe('Vislib Labels Module Test Suite', function () {
|
||||
|
||||
describe('Labels (main)', function () {
|
||||
beforeEach(function () {
|
||||
module('LabelUtilService');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
getLabels = Private(require('components/vislib/utils/labels/labels'));
|
||||
seriesLabels = getLabels(seriesData);
|
||||
rowsLabels = getLabels(rowsData);
|
||||
seriesArr = _.isArray(seriesLabels);
|
||||
rowsArr = _.isArray(rowsLabels);
|
||||
uniqLabels = _.chain(rowsData.rows)
|
||||
.pluck('series')
|
||||
.flatten()
|
||||
.pluck('label')
|
||||
.uniq()
|
||||
.value();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be a function', function () {
|
||||
expect(typeof getLabels).to.be('function');
|
||||
});
|
||||
|
||||
it('should return an array if input is data.series', function () {
|
||||
expect(seriesArr).to.be(true);
|
||||
});
|
||||
|
||||
it('should return an array if input is data.rows', function () {
|
||||
expect(rowsArr).to.be(true);
|
||||
});
|
||||
|
||||
it('should return empty array if input is not an object', function () {
|
||||
error = getLabels('string not object');
|
||||
expect(error.length).to.be(0);
|
||||
});
|
||||
|
||||
it('should return unique label values', function () {
|
||||
expect(rowsLabels[0]).to.equal(uniqLabels[0]);
|
||||
expect(rowsLabels[1]).to.equal(uniqLabels[1]);
|
||||
expect(rowsLabels[2]).to.equal(uniqLabels[2]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Data array', function () {
|
||||
var dataArray;
|
||||
var testSeries;
|
||||
var testRows;
|
||||
|
||||
beforeEach(function () {
|
||||
module('GetArrayUtilService');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
dataArray = Private(require('components/vislib/utils/labels/data_array'));
|
||||
seriesLabels = dataArray(seriesData);
|
||||
rowsLabels = dataArray(rowsData);
|
||||
testSeries = _.isArray(seriesLabels);
|
||||
testRows = _.isArray(rowsLabels);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be a function', function () {
|
||||
expect(typeof dataArray).to.equal('function');
|
||||
});
|
||||
|
||||
it('should return an array of objects if input is data.series', function () {
|
||||
expect(testSeries).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return an array of objects if input is data.rows', function () {
|
||||
expect(testRows).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return an array of same length as input data.series', function () {
|
||||
expect(seriesLabels.length).to.equal(seriesData.series.length);
|
||||
});
|
||||
|
||||
it('should return an array of same length as input data.rows', function () {
|
||||
expect(rowsLabels.length).to.equal(rowsData.rows.length);
|
||||
});
|
||||
|
||||
it('should return an array of objects with obj.labels and obj.values', function () {
|
||||
expect(seriesLabels[0].label).to.equal('100');
|
||||
expect(seriesLabels[0].values[0].x).to.equal(0);
|
||||
expect(seriesLabels[0].values[0].y).to.equal(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Unique labels', function () {
|
||||
var uniqLabels;
|
||||
var arrObj = [
|
||||
{'label': 'a'},
|
||||
{'label': 'b'},
|
||||
{'label': 'b'},
|
||||
{'label': 'c'},
|
||||
{'label': 'c'},
|
||||
{'label': 'd'},
|
||||
{'label': 'f'}
|
||||
];
|
||||
var uniq;
|
||||
var testArr;
|
||||
|
||||
beforeEach(function () {
|
||||
module('UniqLabelUtilService');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
uniqLabels = Private(require('components/vislib/utils/labels/uniq_labels'));
|
||||
uniq = uniqLabels(arrObj);
|
||||
testArr = _.isArray(uniq);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be a function', function () {
|
||||
expect(typeof uniqLabels).to.be('function');
|
||||
});
|
||||
|
||||
it('should return an array', function () {
|
||||
expect(testArr).to.be(true);
|
||||
});
|
||||
|
||||
it('should return array of 5 unique values', function () {
|
||||
expect(uniq.length).to.be(5);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Get series', function () {
|
||||
var getSeries;
|
||||
var columnsLabels;
|
||||
var rowsLabels;
|
||||
var seriesLabels;
|
||||
var columnsArr;
|
||||
var rowsArr;
|
||||
var seriesArr;
|
||||
var error;
|
||||
|
||||
beforeEach(function () {
|
||||
module('GetSeriesUtilService');
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
inject(function (d3, Private) {
|
||||
getSeries = Private(require('components/vislib/utils/labels/get_series'));
|
||||
columnsLabels = getSeries(columnsData);
|
||||
rowsLabels = getSeries(rowsData);
|
||||
seriesLabels = getSeries(seriesData);
|
||||
columnsArr = _.isArray(columnsLabels);
|
||||
rowsArr = _.isArray(rowsLabels);
|
||||
seriesArr = _.isArray(seriesLabels);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be a function', function () {
|
||||
expect(typeof getSeries).to.be('function');
|
||||
});
|
||||
|
||||
it('should return an array if input is data.columns', function () {
|
||||
expect(columnsArr).to.be(true);
|
||||
});
|
||||
|
||||
it('should return an array if input is data.rows', function () {
|
||||
expect(rowsArr).to.be(true);
|
||||
});
|
||||
|
||||
it('should return an empty array if input is data.series', function () {
|
||||
expect(seriesLabels.length).to.be(0);
|
||||
});
|
||||
|
||||
it('should return an array of the same length as as input data.columns', function () {
|
||||
expect(columnsLabels.length).to.be(columnsData.columns.length);
|
||||
});
|
||||
|
||||
it('should return an array of the same length as as input data.rows', function () {
|
||||
expect(rowsLabels.length).to.be(rowsData.rows.length);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue