Skip to content

Commit

Permalink
[UT] Add unittest to test registered credential form get rendered in …
Browse files Browse the repository at this point in the history
…create datasource page

Signed-off-by: Xinrui Bai <[email protected]>
  • Loading branch information
xinruiba committed Mar 2, 2024
1 parent b128a67 commit 1a620b7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EuiSuperSelectOption } from '@elastic/eui';
export interface AuthenticationMethod {
name: string;
credentialSourceOption: EuiSuperSelectOption<string>;
credentialForm?: React.JSX.Element;
credentialForm?: (state?: any, setState?: any) => React.JSX.Element;
crendentialFormField?: { [key: string]: string };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]`;
Expand Down Expand Up @@ -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<any, Readonly<{}>, 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(
<CreateDataSourceForm
handleTestConnection={mockTestConnectionHandler}
handleSubmit={mockSubmitHandler}
handleCancel={mockCancelHandler}
existingDatasourceNamesList={['dup20']}
/>
),
{
wrappingComponent: OpenSearchDashboardsContextProvider,
wrappingComponentProps: {
services: mockedContext,
},
}
);

expect(mockCredentialForm).toHaveBeenCalled();
});
});

0 comments on commit 1a620b7

Please sign in to comment.