Fix Lens auto date bug (#49967)
This commit is contained in:
parent
45617f0bbe
commit
d10b7a1efb
|
@ -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…
Reference in a new issue