diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.test.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.test.tsx
index f37dc088ac78e..e0c43105cb320 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.test.tsx
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.test.tsx
@@ -21,7 +21,6 @@ import React from 'react';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
import { IndexPatternCreationConfig } from '../../../../../../../../management/public';
import { IFieldType } from '../../../../../../../../../../plugins/data/public';
-import { dataPluginMock } from '../../../../../../../../../../plugins/data/public/mocks';
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/advanced_options', () => ({ AdvancedOptions: 'AdvancedOptions' }));
jest.mock('./components/action_buttons', () => ({ ActionButtons: 'ActionButtons' }));
-jest.mock('./../../lib/extract_time_fields', () => ({
- extractTimeFields: (fields: IFieldType) => fields,
+jest.mock('./../../lib', () => ({
+ extractTimeFields: require.requireActual('./../../lib').extractTimeFields,
+ ensureMinimumTime: async (fields: IFieldType) => Promise.resolve(fields),
}));
jest.mock('ui/chrome', () => ({
addBasePath: () => {},
@@ -42,7 +42,19 @@ const mockIndexPatternCreationType = new IndexPatternCreationConfig({
});
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', () => {
it('should render normally', () => {
@@ -292,4 +304,30 @@ describe('StepTimeField', () => {
error: 'foobar',
});
});
+
+ it('should call createIndexPattern with undefined time field when no time filter chosen', async () => {
+ const createIndexPattern = jest.fn();
+
+ const component = shallowWithI18nProvider(
+
+ );
+
+ 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);
+
+ await (component.instance() as StepTimeField).createIndexPattern();
+
+ expect(createIndexPattern).toHaveBeenCalledWith(undefined, '');
+ });
});
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.tsx
index dff2a07e460e2..80582cc1fbd92 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.tsx
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.tsx
@@ -41,7 +41,7 @@ interface StepTimeFieldProps {
indexPattern: string;
indexPatternsService: DataPublicPluginStart['indexPatterns'];
goToPreviousStep: () => void;
- createIndexPattern: (selectedTimeField: string, indexPatternId: string) => void;
+ createIndexPattern: (selectedTimeField: string | undefined, indexPatternId: string) => void;
indexPatternCreationType: IndexPatternCreationConfig;
}
@@ -143,7 +143,7 @@ export class StepTimeField extends Component