diff --git a/openmetadata-ui/src/main/resources/ui/src/components/TableQueries/QueryCard.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/TableQueries/QueryCard.test.tsx index f85e3e844df..65251b1fefc 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/TableQueries/QueryCard.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/TableQueries/QueryCard.test.tsx @@ -11,7 +11,12 @@ * limitations under the License. */ -import { findByText, getByTestId, render } from '@testing-library/react'; +import { + findByText, + getByTestId, + queryByTestId, + render, +} from '@testing-library/react'; import React from 'react'; import { MemoryRouter } from 'react-router-dom'; import QueryCard from './QueryCard'; @@ -54,4 +59,28 @@ describe('Test QueryCard Component', () => { expect(query).toBeInTheDocument(); expect(copyQueryButton).toBeInTheDocument(); }); + + it('Should not render header if user is undefined', async () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + const queryHeader = queryByTestId(container, 'query-header'); + + expect(queryHeader).not.toBeInTheDocument(); + }); + + it('Should not render header if duration is undefined', async () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + const queryHeader = queryByTestId(container, 'query-header'); + + expect(queryHeader).not.toBeInTheDocument(); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/TableQueries/QueryCard.tsx b/openmetadata-ui/src/main/resources/ui/src/components/TableQueries/QueryCard.tsx index 9b32a318476..e0ab5b59f67 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/TableQueries/QueryCard.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/TableQueries/QueryCard.tsx @@ -12,6 +12,7 @@ */ import classNames from 'classnames'; +import { isUndefined } from 'lodash'; import React, { FC, HTMLAttributes, useState } from 'react'; import { Link } from 'react-router-dom'; import { getUserPath } from '../../constants/constants'; @@ -31,40 +32,42 @@ const QueryCard: FC = ({ className, query }) => { setExpanded((pre) => !pre)}> - - - Last run by{' '} - - - {query.user?.displayName ?? query.user?.name} - {' '} - - and took{' '} - {query.duration} seconds - + {!isUndefined(query.user) && !isUndefined(query.duration) ? ( + + + Last run by{' '} + + + {query.user?.displayName ?? query.user?.name} + {' '} + + and took{' '} + {query.duration} seconds + - - {expanded ? ( - - ) : ( - - )} - - + + {expanded ? ( + + ) : ( + + )} + + + ) : null}
- Last run by{' '} - - - {query.user?.displayName ?? query.user?.name} - {' '} - - and took{' '} - {query.duration} seconds -
+ Last run by{' '} + + + {query.user?.displayName ?? query.user?.name} + {' '} + + and took{' '} + {query.duration} seconds +