Fix Lens auto date bug (#49967)

This commit is contained in:
Chris Davies 2019-11-01 15:46:45 -04:00 committed by GitHub
parent 45617f0bbe
commit d10b7a1efb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 1 deletions

View file

@ -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');
});
});

View file

@ -89,7 +89,7 @@ export const autoDate: ExpressionFunction<
...c,
params: {
...c.params,
interval: interval.expression,
interval,
},
};
});