From ea1242e4b548e8b54436a9fd64ef78d9f5d038a1 Mon Sep 17 00:00:00 2001 From: Owen Wang Date: Tue, 21 Jan 2025 16:34:48 +0800 Subject: [PATCH] fix: add check for data source description and adding tests Signed-off-by: Owen Wang --- .../data_source_table.test.tsx.snap | 3647 +++++++++++++++++ .../data_source_table.test.tsx | 39 +- .../data_source_table/data_source_table.tsx | 6 +- .../data_source_management/public/mocks.ts | 27 + 4 files changed, 3715 insertions(+), 4 deletions(-) diff --git a/src/plugins/data_source_management/public/components/data_source_table/__snapshots__/data_source_table.test.tsx.snap b/src/plugins/data_source_management/public/components/data_source_table/__snapshots__/data_source_table.test.tsx.snap index 0c2db331680b..129e373cdbbd 100644 --- a/src/plugins/data_source_management/public/components/data_source_table/__snapshots__/data_source_table.test.tsx.snap +++ b/src/plugins/data_source_management/public/components/data_source_table/__snapshots__/data_source_table.test.tsx.snap @@ -2704,6 +2704,3653 @@ exports[`DataSourceTable should get datasources successful should render normall `; +exports[`DataSourceTable should handle datasources with empty description correctly should render normally 1`] = ` + + + +
+ + +
+ +
+ + + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+ +
+ + +
+ + + Type + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="field_value_selection_0" + isOpen={false} + ownFocus={true} + panelClassName="euiFilterGroup__popoverPanel" + panelPaddingSize="none" + > +
+
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+ +
+ + +
+
+ +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ + +
+ +
+ + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > +
+
+ + + +
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + +
+ +
+
+ + +
+
+ + + + + + + + Type + + + + + + + + + + + + + + Related connections + + + + + +
+
+ + +
+ +
+
+ + +
+
+
+ Data source +
+
+ + + +
+
+
+ Type +
+
+ + OpenSearch + +
+
+
+ +
+ — +
+
+
+
+
+ Related connections +
+
+ +
+ — +
+
+
+
+
+ + +
+ +
+
+ + +
+
+
+ Data source +
+
+ + + +
+
+
+ Type +
+
+ + OpenSearch + +
+
+
+ +
+ — +
+
+
+
+
+ Related connections +
+
+ +
+ — +
+
+
+
+
+ + +
+ +
+
+ + +
+
+
+ Data source +
+
+ + + +
+
+
+ Type +
+
+ + OpenSearch + +
+
+
+ +
+ — +
+
+
+
+
+ Related connections +
+
+ +
+ — +
+
+
+
+
+
+ +
+ +
+ + + +
+ +
+ + + : + 10 + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > +
+
+ + + +
+
+
+
+
+ +
+ + + +
+
+
+
+
+
+ +
+ +
+ + + +`; + exports[`DataSourceTable should not manage datasources when canManageDataSource is false should render empty table 1`] = ` { mockedContext.application.capabilities = capabilities; }); }); + + describe('should handle datasources with empty description correctly', () => { + beforeEach(async () => { + spyOn(utils, 'getDataSources').and.returnValue( + Promise.resolve(getMappedDataSourcesWithEmptyDescription) + ); + spyOn(uiSettings, 'get$').and.returnValue(new BehaviorSubject('test1')); + await act(async () => { + component = await mount( + wrapWithIntl( + + ), + { + wrappingComponent: OpenSearchDashboardsContextProvider, + wrappingComponentProps: { + services: mockedContext, + }, + } + ); + }); + component.update(); + }); + + it('should render normally', () => { + expect(() => component).not.toThrow(); + expect(component).toMatchSnapshot(); + expect(utils.getDataSources).toHaveBeenCalled(); + }); + }); }); diff --git a/src/plugins/data_source_management/public/components/data_source_table/data_source_table.tsx b/src/plugins/data_source_management/public/components/data_source_table/data_source_table.tsx index 94d8a12187ef..3a49468075c6 100644 --- a/src/plugins/data_source_management/public/components/data_source_table/data_source_table.tsx +++ b/src/plugins/data_source_management/public/components/data_source_table/data_source_table.tsx @@ -297,9 +297,9 @@ export const DataSourceTable = ({ history }: RouteComponentProps) => { show: false, }, dataType: 'string' as const, - sortable: ({ description }: { description: string }) => description, - render: (description: string) => - description.length > 0 ? description : , + sortable: ({ description }: { description?: string }) => description, + render: (description?: string) => + !!description && description.length > 0 ? description : , }, { field: 'relatedConnections', diff --git a/src/plugins/data_source_management/public/mocks.ts b/src/plugins/data_source_management/public/mocks.ts index cd26df261ca8..2418ef4e0189 100644 --- a/src/plugins/data_source_management/public/mocks.ts +++ b/src/plugins/data_source_management/public/mocks.ts @@ -289,6 +289,33 @@ export const getMappedDataSources = [ }, ]; +export const getMappedDataSourcesWithEmptyDescription = [ + { + id: 'test-null', + type: 'OpenSearch', + title: 'test-null', + connectionType: 'OpenSearchConnection', + description: null, + relatedConnections: directQueryConnections, + }, + { + id: 'test-undefined', + type: 'OpenSearch', + title: 'test-undefined', + connectionType: 'OpenSearchConnection', + description: undefined, + relatedConnections: directQueryConnections, + }, + { + id: 'test-no-description', + type: 'OpenSearch', + title: 'test-no-description', + connectionType: 'OpenSearchConnection', + // no description + relatedConnections: directQueryConnections, + }, +]; + export const fetchDataSourceMetaData = { dataSourceVersion: '2.11.0', installedPlugins: ['opensearch-ml', 'opensearch-sql'],