Skip to content

Commit

Permalink
[UT] Fix broken test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Xinrui Bai <xinruiba@amazon.com>
  • Loading branch information
xinruiba committed Feb 23, 2024
1 parent 91e734e commit fc0369e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface AuthenticationMethod {
name: string;
credentialSourceOption: EuiSuperSelectOption<string>;
credentialForm?: React.JSX.Element;
crendentialFormField?: { [key: string]: [value: string] };
crendentialFormField?: { [key: string]: string };
}

export type IAuthenticationMethodRegistery = Omit<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import { OpenSearchDashboardsContextProvider } from '../../../../../../opensearc
import { CreateDataSourceForm } from './create_data_source_form';
// @ts-ignore
import { findTestSubject } from '@elastic/eui/lib/test';
import { AuthType } from '../../../../types';
import {
AuthType,
noAuthCredentialAuthMethod,
sigV4AuthMethod,
usernamePasswordAuthMethod,
} from '../../../../types';

const titleIdentifier = '[data-test-subj="createDataSourceFormTitleField"]';
const descriptionIdentifier = `[data-test-subj="createDataSourceFormDescriptionField"]`;
Expand All @@ -24,6 +29,14 @@ const testConnectionButtonIdentifier = '[data-test-subj="createDataSourceTestCon

describe('Datasource Management: Create Datasource form', () => {
const mockedContext = mockManagementPlugin.createDataSourceManagementContext();
mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(
noAuthCredentialAuthMethod
);
mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(
usernamePasswordAuthMethod
);
mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(sigV4AuthMethod);

let component: ReactWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>;
const mockSubmitHandler = jest.fn();
const mockTestConnectionHandler = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
UsernamePasswordTypedContent,
defaultAuthType,
noAuthCredentialAuthMethod,
noAuthCredentialField,
sigV4ServiceOptions,
} from '../../../../types';
import { Header } from '../header';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {
import { OpenSearchDashboardsContextProvider } from '../../../../../../opensearch_dashboards_react/public';
import { EditDataSourceForm } from './edit_data_source_form';
import { act } from 'react-dom/test-utils';
import { AuthType } from '../../../../types';
import {
AuthType,
noAuthCredentialAuthMethod,
sigV4AuthMethod,
usernamePasswordAuthMethod,
} from '../../../../types';

const titleFieldIdentifier = 'dataSourceTitle';
const titleFormRowIdentifier = '[data-test-subj="editDataSourceTitleFormRow"]';
Expand All @@ -29,6 +34,14 @@ const passwordFieldIdentifier = '[data-test-subj="updateDataSourceFormPasswordFi
const updatePasswordBtnIdentifier = '[data-test-subj="editDatasourceUpdatePasswordBtn"]';
describe('Datasource Management: Edit Datasource Form', () => {
const mockedContext = mockManagementPlugin.createDataSourceManagementContext();
mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(
noAuthCredentialAuthMethod
);
mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(
usernamePasswordAuthMethod
);
mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(sigV4AuthMethod);

let component: ReactWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>;
const mockFn = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,25 @@ import { wrapWithIntl } from 'test_utils/enzyme_helpers';
import { RouteComponentProps } from 'react-router-dom';
import { OpenSearchDashboardsContextProvider } from '../../../../opensearch_dashboards_react/public';
import { EditDataSource } from './edit_data_source';
import {
noAuthCredentialAuthMethod,
sigV4AuthMethod,
usernamePasswordAuthMethod,
} from '../../types';

const formIdentifier = 'EditDataSourceForm';
const notFoundIdentifier = '[data-test-subj="dataSourceNotFound"]';

describe('Datasource Management: Edit Datasource Wizard', () => {
const mockedContext = mockManagementPlugin.createDataSourceManagementContext();
mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(
noAuthCredentialAuthMethod
);
mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(
usernamePasswordAuthMethod
);
mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(sigV4AuthMethod);

let component: ReactWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>;
const history = (scopedHistoryMock.create() as unknown) as ScopedHistory;

Expand Down
12 changes: 11 additions & 1 deletion src/plugins/data_source_management/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from './plugin';
import { managementPluginMock } from '../../management/public/mocks';
import { mockManagementPlugin as indexPatternManagementPluginMock } from '../../index_pattern_management/public/mocks';
import { AuthenticationMethod } from './auth_registry';
import { AuthenticationMethod, AuthenticationMethodRegistery } from './auth_registry';

/* Mock Types */

Expand All @@ -30,6 +30,8 @@ export const docLinks = {
},
};

export const authenticationMethodRegistery = new AuthenticationMethodRegistery();

const createDataSourceManagementContext = () => {
const {
chrome,
Expand All @@ -51,6 +53,7 @@ const createDataSourceManagementContext = () => {
http,
docLinks,
setBreadcrumbs: () => {},
authenticationMethodRegistery,
};
};

Expand Down Expand Up @@ -220,6 +223,13 @@ export const testDataSourceManagementPlugin = (
const setup = plugin.setup(coreSetup, {
management: managementPluginMock.createSetupContract(),
indexPatternManagement: indexPatternManagementPluginMock.createSetupContract(),
dataSource: {
dataSourceEnabled: true,
hideLocalCluster: true,
noAuthenticationTypeEnabled: true,
usernamePasswordAuthEnabled: true,
awsSigV4AuthEnabled: true,
},
});
const doStart = () => {
const start = plugin.start(coreStart);
Expand Down

0 comments on commit fc0369e

Please sign in to comment.