diff --git a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts index 00c3b0dbf0ee..5593b82f7bf6 100644 --- a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts +++ b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts @@ -9,7 +9,7 @@ import { EuiSuperSelectOption } from '@elastic/eui'; export interface AuthenticationMethod { name: string; credentialSourceOption: EuiSuperSelectOption; - credentialForm?: React.JSX.Element; + credentialForm?: (state?: any, setState?: any) => React.JSX.Element; crendentialFormField?: { [key: string]: string }; } diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx index 4f30ba9da5e4..38b3cd61c3ad 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx @@ -17,7 +17,10 @@ import { sigV4AuthMethod, usernamePasswordAuthMethod, } from '../../../../types'; -import { AuthenticationMethodRegistery } from 'src/plugins/data_source_management/public/auth_registry'; +import { + AuthenticationMethod, + AuthenticationMethodRegistery, +} from 'src/plugins/data_source_management/public/auth_registry'; const titleIdentifier = '[data-test-subj="createDataSourceFormTitleField"]'; const descriptionIdentifier = `[data-test-subj="createDataSourceFormDescriptionField"]`; @@ -363,3 +366,47 @@ describe('Datasource Management: Create Datasource form with different authType }); }); }); + +describe('Datasource Management: Create Datasource form with registered Auth Type', () => { + let component: ReactWrapper, React.Component<{}, {}, any>>; + const mockSubmitHandler = jest.fn(); + const mockTestConnectionHandler = jest.fn(); + const mockCancelHandler = jest.fn(); + const mockCredentialForm = jest.fn(); + + /* Scenario 1: should render the page normally when only one registered Auth Type supported */ + test('should render the page normally when only one registered Auth Type supported', () => { + const authTypeToBeTested = 'Some Auth Type'; + const authMethodToBeTest = { + name: authTypeToBeTested, + credentialSourceOption: { + value: authTypeToBeTested, + inputDisplay: 'some input', + }, + credentialForm: mockCredentialForm, + } as AuthenticationMethod; + + const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); + mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); + mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTest); + + component = mount( + wrapWithIntl( + + ), + { + wrappingComponent: OpenSearchDashboardsContextProvider, + wrappingComponentProps: { + services: mockedContext, + }, + } + ); + + expect(mockCredentialForm).toHaveBeenCalled(); + }); +});