mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Fix for Vis Editor] Revert setting time field to empty string when it's undefined (#58873) (#59407)
* Revert setting time field to empty string when it's undefined * Add unit test * Mock timeFields * Update step_time_field.test.tsx Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
f3f867295f
commit
0342399452
2 changed files with 44 additions and 6 deletions
|
@ -21,7 +21,6 @@ import React from 'react';
|
||||||
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
|
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
|
||||||
import { IndexPatternCreationConfig } from '../../../../../../../../management/public';
|
import { IndexPatternCreationConfig } from '../../../../../../../../management/public';
|
||||||
import { IFieldType } from '../../../../../../../../../../plugins/data/public';
|
import { IFieldType } from '../../../../../../../../../../plugins/data/public';
|
||||||
import { dataPluginMock } from '../../../../../../../../../../plugins/data/public/mocks';
|
|
||||||
|
|
||||||
import { StepTimeField } from '../step_time_field';
|
import { StepTimeField } from '../step_time_field';
|
||||||
|
|
||||||
|
@ -29,8 +28,9 @@ jest.mock('./components/header', () => ({ Header: 'Header' }));
|
||||||
jest.mock('./components/time_field', () => ({ TimeField: 'TimeField' }));
|
jest.mock('./components/time_field', () => ({ TimeField: 'TimeField' }));
|
||||||
jest.mock('./components/advanced_options', () => ({ AdvancedOptions: 'AdvancedOptions' }));
|
jest.mock('./components/advanced_options', () => ({ AdvancedOptions: 'AdvancedOptions' }));
|
||||||
jest.mock('./components/action_buttons', () => ({ ActionButtons: 'ActionButtons' }));
|
jest.mock('./components/action_buttons', () => ({ ActionButtons: 'ActionButtons' }));
|
||||||
jest.mock('./../../lib/extract_time_fields', () => ({
|
jest.mock('./../../lib', () => ({
|
||||||
extractTimeFields: (fields: IFieldType) => fields,
|
extractTimeFields: require.requireActual('./../../lib').extractTimeFields,
|
||||||
|
ensureMinimumTime: async (fields: IFieldType) => Promise.resolve(fields),
|
||||||
}));
|
}));
|
||||||
jest.mock('ui/chrome', () => ({
|
jest.mock('ui/chrome', () => ({
|
||||||
addBasePath: () => {},
|
addBasePath: () => {},
|
||||||
|
@ -42,7 +42,19 @@ const mockIndexPatternCreationType = new IndexPatternCreationConfig({
|
||||||
});
|
});
|
||||||
|
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
const indexPatternsService = dataPluginMock.createStartContract().indexPatterns;
|
const fields = [
|
||||||
|
{
|
||||||
|
name: '@timestamp',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const indexPatternsService = {
|
||||||
|
make: () => ({
|
||||||
|
fieldsFetcher: {
|
||||||
|
fetchForWildcard: jest.fn().mockReturnValue(Promise.resolve(fields)),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
} as any;
|
||||||
|
|
||||||
describe('StepTimeField', () => {
|
describe('StepTimeField', () => {
|
||||||
it('should render normally', () => {
|
it('should render normally', () => {
|
||||||
|
@ -292,4 +304,30 @@ describe('StepTimeField', () => {
|
||||||
error: 'foobar',
|
error: 'foobar',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should call createIndexPattern with undefined time field when no time filter chosen', async () => {
|
||||||
|
const createIndexPattern = jest.fn();
|
||||||
|
|
||||||
|
const component = shallowWithI18nProvider(
|
||||||
|
<StepTimeField
|
||||||
|
indexPattern="ki*"
|
||||||
|
indexPatternsService={indexPatternsService}
|
||||||
|
goToPreviousStep={noop}
|
||||||
|
createIndexPattern={createIndexPattern}
|
||||||
|
indexPatternCreationType={mockIndexPatternCreationType}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
await (component.instance() as StepTimeField).fetchTimeFields();
|
||||||
|
|
||||||
|
expect((component.state() as any).timeFields).toHaveLength(3);
|
||||||
|
|
||||||
|
(component.instance() as StepTimeField).onTimeFieldChanged(({
|
||||||
|
target: { value: undefined },
|
||||||
|
} as unknown) as React.ChangeEvent<HTMLSelectElement>);
|
||||||
|
|
||||||
|
await (component.instance() as StepTimeField).createIndexPattern();
|
||||||
|
|
||||||
|
expect(createIndexPattern).toHaveBeenCalledWith(undefined, '');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -41,7 +41,7 @@ interface StepTimeFieldProps {
|
||||||
indexPattern: string;
|
indexPattern: string;
|
||||||
indexPatternsService: DataPublicPluginStart['indexPatterns'];
|
indexPatternsService: DataPublicPluginStart['indexPatterns'];
|
||||||
goToPreviousStep: () => void;
|
goToPreviousStep: () => void;
|
||||||
createIndexPattern: (selectedTimeField: string, indexPatternId: string) => void;
|
createIndexPattern: (selectedTimeField: string | undefined, indexPatternId: string) => void;
|
||||||
indexPatternCreationType: IndexPatternCreationConfig;
|
indexPatternCreationType: IndexPatternCreationConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ export class StepTimeField extends Component<StepTimeFieldProps, StepTimeFieldSt
|
||||||
const { selectedTimeField, indexPatternId } = this.state;
|
const { selectedTimeField, indexPatternId } = this.state;
|
||||||
this.setState({ isCreating: true });
|
this.setState({ isCreating: true });
|
||||||
try {
|
try {
|
||||||
await createIndexPattern(selectedTimeField || '', indexPatternId);
|
await createIndexPattern(selectedTimeField, indexPatternId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!this.mounted) return;
|
if (!this.mounted) return;
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue