diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/__snapshots__/step_data_source.test.tsx.snap b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/__snapshots__/step_data_source.test.tsx.snap new file mode 100644 index 000000000000..ba690127435c --- /dev/null +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/__snapshots__/step_data_source.test.tsx.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`StepDataSource should render normally 1`] = ` + + +
+ + +`; diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/components/header/__snapshots__/header.test.tsx.snap b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/components/header/__snapshots__/header.test.tsx.snap new file mode 100644 index 000000000000..40ce23f30de4 --- /dev/null +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/components/header/__snapshots__/header.test.tsx.snap @@ -0,0 +1,238 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Header should render data source finder when choose to use data source 1`] = ` +
+ +

+ +

+
+ + + + + + } + onChange={[Function]} + /> + + + + + + } + onChange={[Function]} + /> + + + + + + + + + + + + + + + +
+`; + +exports[`Header should render normally 1`] = ` +
+ +

+ +

+
+ + + + + + } + onChange={[Function]} + /> + + + + + + } + onChange={[Function]} + /> + + + + + + + + + + + +
+`; diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/components/header/header.test.tsx b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/components/header/header.test.tsx new file mode 100644 index 000000000000..0805f6a5f78e --- /dev/null +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/components/header/header.test.tsx @@ -0,0 +1,98 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { Header } from '../header'; +import { shallow } from 'enzyme'; + +describe('Header', () => { + it('should render normally', () => { + const component = shallow( +
{}} + dataSourceRef={{ type: 'type', id: 'id' }!} + goToNextStep={() => {}} + isNextStepDisabled={true} + stepInfo={{ totalStepNumber: 0, currentStepNumber: 0 }} + /> + ); + + expect(component).toMatchSnapshot(); + }); + + it('should render data source finder when choose to use data source', () => { + const component = shallow( +
{}} + dataSourceRef={{ type: 'type', id: 'id' }!} + goToNextStep={() => {}} + isNextStepDisabled={true} + stepInfo={{ totalStepNumber: 0, currentStepNumber: 0 }} + /> + ); + + component + .find('[data-test-subj="createIndexPatternStepDataSourceUseDataSourceRadio"]') + .simulate('change', { + target: { + checked: true, + }, + }); + + expect(component).toMatchSnapshot(); + }); + + it('should disable next step before select data source', () => { + const component = shallow( +
{}} + dataSourceRef={{ type: 'type', id: 'id' }!} + goToNextStep={() => {}} + isNextStepDisabled={true} + stepInfo={{ totalStepNumber: 0, currentStepNumber: 0 }} + /> + ); + + component + .find('[data-test-subj="createIndexPatternStepDataSourceUseDataSourceRadio"]') + .simulate('change', { + target: { + checked: true, + }, + }); + + expect( + component + .find('[data-test-subj="createIndexPatternStepDataSourceNextStepButton"]') + .prop('isDisabled') + ).toEqual(true); + }); + + it('should enable next step when pick default option', () => { + const component = shallow( +
{}} + dataSourceRef={{ type: 'type', id: 'id' }!} + goToNextStep={() => {}} + isNextStepDisabled={true} + stepInfo={{ totalStepNumber: 0, currentStepNumber: 0 }} + /> + ); + + component + .find('[data-test-subj="createIndexPatternStepDataSourceUseDefaultRadio"]') + .simulate('change', { + target: { + checked: true, + }, + }); + + expect( + component + .find('[data-test-subj="createIndexPatternStepDataSourceNextStepButton"]') + .prop('isDisabled') + ).toEqual(false); + }); +}); diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/components/header/header.tsx b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/components/header/header.tsx index b66aeceecb51..5786752b27e8 100644 --- a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/components/header/header.tsx +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/components/header/header.tsx @@ -27,7 +27,7 @@ import { useOpenSearchDashboards } from '../../../../../../../../../plugins/open import { StepInfo } from '../../../../types'; interface HeaderProps { - onSearchSelected: (id: string, type: string) => void; + onDataSourceSelected: (id: string, type: string) => void; dataSourceRef: DataSourceRef; goToNextStep: (dataSourceRef: DataSourceRef) => void; isNextStepDisabled: boolean; @@ -37,7 +37,7 @@ interface HeaderProps { const DATA_SOURCE_PAGE_SIZE = 5; export const Header: React.FC = (props: HeaderProps) => { - const { dataSourceRef, onSearchSelected, goToNextStep, isNextStepDisabled, stepInfo } = props; + const { dataSourceRef, onDataSourceSelected, goToNextStep, isNextStepDisabled, stepInfo } = props; const { currentStepNumber, totalStepNumber } = stepInfo; const [defaultChecked, setDefaultChecked] = useState(true); @@ -74,10 +74,9 @@ export const Header: React.FC = (props: HeaderProps) => { defaultMessage="Please pick the data source -- within which to configure index patterns." /> - - = (props: HeaderProps) => { = (props: HeaderProps) => { = (props: HeaderProps) => { { + it('should render normally', () => { + const component = shallow( + {}} + stepInfo={{ totalStepNumber: 0, currentStepNumber: 0 }} + /> + ); + + expect(component).toMatchSnapshot(); + }); +}); diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/step_data_source.tsx b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/step_data_source.tsx index ea16e93ae539..5e1b1c92f1aa 100644 --- a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/step_data_source.tsx +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/components/step_data_source/step_data_source.tsx @@ -21,7 +21,7 @@ export const StepDataSource = (props: StepDataSourceProps) => { const [selectedDataSource, setSelectedDataSource] = useState(); const [isNextStepDisabled, setIsNextStepDisabled] = useState(true); - const onSearchSelected = (id: string, selectedType: string) => { + const onDataSourceSelected = (id: string, selectedType: string) => { const selected = { id, type: selectedType }; setSelectedDataSource(selected); @@ -32,7 +32,7 @@ export const StepDataSource = (props: StepDataSourceProps) => { return (
goToNextStep(selectedDataSource!)} isNextStepDisabled={isNextStepDisabled}