mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
parent
908ec4c823
commit
b61401233f
2 changed files with 77 additions and 1 deletions
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { autoDate } from './auto_date';
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
jest.mock('ui/chrome');
|
||||
|
||||
describe('auto_date', () => {
|
||||
it('should do nothing if no time range is provided', () => {
|
||||
const result = autoDate.fn(
|
||||
{
|
||||
type: 'kibana_context',
|
||||
},
|
||||
{
|
||||
aggConfigs: 'canttouchthis',
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
expect(result).toEqual('canttouchthis');
|
||||
});
|
||||
|
||||
it('should not change anything if there are no auto date histograms', () => {
|
||||
const aggConfigs = JSON.stringify([
|
||||
{ type: 'date_histogram', params: { interval: '35h' } },
|
||||
{ type: 'count' },
|
||||
]);
|
||||
const result = autoDate.fn(
|
||||
{
|
||||
timeRange: {
|
||||
from: 'now-10d',
|
||||
to: 'now',
|
||||
},
|
||||
type: 'kibana_context',
|
||||
},
|
||||
{
|
||||
aggConfigs,
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
expect(result).toEqual(aggConfigs);
|
||||
});
|
||||
|
||||
it('should change auto date histograms', () => {
|
||||
const aggConfigs = JSON.stringify([
|
||||
{ type: 'date_histogram', params: { interval: 'auto' } },
|
||||
{ type: 'count' },
|
||||
]);
|
||||
const result = autoDate.fn(
|
||||
{
|
||||
timeRange: {
|
||||
from: 'now-10d',
|
||||
to: 'now',
|
||||
},
|
||||
type: 'kibana_context',
|
||||
},
|
||||
{
|
||||
aggConfigs,
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
const interval = JSON.parse(result).find(
|
||||
(agg: { type: string }) => agg.type === 'date_histogram'
|
||||
).params.interval;
|
||||
|
||||
expect(interval).toBeTruthy();
|
||||
expect(typeof interval).toEqual('string');
|
||||
expect(interval).not.toEqual('auto');
|
||||
});
|
||||
});
|
|
@ -89,7 +89,7 @@ export const autoDate: ExpressionFunction<
|
|||
...c,
|
||||
params: {
|
||||
...c.params,
|
||||
interval: interval.expression,
|
||||
interval,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue