Skip to content

Commit

Permalink
[Multiple Datasource Test]add more test for icon and aggregated view (#…
Browse files Browse the repository at this point in the history
…6729) (#6740)

* add more test for icon and aggregated view



* Changeset file for PR #6729 created/updated

* Update CHANGELOG.md

---------



(cherry picked from commit 60f9d05)

Signed-off-by: yujin-emma <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
3 people authored May 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 5008e77 commit 3eab14f
Showing 7 changed files with 1,278 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6729.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Add more test for icon and aggregated view ([#6729](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6729))

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { shallow } from 'enzyme';
import React from 'react';
import { EmptyIcon } from './empty_icon';

describe('Test on empty icon', () => {
it('should render the component normally', () => {
const component = shallow(<EmptyIcon />);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { shallow } from 'enzyme';
import React from 'react';
import { ErrorIcon } from './error_icon';

describe('Test on empty icon', () => {
it('should render the component normally', () => {
const component = shallow(<ErrorIcon />);
expect(component).toMatchSnapshot();
});
});

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import {
getDataSourcesWithFieldsResponse,
mockResponseForSavedObjectsCalls,
mockUiSettingsCalls,
mockErrorResponseForSavedObjectsCalls,
} from '../../mocks';
import * as utils from '../utils';
import { EuiSelectable, EuiSwitch } from '@elastic/eui';
@@ -269,3 +270,235 @@ describe('DataSourceAggregatedView: read active view (displayAllCompatibleDataSo
}
);
});

describe('DataSourceAggregatedView empty state test with local cluster hiding', () => {
let component: ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>;
let client: SavedObjectsClientContract;
const { toasts } = notificationServiceMock.createStartContract();
const uiSettings = uiSettingsServiceMock.createStartContract();
const application = applicationServiceMock.createStartContract();
const nextTick = () => new Promise((res) => process.nextTick(res));

beforeEach(() => {
client = {
find: jest.fn().mockResolvedValue([]),
} as any;
mockResponseForSavedObjectsCalls(client, 'find', {});
mockUiSettingsCalls(uiSettings, 'get', 'test1');
jest.spyOn(utils, 'getApplication').mockReturnValue(application);
});

afterEach(() => {
jest.clearAllMocks(); // Clear all mocks to reset call counts and mock implementations
});

it.each([
{
filter: (ds: SavedObject<DataSourceAttributes>) => {
return true;
},
activeDataSourceIds: undefined,
hideLocalCluster: true,
displayAllCompatibleDataSources: true,
},
{
filter: (ds: SavedObject<DataSourceAttributes>) => {
return false;
},
activeDataSourceIds: undefined,
hideLocalCluster: true,
displayAllCompatibleDataSources: true,
},
{
filter: (ds: SavedObject<DataSourceAttributes>) => {
return true;
},
activeDataSourceIds: undefined,
hideLocalCluster: true,
displayAllCompatibleDataSources: false,
},
{
filter: (ds: SavedObject<DataSourceAttributes>) => {
return false;
},
activeDataSourceIds: undefined,
hideLocalCluster: true,
displayAllCompatibleDataSources: false,
},
])(
'should render warning when no data sources added',
async ({ filter, activeDataSourceIds, hideLocalCluster, displayAllCompatibleDataSources }) => {
component = shallow(
<DataSourceAggregatedView
fullWidth={false}
hideLocalCluster={hideLocalCluster}
savedObjectsClient={client}
notifications={toasts}
displayAllCompatibleDataSources={displayAllCompatibleDataSources}
uiSettings={uiSettings}
activeDataSourceIds={activeDataSourceIds}
dataSourceFilter={filter}
/>
);

expect(component).toMatchSnapshot();
await nextTick();
expect(toasts.add).toHaveBeenCalledTimes(1);
expect(toasts.add.mock.calls[0][0]).toEqual({
color: 'warning',
text: expect.any(Function),
title: 'No data sources connected yet. Connect your data sources to get started.',
});
expect(component.state('showEmptyState')).toBe(true);
await nextTick();
expect(component.find('NoDataSource').exists()).toBe(true);
}
);
});

describe('DataSourceAggregatedView empty state test due to filter out with local cluster hiding', () => {
let component: ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>;
let client: SavedObjectsClientContract;
const { toasts } = notificationServiceMock.createStartContract();
const uiSettings = uiSettingsServiceMock.createStartContract();
const application = applicationServiceMock.createStartContract();
const nextTick = () => new Promise((res) => process.nextTick(res));

beforeEach(() => {
client = {
find: jest.fn().mockResolvedValue([]),
} as any;
mockResponseForSavedObjectsCalls(client, 'find', getDataSourcesWithFieldsResponse);
mockUiSettingsCalls(uiSettings, 'get', 'test1');
jest.spyOn(utils, 'getApplication').mockReturnValue(application);
});

afterEach(() => {
jest.clearAllMocks(); // Clear all mocks to reset call counts and mock implementations
});

it.each([
{
filter: (ds: SavedObject<DataSourceAttributes>) => {
return false;
},
activeDataSourceIds: undefined,
hideLocalCluster: true,
displayAllCompatibleDataSources: true,
},
{
filter: (ds: SavedObject<DataSourceAttributes>) => {
return false;
},
activeDataSourceIds: undefined,
hideLocalCluster: true,
displayAllCompatibleDataSources: false,
},
])(
'should render warning when no data sources added',
async ({ filter, activeDataSourceIds, hideLocalCluster, displayAllCompatibleDataSources }) => {
component = shallow(
<DataSourceAggregatedView
fullWidth={false}
hideLocalCluster={hideLocalCluster}
savedObjectsClient={client}
notifications={toasts}
displayAllCompatibleDataSources={displayAllCompatibleDataSources}
uiSettings={uiSettings}
activeDataSourceIds={activeDataSourceIds}
dataSourceFilter={filter}
/>
);

expect(component).toMatchSnapshot();
await nextTick();
expect(toasts.add).toHaveBeenCalledTimes(1);
expect(toasts.add.mock.calls[0][0]).toEqual({
color: 'warning',
text: expect.any(Function),
title: 'No data sources connected yet. Connect your data sources to get started.',
});
expect(component.state('showEmptyState')).toBe(true);
await nextTick();
expect(component.find('NoDataSource').exists()).toBe(true);
}
);
});

describe('DataSourceAggregatedView error state test no matter hide local cluster or not', () => {
let component: ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>;
let client: SavedObjectsClientContract;
const { toasts } = notificationServiceMock.createStartContract();
const uiSettings = uiSettingsServiceMock.createStartContract();
const application = applicationServiceMock.createStartContract();
const nextTick = () => new Promise((res) => process.nextTick(res));

beforeEach(() => {
client = {
find: jest.fn().mockResolvedValue([]),
} as any;
mockErrorResponseForSavedObjectsCalls(client, 'find');
mockUiSettingsCalls(uiSettings, 'get', 'test1');
jest.spyOn(utils, 'getApplication').mockReturnValue(application);
});

afterEach(() => {
jest.clearAllMocks(); // Clear all mocks to reset call counts and mock implementations
});

it.each([
{
filter: (ds: SavedObject<DataSourceAttributes>) => {
return true;
},
activeDataSourceIds: undefined,
hideLocalCluster: true,
displayAllCompatibleDataSources: true,
},
{
filter: (ds: SavedObject<DataSourceAttributes>) => {
return false;
},
activeDataSourceIds: undefined,
hideLocalCluster: true,
displayAllCompatibleDataSources: true,
},
{
filter: (ds: SavedObject<DataSourceAttributes>) => {
return true;
},
activeDataSourceIds: undefined,
hideLocalCluster: true,
displayAllCompatibleDataSources: false,
},
{
filter: (ds: SavedObject<DataSourceAttributes>) => {
return false;
},
activeDataSourceIds: undefined,
hideLocalCluster: true,
displayAllCompatibleDataSources: false,
},
])(
'should render error state when catch error',
async ({ filter, activeDataSourceIds, hideLocalCluster, displayAllCompatibleDataSources }) => {
component = shallow(
<DataSourceAggregatedView
fullWidth={false}
hideLocalCluster={hideLocalCluster}
savedObjectsClient={client}
notifications={toasts}
displayAllCompatibleDataSources={displayAllCompatibleDataSources}
uiSettings={uiSettings}
activeDataSourceIds={activeDataSourceIds}
dataSourceFilter={filter}
/>
);

expect(component).toMatchSnapshot();
await nextTick();
expect(toasts.add).toBeCalled();
expect(component.state('showError')).toBe(true);
}
);
});

0 comments on commit 3eab14f

Please sign in to comment.