Skip to content

Commit

Permalink
fix for tests
Browse files Browse the repository at this point in the history
Signed-off-by: Eric <menwe@amazon.com>
  • Loading branch information
mengweieric committed Jul 30, 2024
1 parent 2324593 commit 0c92bf0
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
defaultDataSourceMetadata,
s3DataSourceMetadata,
} from '../constants';
import { IUiSettingsClient } from '../../../../../../src/core/public';

describe('DataSourceSelectable', () => {
let dataSourcesMock: DataSource[];
Expand All @@ -23,6 +24,7 @@ describe('DataSourceSelectable', () => {
let setSelectedSourcesMock: (sources: DataSourceOption[]) => void = jest.fn();
let setDataSourceOptionListMock: (sources: DataSourceGroup[]) => void = jest.fn();
let onFetchDataSetErrorMock: (error: Error) => void = jest.fn();
let uiSettingsMock: IUiSettingsClient;
const onRefresh: () => void = jest.fn();

beforeEach(() => {
Expand All @@ -46,6 +48,27 @@ describe('DataSourceSelectable', () => {
setSelectedSourcesMock = jest.fn();
setDataSourceOptionListMock = jest.fn();
onFetchDataSetErrorMock = jest.fn();
uiSettingsMock = {
get: jest.fn().mockImplementation((key) => {
switch (key) {
case 'home:useNewHomePage':
return true; // or false based on your test case
case 'query:enhancements:enabled':
return true; // or false based on your test case
default:
return undefined;
}
}),
get$: jest.fn(),
getAll: jest.fn(),
set: jest.fn(),
overrideLocalDefault: jest.fn(),
remove: jest.fn(),
removeMany: jest.fn(),
isDeclared: jest.fn(),
isDefault: jest.fn(),
isCustom: jest.fn(),
};
});

it('renders without crashing', () => {
Expand All @@ -58,6 +81,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);
});
Expand All @@ -73,6 +97,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);
});
Expand All @@ -93,6 +118,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);
});
Expand Down Expand Up @@ -131,6 +157,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);

Expand Down Expand Up @@ -183,6 +210,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);

Expand Down Expand Up @@ -235,6 +263,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);

Expand All @@ -259,6 +288,7 @@ describe('DataSourceSelectable', () => {
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
onRefresh={onRefresh}
uiSettings={uiSettingsMock}
/>
);
const refreshButton = getByLabelText('sourceRefresh');
Expand Down

0 comments on commit 0c92bf0

Please sign in to comment.