mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
fix tests
This commit is contained in:
parent
d4c1c76764
commit
543bb11a8a
3 changed files with 17 additions and 10 deletions
|
@ -3,8 +3,7 @@ define(function (require) {
|
||||||
var moment = require('moment');
|
var moment = require('moment');
|
||||||
|
|
||||||
return function orderedDateAxis(vis, chart) {
|
return function orderedDateAxis(vis, chart) {
|
||||||
var aspects = chart.aspects;
|
var xAgg = chart.aspects.x.agg;
|
||||||
var xAgg = aspects.x.agg;
|
|
||||||
var buckets = xAgg.buckets;
|
var buckets = xAgg.buckets;
|
||||||
var format = buckets.getScaledDateFormat();
|
var format = buckets.getScaledDateFormat();
|
||||||
|
|
||||||
|
@ -17,9 +16,8 @@ define(function (require) {
|
||||||
interval: buckets.getInterval(),
|
interval: buckets.getInterval(),
|
||||||
};
|
};
|
||||||
|
|
||||||
var axisOnTimeField = xAgg.fieldName() === xAgg.vis.indexPattern.timeFieldName;
|
var axisOnTimeField = xAgg.fieldIsTimeField();
|
||||||
var bounds = buckets.getBounds();
|
var bounds = buckets.getBounds();
|
||||||
|
|
||||||
if (bounds && axisOnTimeField) {
|
if (bounds && axisOnTimeField) {
|
||||||
chart.ordered.min = bounds.min;
|
chart.ordered.min = bounds.min;
|
||||||
chart.ordered.max = bounds.max;
|
chart.ordered.max = bounds.max;
|
||||||
|
|
|
@ -14,6 +14,7 @@ define(function (require) {
|
||||||
aspects: {
|
aspects: {
|
||||||
x: {
|
x: {
|
||||||
agg: {
|
agg: {
|
||||||
|
fieldIsTimeField: _.constant(true),
|
||||||
buckets: {
|
buckets: {
|
||||||
getScaledDateFormat: _.constant('hh:mm:ss'),
|
getScaledDateFormat: _.constant('hh:mm:ss'),
|
||||||
getInterval: _.constant(moment.duration(15, 'm')),
|
getInterval: _.constant(moment.duration(15, 'm')),
|
||||||
|
|
|
@ -5,19 +5,27 @@ define(function (require) {
|
||||||
|
|
||||||
describe('params', function () {
|
describe('params', function () {
|
||||||
var paramWriter;
|
var paramWriter;
|
||||||
|
var writeInterval;
|
||||||
|
|
||||||
var aggTypes;
|
var aggTypes;
|
||||||
var AggConfig;
|
var AggConfig;
|
||||||
var setTimeBounds;
|
var setTimeBounds;
|
||||||
|
var timeField;
|
||||||
|
|
||||||
beforeEach(module('kibana'));
|
beforeEach(module('kibana'));
|
||||||
beforeEach(inject(function (Private, $injector) {
|
beforeEach(inject(function (Private, $injector) {
|
||||||
var AggParamWriter = Private(require('test_utils/agg_param_writer'));
|
var AggParamWriter = Private(require('test_utils/agg_param_writer'));
|
||||||
|
var indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
|
||||||
var timefilter = $injector.get('timefilter');
|
var timefilter = $injector.get('timefilter');
|
||||||
|
|
||||||
|
timeField = indexPattern.timeFieldName;
|
||||||
aggTypes = Private(require('components/agg_types/index'));
|
aggTypes = Private(require('components/agg_types/index'));
|
||||||
AggConfig = Private(require('components/vis/_agg_config'));
|
AggConfig = Private(require('components/vis/_agg_config'));
|
||||||
|
|
||||||
paramWriter = new AggParamWriter({ aggType: 'date_histogram' });
|
paramWriter = new AggParamWriter({ aggType: 'date_histogram' });
|
||||||
|
writeInterval = function (interval) {
|
||||||
|
return paramWriter.write({ interval: interval, field: timeField });
|
||||||
|
};
|
||||||
|
|
||||||
var now = moment();
|
var now = moment();
|
||||||
setTimeBounds = function (n, units) {
|
setTimeBounds = function (n, units) {
|
||||||
|
@ -31,24 +39,24 @@ define(function (require) {
|
||||||
|
|
||||||
describe('interval', function () {
|
describe('interval', function () {
|
||||||
it('accepts a valid interval', function () {
|
it('accepts a valid interval', function () {
|
||||||
var output = paramWriter.write({ interval: 'day' });
|
var output = writeInterval('day');
|
||||||
expect(output.params).to.have.property('interval', '1d');
|
expect(output.params).to.have.property('interval', '1d');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores invalid intervals', function () {
|
it('ignores invalid intervals', function () {
|
||||||
var output = paramWriter.write({ interval: 'foo' });
|
var output = writeInterval('foo');
|
||||||
expect(output.params).to.have.property('interval', '0ms');
|
expect(output.params).to.have.property('interval', '0ms');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('automatically picks an interval', function () {
|
it('automatically picks an interval', function () {
|
||||||
setTimeBounds(15, 'minutes');
|
setTimeBounds(15, 'minutes');
|
||||||
var output = paramWriter.write({ interval: 'auto' });
|
var output = writeInterval('auto');
|
||||||
expect(output.params.interval).to.be('30s');
|
expect(output.params.interval).to.be('30s');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('scales up the interval if it will make too many buckets', function () {
|
it('scales up the interval if it will make too many buckets', function () {
|
||||||
setTimeBounds(30, 'minutes');
|
setTimeBounds(30, 'minutes');
|
||||||
var output = paramWriter.write({ interval: 'second' });
|
var output = writeInterval('second');
|
||||||
expect(output.params.interval).to.be('10s');
|
expect(output.params.interval).to.be('10s');
|
||||||
expect(output.metricScaleText).to.be('second');
|
expect(output.metricScaleText).to.be('second');
|
||||||
expect(output.metricScale).to.be(0.1);
|
expect(output.metricScale).to.be(0.1);
|
||||||
|
@ -56,7 +64,7 @@ define(function (require) {
|
||||||
|
|
||||||
it('does not scale down the interval', function () {
|
it('does not scale down the interval', function () {
|
||||||
setTimeBounds(1, 'minutes');
|
setTimeBounds(1, 'minutes');
|
||||||
var output = paramWriter.write({ interval: 'hour' });
|
var output = writeInterval('hour');
|
||||||
expect(output.params.interval).to.be('1h');
|
expect(output.params.interval).to.be('1h');
|
||||||
expect(output.metricScaleText).to.be(undefined);
|
expect(output.metricScaleText).to.be(undefined);
|
||||||
expect(output.metricScale).to.be(undefined);
|
expect(output.metricScale).to.be(undefined);
|
||||||
|
@ -82,7 +90,7 @@ define(function (require) {
|
||||||
var histoConfig = new AggConfig(vis, {
|
var histoConfig = new AggConfig(vis, {
|
||||||
type: aggTypes.byName.date_histogram,
|
type: aggTypes.byName.date_histogram,
|
||||||
schema: 'segment',
|
schema: 'segment',
|
||||||
params: { interval: 'second' }
|
params: { interval: 'second', field: timeField }
|
||||||
});
|
});
|
||||||
|
|
||||||
vis.aggs.push(histoConfig);
|
vis.aggs.push(histoConfig);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue