From 60f9d0522394a3d89bdf2f69bdb04bb9a14e9c4e Mon Sep 17 00:00:00 2001 From: Yu Jin <112784385+yujin-emma@users.noreply.github.com> Date: Tue, 7 May 2024 15:09:59 -0700 Subject: [PATCH] [Multiple Datasource Test]add more test for icon and aggregated view (#6729) * add more test for icon and aggregated view Signed-off-by: yujin-emma * Changeset file for PR #6729 created/updated * Update CHANGELOG.md --------- Signed-off-by: yujin-emma Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> --- changelogs/fragments/6729.yml | 2 + .../__snapshots__/empty_icon.test.tsx.snap | 39 + .../__snapshots__/error_icon.test.tsx.snap | 24 + .../custom_database_icon/empty_icon.test.tsx | 15 + .../custom_database_icon/error_icon.test.tsx | 15 + .../data_source_aggregated_view.test.tsx.snap | 950 ++++++++++++++++++ .../data_source_aggregated_view.test.tsx | 233 +++++ 7 files changed, 1278 insertions(+) create mode 100644 changelogs/fragments/6729.yml create mode 100644 src/plugins/data_source_management/public/components/custom_database_icon/__snapshots__/empty_icon.test.tsx.snap create mode 100644 src/plugins/data_source_management/public/components/custom_database_icon/__snapshots__/error_icon.test.tsx.snap create mode 100644 src/plugins/data_source_management/public/components/custom_database_icon/empty_icon.test.tsx create mode 100644 src/plugins/data_source_management/public/components/custom_database_icon/error_icon.test.tsx diff --git a/changelogs/fragments/6729.yml b/changelogs/fragments/6729.yml new file mode 100644 index 000000000000..8a564e684ffc --- /dev/null +++ b/changelogs/fragments/6729.yml @@ -0,0 +1,2 @@ +fix: +- Add more test for icon and aggregated view ([#6729](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6729)) \ No newline at end of file diff --git a/src/plugins/data_source_management/public/components/custom_database_icon/__snapshots__/empty_icon.test.tsx.snap b/src/plugins/data_source_management/public/components/custom_database_icon/__snapshots__/empty_icon.test.tsx.snap new file mode 100644 index 000000000000..28f9cf9d4c68 --- /dev/null +++ b/src/plugins/data_source_management/public/components/custom_database_icon/__snapshots__/empty_icon.test.tsx.snap @@ -0,0 +1,39 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Test on empty icon should render the component normally 1`] = ` + + + + + + + + +`; diff --git a/src/plugins/data_source_management/public/components/custom_database_icon/__snapshots__/error_icon.test.tsx.snap b/src/plugins/data_source_management/public/components/custom_database_icon/__snapshots__/error_icon.test.tsx.snap new file mode 100644 index 000000000000..fcb1050538a8 --- /dev/null +++ b/src/plugins/data_source_management/public/components/custom_database_icon/__snapshots__/error_icon.test.tsx.snap @@ -0,0 +1,24 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Test on empty icon should render the component normally 1`] = ` + + + + +`; diff --git a/src/plugins/data_source_management/public/components/custom_database_icon/empty_icon.test.tsx b/src/plugins/data_source_management/public/components/custom_database_icon/empty_icon.test.tsx new file mode 100644 index 000000000000..e72c429ec391 --- /dev/null +++ b/src/plugins/data_source_management/public/components/custom_database_icon/empty_icon.test.tsx @@ -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(); + expect(component).toMatchSnapshot(); + }); +}); diff --git a/src/plugins/data_source_management/public/components/custom_database_icon/error_icon.test.tsx b/src/plugins/data_source_management/public/components/custom_database_icon/error_icon.test.tsx new file mode 100644 index 000000000000..bba81a16f071 --- /dev/null +++ b/src/plugins/data_source_management/public/components/custom_database_icon/error_icon.test.tsx @@ -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(); + expect(component).toMatchSnapshot(); + }); +}); diff --git a/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap b/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap index f6324c17061d..23fee253ce08 100644 --- a/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap +++ b/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap @@ -1,5 +1,955 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`DataSourceAggregatedView empty state test due to filter out with local cluster hiding should render warning when no data sources added 1`] = ` + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="dataSourceSViewContextMenuPopover" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + + + + + + + + + + + + +`; + +exports[`DataSourceAggregatedView empty state test due to filter out with local cluster hiding should render warning when no data sources added 2`] = ` + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="dataSourceSViewContextMenuPopover" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + + + + + + + + + + + + + + + +`; + +exports[`DataSourceAggregatedView empty state test with local cluster hiding should render warning when no data sources added 1`] = ` + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="dataSourceSViewContextMenuPopover" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + + + + + + + + + + + + +`; + +exports[`DataSourceAggregatedView empty state test with local cluster hiding should render warning when no data sources added 2`] = ` + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="dataSourceSViewContextMenuPopover" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + + + + + + + + + + + + +`; + +exports[`DataSourceAggregatedView empty state test with local cluster hiding should render warning when no data sources added 3`] = ` + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="dataSourceSViewContextMenuPopover" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + + + + + + + + + + + + + + + +`; + +exports[`DataSourceAggregatedView empty state test with local cluster hiding should render warning when no data sources added 4`] = ` + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="dataSourceSViewContextMenuPopover" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + + + + + + + + + + + + + + + +`; + +exports[`DataSourceAggregatedView error state test no matter hide local cluster or not should render error state when catch error 1`] = ` + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="dataSourceSViewContextMenuPopover" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + + + + + + + + + + + + +`; + +exports[`DataSourceAggregatedView error state test no matter hide local cluster or not should render error state when catch error 2`] = ` + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="dataSourceSViewContextMenuPopover" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + + + + + + + + + + + + +`; + +exports[`DataSourceAggregatedView error state test no matter hide local cluster or not should render error state when catch error 3`] = ` + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="dataSourceSViewContextMenuPopover" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + + + + + + + + + + + + + + + +`; + +exports[`DataSourceAggregatedView error state test no matter hide local cluster or not should render error state when catch error 4`] = ` + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="dataSourceSViewContextMenuPopover" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + + + + + + + + + + + + + + + +`; + exports[`DataSourceAggregatedView: read active view (displayAllCompatibleDataSources is set to false) should render normally with local cluster and active selections configured 1`] = ` { + let component: ShallowWrapper, 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) => { + return true; + }, + activeDataSourceIds: undefined, + hideLocalCluster: true, + displayAllCompatibleDataSources: true, + }, + { + filter: (ds: SavedObject) => { + return false; + }, + activeDataSourceIds: undefined, + hideLocalCluster: true, + displayAllCompatibleDataSources: true, + }, + { + filter: (ds: SavedObject) => { + return true; + }, + activeDataSourceIds: undefined, + hideLocalCluster: true, + displayAllCompatibleDataSources: false, + }, + { + filter: (ds: SavedObject) => { + return false; + }, + activeDataSourceIds: undefined, + hideLocalCluster: true, + displayAllCompatibleDataSources: false, + }, + ])( + 'should render warning when no data sources added', + async ({ filter, activeDataSourceIds, hideLocalCluster, displayAllCompatibleDataSources }) => { + component = shallow( + + ); + + 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, 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) => { + return false; + }, + activeDataSourceIds: undefined, + hideLocalCluster: true, + displayAllCompatibleDataSources: true, + }, + { + filter: (ds: SavedObject) => { + return false; + }, + activeDataSourceIds: undefined, + hideLocalCluster: true, + displayAllCompatibleDataSources: false, + }, + ])( + 'should render warning when no data sources added', + async ({ filter, activeDataSourceIds, hideLocalCluster, displayAllCompatibleDataSources }) => { + component = shallow( + + ); + + 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, 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) => { + return true; + }, + activeDataSourceIds: undefined, + hideLocalCluster: true, + displayAllCompatibleDataSources: true, + }, + { + filter: (ds: SavedObject) => { + return false; + }, + activeDataSourceIds: undefined, + hideLocalCluster: true, + displayAllCompatibleDataSources: true, + }, + { + filter: (ds: SavedObject) => { + return true; + }, + activeDataSourceIds: undefined, + hideLocalCluster: true, + displayAllCompatibleDataSources: false, + }, + { + filter: (ds: SavedObject) => { + return false; + }, + activeDataSourceIds: undefined, + hideLocalCluster: true, + displayAllCompatibleDataSources: false, + }, + ])( + 'should render error state when catch error', + async ({ filter, activeDataSourceIds, hideLocalCluster, displayAllCompatibleDataSources }) => { + component = shallow( + + ); + + expect(component).toMatchSnapshot(); + await nextTick(); + expect(toasts.add).toBeCalled(); + expect(component.state('showError')).toBe(true); + } + ); +});