mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-05 15:48:03 +00:00
fix stored procedure summary panel exception (#22189)
This commit is contained in:
parent
02a5a5fcc2
commit
16b94538df
@ -11,9 +11,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import { isEmpty } from 'lodash';
|
||||||
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
|
import { EntityType } from '../enums/entity.enum';
|
||||||
import { SummaryEntityType } from '../enums/EntitySummary.enum';
|
import { SummaryEntityType } from '../enums/EntitySummary.enum';
|
||||||
import { Column } from '../generated/entity/data/table';
|
import { Column } from '../generated/entity/data/table';
|
||||||
import {
|
import {
|
||||||
|
getEntityChildDetails,
|
||||||
getFormattedEntityData,
|
getFormattedEntityData,
|
||||||
getHighlightOfListItem,
|
getHighlightOfListItem,
|
||||||
getMapOfListHighlights,
|
getMapOfListHighlights,
|
||||||
@ -35,6 +40,9 @@ import {
|
|||||||
mockLinkBasedSummaryTitleDashboardResponse,
|
mockLinkBasedSummaryTitleDashboardResponse,
|
||||||
mockLinkBasedSummaryTitleResponse,
|
mockLinkBasedSummaryTitleResponse,
|
||||||
mockListItemNameHighlight,
|
mockListItemNameHighlight,
|
||||||
|
mockStoredProcedureWithCode,
|
||||||
|
mockStoredProcedureWithEmptyCode,
|
||||||
|
mockStoredProcedureWithoutCode,
|
||||||
mockTagFQNsForHighlight,
|
mockTagFQNsForHighlight,
|
||||||
mockTagsSortAndHighlightResponse,
|
mockTagsSortAndHighlightResponse,
|
||||||
mockTextBasedSummaryTitleResponse,
|
mockTextBasedSummaryTitleResponse,
|
||||||
@ -49,6 +57,16 @@ jest.mock('../constants/EntitySummaryPanelUtils.constant', () => ({
|
|||||||
],
|
],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
jest.mock('../components/Database/SchemaEditor/SchemaEditor', () => {
|
||||||
|
return jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation(({ value }) => (
|
||||||
|
<div data-testid="schema-editor">
|
||||||
|
{isEmpty(value) ? 'No code available' : value}
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
describe('EntitySummaryPanelUtils tests', () => {
|
describe('EntitySummaryPanelUtils tests', () => {
|
||||||
describe('getFormattedEntityData', () => {
|
describe('getFormattedEntityData', () => {
|
||||||
it('getFormattedEntityData should return formatted data properly for table columns data with nesting, and also sort the data based on highlights', () => {
|
it('getFormattedEntityData should return formatted data properly for table columns data with nesting, and also sort the data based on highlights', () => {
|
||||||
@ -188,4 +206,94 @@ describe('EntitySummaryPanelUtils tests', () => {
|
|||||||
expect(result).toEqual(mockGetHighlightOfListItemResponse);
|
expect(result).toEqual(mockGetHighlightOfListItemResponse);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getEntityChildDetails', () => {
|
||||||
|
const renderWithRouter = (component: JSX.Element) => {
|
||||||
|
return render(<BrowserRouter>{component}</BrowserRouter>);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('STORED_PROCEDURE cases', () => {
|
||||||
|
it('should render stored procedure with code correctly', () => {
|
||||||
|
const result = getEntityChildDetails(
|
||||||
|
EntityType.STORED_PROCEDURE,
|
||||||
|
mockStoredProcedureWithCode
|
||||||
|
);
|
||||||
|
|
||||||
|
renderWithRouter(result as JSX.Element);
|
||||||
|
|
||||||
|
expect(screen.getByText('label.code')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('schema-editor')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('schema-editor')).toHaveTextContent(
|
||||||
|
'CREATE PROCEDURE test_stored_procedure() BEGIN SELECT * FROM users; END'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render stored procedure without code correctly (null storedProcedureCode)', () => {
|
||||||
|
const result = getEntityChildDetails(
|
||||||
|
EntityType.STORED_PROCEDURE,
|
||||||
|
mockStoredProcedureWithoutCode
|
||||||
|
);
|
||||||
|
|
||||||
|
renderWithRouter(result as JSX.Element);
|
||||||
|
|
||||||
|
expect(screen.getByText('label.code')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('schema-editor')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('schema-editor')).toHaveTextContent(
|
||||||
|
'No code available'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render stored procedure with empty code correctly', () => {
|
||||||
|
const result = getEntityChildDetails(
|
||||||
|
EntityType.STORED_PROCEDURE,
|
||||||
|
mockStoredProcedureWithEmptyCode
|
||||||
|
);
|
||||||
|
|
||||||
|
renderWithRouter(result as JSX.Element);
|
||||||
|
|
||||||
|
expect(screen.getByText('label.code')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('schema-editor')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('schema-editor')).toHaveTextContent(
|
||||||
|
'No code available'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render stored procedure with undefined code field correctly', () => {
|
||||||
|
const mockStoredProcedureWithUndefinedCode = {
|
||||||
|
...mockStoredProcedureWithCode,
|
||||||
|
storedProcedureCode: {
|
||||||
|
language: 'SQL',
|
||||||
|
code: undefined,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = getEntityChildDetails(
|
||||||
|
EntityType.STORED_PROCEDURE,
|
||||||
|
mockStoredProcedureWithUndefinedCode
|
||||||
|
);
|
||||||
|
|
||||||
|
renderWithRouter(result as JSX.Element);
|
||||||
|
|
||||||
|
expect(screen.getByText('label.code')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('schema-editor')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('schema-editor')).toHaveTextContent(
|
||||||
|
'No code available'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render stored procedure heading and testId correctly', () => {
|
||||||
|
const result = getEntityChildDetails(
|
||||||
|
EntityType.STORED_PROCEDURE,
|
||||||
|
mockStoredProcedureWithCode
|
||||||
|
);
|
||||||
|
|
||||||
|
renderWithRouter(result as JSX.Element);
|
||||||
|
|
||||||
|
expect(screen.getByTestId('code-header')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('code-header')).toHaveTextContent(
|
||||||
|
'label.code'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -544,7 +544,7 @@ export const getEntityChildDetails = (
|
|||||||
(
|
(
|
||||||
(entityInfo as StoredProcedure)
|
(entityInfo as StoredProcedure)
|
||||||
.storedProcedureCode as StoredProcedureCodeObject
|
.storedProcedureCode as StoredProcedureCodeObject
|
||||||
).code ?? ''
|
)?.code ?? ''
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -17,6 +17,10 @@ import { Link } from 'react-router-dom';
|
|||||||
import { BasicEntityInfo } from '../../components/Explore/EntitySummaryPanel/SummaryList/SummaryList.interface';
|
import { BasicEntityInfo } from '../../components/Explore/EntitySummaryPanel/SummaryList/SummaryList.interface';
|
||||||
import { ICON_DIMENSION } from '../../constants/constants';
|
import { ICON_DIMENSION } from '../../constants/constants';
|
||||||
import { Task } from '../../generated/entity/data/pipeline';
|
import { Task } from '../../generated/entity/data/pipeline';
|
||||||
|
import {
|
||||||
|
StoredProcedure,
|
||||||
|
StoredProcedureCodeObject,
|
||||||
|
} from '../../generated/entity/data/storedProcedure';
|
||||||
import {
|
import {
|
||||||
Column,
|
Column,
|
||||||
DataType,
|
DataType,
|
||||||
@ -396,3 +400,87 @@ export const mockInvalidDataResponse = [
|
|||||||
type: undefined,
|
type: undefined,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const mockStoredProcedureWithCode: StoredProcedure = {
|
||||||
|
id: '123e4567-e89b-12d3-a456-426614174000',
|
||||||
|
name: 'test_stored_procedure',
|
||||||
|
fullyQualifiedName: 'sample_database.test_stored_procedure',
|
||||||
|
description: 'A test stored procedure',
|
||||||
|
storedProcedureCode: {
|
||||||
|
language: 'SQL',
|
||||||
|
code: 'CREATE PROCEDURE test_stored_procedure()\nBEGIN\n SELECT * FROM users;\nEND',
|
||||||
|
} as StoredProcedureCodeObject,
|
||||||
|
databaseSchema: {
|
||||||
|
id: '456e7890-e12b-34c5-d678-901234567890',
|
||||||
|
name: 'test_schema',
|
||||||
|
fullyQualifiedName: 'sample_database.test_schema',
|
||||||
|
type: 'databaseSchema',
|
||||||
|
},
|
||||||
|
database: {
|
||||||
|
id: '789e0123-e45f-67g8-h901-234567890123',
|
||||||
|
name: 'sample_database',
|
||||||
|
fullyQualifiedName: 'sample_database',
|
||||||
|
type: 'database',
|
||||||
|
},
|
||||||
|
service: {
|
||||||
|
id: '012e3456-e78h-90i1-j234-567890123456',
|
||||||
|
name: 'mysql_service',
|
||||||
|
fullyQualifiedName: 'mysql_service',
|
||||||
|
type: 'databaseService',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mockStoredProcedureWithoutCode: StoredProcedure = {
|
||||||
|
id: '123e4567-e89b-12d3-a456-426614174001',
|
||||||
|
name: 'test_stored_procedure_no_code',
|
||||||
|
fullyQualifiedName: 'sample_database.test_stored_procedure_no_code',
|
||||||
|
description: 'A test stored procedure without code',
|
||||||
|
storedProcedureCode: null,
|
||||||
|
databaseSchema: {
|
||||||
|
id: '456e7890-e12b-34c5-d678-901234567890',
|
||||||
|
name: 'test_schema',
|
||||||
|
fullyQualifiedName: 'sample_database.test_schema',
|
||||||
|
type: 'databaseSchema',
|
||||||
|
},
|
||||||
|
database: {
|
||||||
|
id: '789e0123-e45f-67g8-h901-234567890123',
|
||||||
|
name: 'sample_database',
|
||||||
|
fullyQualifiedName: 'sample_database',
|
||||||
|
type: 'database',
|
||||||
|
},
|
||||||
|
service: {
|
||||||
|
id: '012e3456-e78h-90i1-j234-567890123456',
|
||||||
|
name: 'mysql_service',
|
||||||
|
fullyQualifiedName: 'mysql_service',
|
||||||
|
type: 'databaseService',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mockStoredProcedureWithEmptyCode: StoredProcedure = {
|
||||||
|
id: '123e4567-e89b-12d3-a456-426614174002',
|
||||||
|
name: 'test_stored_procedure_empty_code',
|
||||||
|
fullyQualifiedName: 'sample_database.test_stored_procedure_empty_code',
|
||||||
|
description: 'A test stored procedure with empty code',
|
||||||
|
storedProcedureCode: {
|
||||||
|
language: 'SQL',
|
||||||
|
code: '',
|
||||||
|
} as StoredProcedureCodeObject,
|
||||||
|
databaseSchema: {
|
||||||
|
id: '456e7890-e12b-34c5-d678-901234567890',
|
||||||
|
name: 'test_schema',
|
||||||
|
fullyQualifiedName: 'sample_database.test_schema',
|
||||||
|
type: 'databaseSchema',
|
||||||
|
},
|
||||||
|
database: {
|
||||||
|
id: '789e0123-e45f-67g8-h901-234567890123',
|
||||||
|
name: 'sample_database',
|
||||||
|
fullyQualifiedName: 'sample_database',
|
||||||
|
type: 'database',
|
||||||
|
},
|
||||||
|
service: {
|
||||||
|
id: '012e3456-e78h-90i1-j234-567890123456',
|
||||||
|
name: 'mysql_service',
|
||||||
|
fullyQualifiedName: 'mysql_service',
|
||||||
|
type: 'databaseService',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user