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..86a5cbb61bae 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,765 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +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); + }); + + 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).toBeCalled(); + expect(component.state('showEmptyState')).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); + }); + + 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); + } + ); +});