From ea9ef88af594b7ee8ab59e0b56fb42fa8ef6b067 Mon Sep 17 00:00:00 2001 From: Aniket Katkar Date: Thu, 19 Jan 2023 11:30:36 +0530 Subject: [PATCH] Added unit tests for components (#9790) -ActivityFeelList -CustomPropertyTable -Users --- .../ActivityFeedList.test.tsx | 42 ++++++++++++++++++- .../ActivityFeedList/ActivityFeedList.tsx | 2 +- .../components/Users/Users.component.test.tsx | 29 +++++++++++++ .../CustomPropertyTable.test.tsx | 31 ++++++++++++-- 4 files changed, 98 insertions(+), 6 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedList/ActivityFeedList.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedList/ActivityFeedList.test.tsx index 344d3fffe45..7905da69949 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedList/ActivityFeedList.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedList/ActivityFeedList.test.tsx @@ -11,7 +11,7 @@ * limitations under the License. */ -import { findByTestId, render } from '@testing-library/react'; +import { findByTestId, queryByTestId, render } from '@testing-library/react'; import React from 'react'; import { MemoryRouter } from 'react-router-dom'; import ActivityFeedList from './ActivityFeedList'; @@ -85,6 +85,10 @@ jest.mock('../NoFeedPlaceholder/NoFeedPlaceholder', () => { return jest.fn().mockReturnValue(

NoFeedPlaceholder

); }); +jest.mock('../../common/error-with-placeholder/ErrorPlaceHolder', () => { + return jest.fn().mockReturnValue(

ErrorPlaceHolder

); +}); + jest.mock('./FeedListBody', () => { return jest.fn().mockReturnValue(

FeedListBody

); }); @@ -115,4 +119,40 @@ describe('Test FeedList Component', () => { expect(feed1).toBeInTheDocument(); expect(feed2).toBeInTheDocument(); }); + + it('No data placeholders should not displayed if feedList is empty but feeds are loading', async () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + const noFeedPlaceholderContainer = queryByTestId( + container, + 'no-data-placeholder-container' + ); + + expect(noFeedPlaceholderContainer).toBeNull(); + }); + + it('No data placeholders should be displayed if feedList is empty and feeds are not loading', async () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + const noFeedPlaceholderContainer = await findByTestId( + container, + 'no-data-placeholder-container' + ); + + expect(noFeedPlaceholderContainer).toBeInTheDocument(); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedList/ActivityFeedList.tsx b/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedList/ActivityFeedList.tsx index a4bb9fc486c..fea73f26b85 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedList/ActivityFeedList.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/ActivityFeedList/ActivityFeedList.tsx @@ -297,7 +297,7 @@ const ActivityFeedList: FC = ({ ) : ( !isFeedLoading && ( -
+
{entityName && feedFilter === FeedFilter.ALL && !threadType ? ( ) : !refreshFeedCount ? ( diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Users/Users.component.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Users/Users.component.test.tsx index f26bc4bb408..2e8dab745f3 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Users/Users.component.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Users/Users.component.test.tsx @@ -235,4 +235,33 @@ describe('Test User Component', () => { expect(inheritedRoles).toBeInTheDocument(); }); + + it('MyData tab should show loader if the data is loading', async () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + const inheritedRoles = await findByTestId(container, 'loader'); + + expect(inheritedRoles).toBeInTheDocument(); + }); + + it('Following tab should show loader if the data is loading', async () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + const inheritedRoles = await findByTestId(container, 'loader'); + + expect(inheritedRoles).toBeInTheDocument(); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/CustomPropertyTable/CustomPropertyTable.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/CustomPropertyTable/CustomPropertyTable.test.tsx index ff76015c3e3..fd1a804e390 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/CustomPropertyTable/CustomPropertyTable.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/CustomPropertyTable/CustomPropertyTable.test.tsx @@ -11,7 +11,12 @@ * limitations under the License. */ -import { render, screen } from '@testing-library/react'; +import { + act, + render, + screen, + waitForElementToBeRemoved, +} from '@testing-library/react'; import React from 'react'; import { getTypeByFQN } from 'rest/metadataTypeAPI'; import { EntityType } from '../../../enums/entity.enum'; @@ -54,6 +59,10 @@ jest.mock('../error-with-placeholder/ErrorPlaceHolder', () => { return jest.fn().mockReturnValue(
ErrorPlaceHolder.component
); }); +jest.mock('components/Loader/Loader', () => { + return jest.fn().mockReturnValue(
Loader
); +}); + jest.mock('rest/metadataTypeAPI', () => ({ getTypeByFQN: jest.fn().mockImplementation(() => Promise.resolve({ @@ -73,7 +82,9 @@ const mockProp = { describe('Test CustomProperty Table Component', () => { it('Should render table component', async () => { - render(); + await act(async () => { + render(); + }); const table = await screen.findByTestId('custom-properties-table'); expect(table).toBeInTheDocument(); @@ -91,9 +102,21 @@ describe('Test CustomProperty Table Component', () => { (getTypeByFQN as jest.Mock).mockImplementationOnce(() => Promise.resolve({ customProperties: [] }) ); - const { findByText } = render(); - const noDataPlaceHolder = await findByText('ErrorPlaceHolder.component'); + await act(async () => { + render(); + }); + const noDataPlaceHolder = await screen.findByText( + 'ErrorPlaceHolder.component' + ); expect(noDataPlaceHolder).toBeInTheDocument(); }); + + it('Loader should be shown while loading the custom properties', async () => { + (getTypeByFQN as jest.Mock).mockResolvedValueOnce(Promise.resolve({})); + render(); + + // To check if loader was rendered when the loading state was true and then removed after loading is false + await waitForElementToBeRemoved(() => screen.getByTestId('loader')); + }); });