From db75711f043a9e1f2872a1053fe7dda1459d4f08 Mon Sep 17 00:00:00 2001 From: yujin-emma Date: Tue, 7 May 2024 05:06:45 +0000 Subject: [PATCH 1/3] add more test for icon and aggregated view Signed-off-by: yujin-emma --- CHANGELOG.md | 1 + .../__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, 1277 insertions(+) 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/CHANGELOG.md b/CHANGELOG.md index aa524b4ec4dd..94e8be4d89b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [Multiple Datasource] Add empty state component for no connected data source ([#6499](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6499)) - [Multiple Datasource] Add popover for empty state and redirect to data source management page([#6514](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6514)) - [Multiple Datasource] Update empty state font size and footer button size to small ([6549](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6549)) +- [Multiple Datasource] Add UT for empty, error icon and aggregated view ([#6729](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6729)) - [Workspace] Add APIs to support plugin state in request ([#6303](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6303)) - [Workspace] Filter left nav menu items according to the current workspace ([#6234](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6234)) - [Multiple Datasource] Add multi data source support to Timeline ([#6385](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6385)) 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); + } + ); +}); From bcb355e48b99070bbea6dcf4e52ad7824dce749e Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 19:03:37 +0000 Subject: [PATCH 2/3] Changeset file for PR #6729 created/updated --- changelogs/fragments/6729.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/6729.yml 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 From d457fa1ac5ec96227d63cbb82f9f282bf09d8fff Mon Sep 17 00:00:00 2001 From: Yu Jin <112784385+yujin-emma@users.noreply.github.com> Date: Tue, 7 May 2024 13:09:00 -0700 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94e8be4d89b3..aa524b4ec4dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,7 +89,6 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [Multiple Datasource] Add empty state component for no connected data source ([#6499](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6499)) - [Multiple Datasource] Add popover for empty state and redirect to data source management page([#6514](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6514)) - [Multiple Datasource] Update empty state font size and footer button size to small ([6549](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6549)) -- [Multiple Datasource] Add UT for empty, error icon and aggregated view ([#6729](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6729)) - [Workspace] Add APIs to support plugin state in request ([#6303](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6303)) - [Workspace] Filter left nav menu items according to the current workspace ([#6234](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6234)) - [Multiple Datasource] Add multi data source support to Timeline ([#6385](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6385))