From b9ec9bea88b2c30efc62a3fda009495ef558e5ac Mon Sep 17 00:00:00 2001 From: darth-coder00 <86726556+darth-coder00@users.noreply.github.com> Date: Thu, 3 Feb 2022 09:37:27 +0530 Subject: [PATCH] Fixed failing unit tests (#2580) --- .../ui/src/components/MyData/MyData.test.tsx | 72 +++++++++++++++---- .../UserDataCard/UserDataCard.test.tsx | 48 +------------ .../ui/src/pages/login/index.test.tsx | 10 +++ .../resources/ui/src/pages/login/index.tsx | 11 ++- .../ui/src/pages/tags/index.test.tsx | 32 +++++---- .../ui/src/pages/teams/index.test.tsx | 57 ++++++++------- 6 files changed, 131 insertions(+), 99 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/MyData/MyData.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/MyData/MyData.test.tsx index 1e60425fe2c..541590ce9a6 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/MyData/MyData.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/MyData/MyData.test.tsx @@ -14,13 +14,13 @@ /* eslint-disable @typescript-eslint/camelcase */ import { - findAllByTestId, + findAllByText, findByTestId, findByText, render, } from '@testing-library/react'; import { SearchResponse } from 'Models'; -import React from 'react'; +import React, { ReactNode } from 'react'; import { MemoryRouter } from 'react-router-dom'; import { User } from '../../generated/entity/teams/user'; import { formatDataResponse } from '../../utils/APIUtils'; @@ -234,10 +234,51 @@ jest.mock('../../components/recently-viewed/RecentlyViewed', () => { return jest.fn().mockReturnValue(

RecentlyViewed

); }); -jest.mock('../MyDataHeader/MyDataHeader.component', () => { - return jest.fn().mockReturnValue(

MyDataHeader

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

DropDownList

); }); +jest.mock('../common/FeedCard/FeedCards.component', () => { + return jest.fn().mockReturnValue(

FeedCards

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

MyAssetStats

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

EntityList

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

RecentSearchedTerms

); +}); + +jest.mock( + '../containers/PageLayout', + () => + ({ + children, + leftPanel, + rightPanel, + }: { + children: ReactNode; + rightPanel: ReactNode; + leftPanel: ReactNode; + }) => + ( +
+
{leftPanel}
+
{rightPanel}
+ {children} +
+ ) +); + +jest.mock('../../utils/EntityVersionUtils', () => ({ + getFeedSummary: jest.fn().mockImplementation(() =>

EntityVersionUtils

), +})); + jest.mock('../../utils/ServiceUtils', () => ({ getAllServices: jest .fn() @@ -278,16 +319,19 @@ describe('Test MyData page', () => { wrapper: MemoryRouter, } ); - const pageContainer = await findByTestId(container, 'fluid-container'); - const searchData = await findByTestId(container, 'search-data'); - const wrappedContent = await findByTestId(container, 'wrapped-content'); - const tabs = await findAllByTestId(container, 'tab'); - const myDataHeader = await findByText(container, /MyDataHeader/i); + const pageLayout = await findByTestId(container, 'PageLayout'); + const leftPanel = await findByTestId(container, 'left-panel-content'); + const rightPanel = await findByTestId(container, 'right-panel-content'); + const recentSearchedTerms = await findByText( + container, + /RecentSearchedTerms/i + ); + const entityList = await findAllByText(container, /EntityList/i); - expect(pageContainer).toBeInTheDocument(); - expect(searchData).toBeInTheDocument(); - expect(wrappedContent).toBeInTheDocument(); - expect(myDataHeader).toBeInTheDocument(); - expect(tabs.length).toBe(3); + expect(pageLayout).toBeInTheDocument(); + expect(leftPanel).toBeInTheDocument(); + expect(rightPanel).toBeInTheDocument(); + expect(recentSearchedTerms).toBeInTheDocument(); + expect(entityList.length).toBe(2); }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/UserDataCard/UserDataCard.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/UserDataCard/UserDataCard.test.tsx index 6eac1628130..a916e5cafd8 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/UserDataCard/UserDataCard.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/UserDataCard/UserDataCard.test.tsx @@ -11,7 +11,7 @@ * limitations under the License. */ -import { findByTestId, fireEvent, render } from '@testing-library/react'; +import { findByTestId, render } from '@testing-library/react'; import React from 'react'; import { MemoryRouter } from 'react-router-dom'; import UserDataCard from './UserDataCard'; @@ -32,19 +32,7 @@ jest.mock('../../components/common/avatar/Avatar', () => { return jest.fn().mockReturnValue(

Avatar

); }); -jest.mock('../../utils/SvgUtils', () => { - return { - __esModule: true, - default: jest.fn().mockReturnValue(

SVGIcons

), - Icons: { - TABLE: 'table', - TOPIC: 'topic', - DASHBOARD: 'dashboard', - }, - }; -}); - -describe('Test userCard component', () => { +describe('Test UserDataCard component', () => { it('Component should render', async () => { const { container } = render( , @@ -70,36 +58,4 @@ describe('Test userCard component', () => { expect(await findByTestId(container, 'data-container')).toBeInTheDocument(); }); - - it('If isActionVisible is passed it should show delete icon', async () => { - const { container } = render( - , - { - wrapper: MemoryRouter, - } - ); - - const remove = await findByTestId(container, 'remove'); - - expect(remove).toBeInTheDocument(); - - fireEvent.click(remove); - - expect(mockRemove).toBeCalled(); - }); - - it('If dataset is provided, it should display accordingly', async () => { - const { container } = render( - , - { - wrapper: MemoryRouter, - } - ); - - const svgIcon = await findByTestId(container, 'svg-icon'); - const datasetLink = await findByTestId(container, 'dataset-link'); - - expect(svgIcon).toBeInTheDocument(); - expect(datasetLink).toBeInTheDocument(); - }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/login/index.test.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/login/index.test.tsx index d2bc42a05f0..f364b564bf3 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/login/index.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/login/index.test.tsx @@ -28,14 +28,24 @@ jest.mock(
{children}
); +jest.mock('../../assets/img/login-bg.jpeg', () => 'login-bg.jpeg'); + +jest.mock('./LoginCarousel', () => + jest.fn().mockReturnValue(

LoginCarousel

) +); + describe('Test SigninPage Component', () => { it('Component should render', async () => { const { container } = render(, { wrapper: MemoryRouter, }); const servicePage = await findByTestId(container, 'signin-page'); + const bgImg = await findByTestId(container, 'bg-image'); + const LoginCarousel = await findByText(container, /LoginCarousel/i); expect(servicePage).toBeInTheDocument(); + expect(bgImg).toBeInTheDocument(); + expect(LoginCarousel).toBeInTheDocument(); }); it('Sign in button should render', async () => { diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/login/index.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/login/index.tsx index 9a994b5f8b5..0c15ff09f04 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/login/index.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/login/index.tsx @@ -74,7 +74,9 @@ const SigninPage = () => { } return ( -
+
@@ -89,7 +91,12 @@ const SigninPage = () => {
- bg-image + bg-image
diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/tags/index.test.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/tags/index.test.tsx index 4961aa61b4e..04e9c095477 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/tags/index.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/tags/index.test.tsx @@ -14,6 +14,7 @@ import { findAllByTestId, findByTestId, + findByText, fireEvent, render, } from '@testing-library/react'; @@ -78,23 +79,24 @@ jest.mock('../../utils/TagsUtils', () => ({ })); jest.mock( - '../../components/containers/PageContainer', + '../../components/containers/PageLayout', () => - ({ - children, - leftPanelContent, - }: { - children: ReactNode; - leftPanelContent: ReactNode; - }) => + ({ children, leftPanel }: { children: ReactNode; leftPanel: ReactNode }) => ( -
-
{leftPanelContent}
+
+
{leftPanel}
{children}
) ); +jest.mock( + '../../components/containers/PageContainerV1', + () => + ({ children }: { children: ReactNode }) => +
{children}
+); + jest.mock('../../components/common/non-admin-action/NonAdminAction', () => { return jest .fn() @@ -121,6 +123,10 @@ jest.mock('../../components/Modals/FormModal', () => { return jest.fn().mockReturnValue(

FormModal

); }); +jest.mock('../../components/common/description/Description', () => { + return jest.fn().mockReturnValue(

DescriptionComponent

); +}); + jest.mock('../../components/common/non-admin-action/NonAdminAction', () => { return jest .fn() @@ -135,7 +141,7 @@ describe('Test TagsPage page', () => { const tagsComponent = await findByTestId(container, 'tags-container'); const pageContainerComponent = await findByTestId( container, - 'PageContainer' + 'PageContainerV1' ); const leftPanelContent = await findByTestId( container, @@ -202,10 +208,10 @@ describe('Test TagsPage page', () => { container, 'description-container' ); - const addDescription = await findByTestId(container, 'add-description'); + const description = await findByText(container, /DescriptionComponent/i); expect(descriptionContainer).toBeInTheDocument(); - expect(addDescription).toBeInTheDocument(); + expect(description).toBeInTheDocument(); }); it('Table with respective header should be render', async () => { diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/teams/index.test.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/teams/index.test.tsx index adb8e05597c..c03812cd82a 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/teams/index.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/teams/index.test.tsx @@ -11,7 +11,12 @@ * limitations under the License. */ -import { findByTestId, fireEvent, render } from '@testing-library/react'; +import { + findByTestId, + findByText, + fireEvent, + render, +} from '@testing-library/react'; import React, { ReactNode } from 'react'; import TeamsPage from './index'; @@ -25,17 +30,17 @@ const mockTeamsData = [ }, { description: '', - displayName: 'Cloud Infra', - href: 'href1', - id: 'id1', - name: 'Cloud_Infra', + displayName: 'Cloud Infra 2', + href: 'href2', + id: 'id2', + name: 'Cloud_Infra 2', }, { description: '', - displayName: 'Cloud Infra', - href: 'href1', - id: 'id1', - name: 'Cloud_Infra', + displayName: 'Cloud Infra 3', + href: 'href3', + id: 'id3', + name: 'Cloud_Infra 3', }, ]; @@ -86,7 +91,9 @@ jest.mock('../../axiosAPIs/teamsAPI', () => ({ .mockImplementation(() => Promise.resolve({ data: mockDataTeamByName })), getTeams: jest .fn() - .mockImplementation(() => Promise.resolve({ data: mockTeamsData })), + .mockImplementation(() => + Promise.resolve({ data: { data: mockTeamsData } }) + ), patchTeamDetail: jest.fn(), })); @@ -102,18 +109,19 @@ jest.mock('../../components/Modals/FormModal', () => { }); jest.mock( - '../../components/containers/PageContainer', + '../../components/containers/PageContainerV1', () => - ({ - children, - leftPanelContent, - }: { - children: ReactNode; - leftPanelContent: ReactNode; - }) => + ({ children }: { children: ReactNode }) => +
{children}
+); + +jest.mock( + '../../components/containers/PageLayout', + () => + ({ children, leftPanel }: { children: ReactNode; leftPanel: ReactNode }) => ( -
-
{leftPanelContent}
+
+
{leftPanel}
{children}
) @@ -152,6 +160,10 @@ jest.mock('./UserCard', () => { return jest.fn().mockReturnValue(
UserCard
); }); +jest.mock('../../components/common/description/Description', () => { + return jest.fn().mockReturnValue(
Description
); +}); + describe('Test Teams page', () => { it('Component should render', async () => { const { container } = render(); @@ -220,12 +232,9 @@ describe('Test Teams page', () => { container, 'description-container' ); - - const description = await findByTestId(container, 'description'); - const addDescription = await findByTestId(container, 'add-description'); + const description = await findByText(container, /Description/i); expect(descriptionContainer).toBeInTheDocument(); - expect(addDescription).toBeInTheDocument(); expect(description).toBeInTheDocument(); });