diff --git a/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/SchemaTable.test.tsx b/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/SchemaTable.test.tsx index a6337eb434f..5ccebe0da98 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/SchemaTable.test.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/SchemaTable.test.tsx @@ -19,14 +19,14 @@ import { getAllByTestId, render } from '@testing-library/react'; import { TableDetail } from 'Models'; import React from 'react'; import { MemoryRouter } from 'react-router-dom'; -import { Column, ColumnDataType } from '../../generated/entity/data/table'; +import { ColumnDataType } from '../../generated/entity/data/table'; import SchemaTable from './SchemaTable'; jest.mock('../common/rich-text-editor/RichTextEditorPreviewer', () => { return jest.fn().mockReturnValue(

RichTextEditorPreviewer

); }); -const mockColumns: Column[] = [ +const mockColumns = [ { name: 'testId', columnDataType: ColumnDataType.String, diff --git a/catalog-rest-service/src/main/resources/ui/src/components/my-data/MyDataHeader.test.tsx b/catalog-rest-service/src/main/resources/ui/src/components/my-data/MyDataHeader.test.tsx new file mode 100644 index 00000000000..10aef0c75a6 --- /dev/null +++ b/catalog-rest-service/src/main/resources/ui/src/components/my-data/MyDataHeader.test.tsx @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +import { getByTestId, getByText, render } from '@testing-library/react'; +import React from 'react'; +import { MemoryRouter } from 'react-router'; +import MyDataHeader from './MyDataHeader'; + +describe('Test MyDataHeader Component', () => { + it('Component should render', () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + const myDataHeader = getByTestId(container, 'data-header-container'); + + expect(myDataHeader).toBeInTheDocument(); + }); + + it('Should have main title', () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + const mainTitle = getByTestId(container, 'main-title'); + + expect(mainTitle).toBeInTheDocument(); + }); + + it('Should have 3 state box', () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + const stateBox = getByTestId(container, 'states-box-container'); + + expect(stateBox.childElementCount).toBe(3); + expect(getByText(container, /Explore Assets/i)).toBeInTheDocument(); + expect(getByText(container, /Register Services/i)).toBeInTheDocument(); + expect(getByText(container, /Knowledgebase/i)).toBeInTheDocument(); + }); + + it('Should have 6 data summary details', () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + const dataSummary = getByTestId(container, 'data-summary-container'); + + expect(dataSummary.childElementCount).toBe(6); + }); + + it('Should display same count as provided by props', () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + expect(getByText(container, /40 tables/i)).toBeInTheDocument(); + expect(getByText(container, /13 topics/i)).toBeInTheDocument(); + expect(getByText(container, /10 dashboards/i)).toBeInTheDocument(); + expect(getByText(container, /4 of services/i)).toBeInTheDocument(); + expect(getByText(container, /193 assets/i)).toBeInTheDocument(); + }); + + it('OnClick it should redirect to respective page', () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + const tables = getByTestId(container, 'tables'); + const topics = getByTestId(container, 'topics'); + const dashboards = getByTestId(container, 'dashboards'); + const service = getByTestId(container, 'service'); + const user = getByTestId(container, 'user'); + const terms = getByTestId(container, 'terms'); + + expect(tables).toHaveAttribute('href', '/explore/tables'); + expect(topics).toHaveAttribute('href', '/explore/topics'); + expect(dashboards).toHaveAttribute('href', '/explore/dashboards'); + expect(service).toHaveAttribute('href', '/services'); + expect(user).toHaveAttribute('href', '/teams'); + expect(terms).toHaveAttribute('href', '/teams'); + }); +}); diff --git a/catalog-rest-service/src/main/resources/ui/src/components/my-data/MyDataHeader.tsx b/catalog-rest-service/src/main/resources/ui/src/components/my-data/MyDataHeader.tsx index 1f9ee1718e8..c9231681824 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/my-data/MyDataHeader.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/my-data/MyDataHeader.tsx @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + import classNames from 'classnames'; import { observer } from 'mobx-react'; import React, { FunctionComponent, useEffect, useState } from 'react'; @@ -19,6 +36,7 @@ type Summary = { icon: string; data: string; link?: string; + dataTestId?: string; }; const LANDING_STATES = [ @@ -46,7 +64,7 @@ const MyDataHeader: FunctionComponent = ({ const [dataSummary, setdataSummary] = useState>({}); const getFormattedDescription = (description: string) => { - return description.replaceAll('{countAssets}', countAssets.toString()); + return description.replace(/{countAssets}/g, countAssets.toString()); }; const getSummarydata = () => { @@ -55,31 +73,37 @@ const MyDataHeader: FunctionComponent = ({ icon: Icons.TABLE_GREY, data: `${entityCounts.tableCount} Tables`, link: `/explore/tables`, + dataTestId: 'tables', }, topics: { icon: Icons.TOPIC_GREY, data: `${entityCounts.topicCount} Topics`, link: `/explore/topics`, + dataTestId: 'topics', }, dashboards: { icon: Icons.DASHBOARD_GREY, data: `${entityCounts.dashboardCount} Dashboards`, link: `/explore/dashboards`, + dataTestId: 'dashboards', }, service: { icon: Icons.SERVICE, data: `${countServices} of Services`, link: `/services`, + dataTestId: 'service', }, user: { icon: Icons.USERS, data: `${users.length} of Users`, link: `/teams`, + dataTestId: 'user', }, terms: { icon: Icons.TERMS, data: `${userTeams.length} of Teams`, link: `/teams`, + dataTestId: 'terms', }, }; }; @@ -95,12 +119,14 @@ const MyDataHeader: FunctionComponent = ({ }, [userTeams, users, countServices]); return ( -
-

+
+

Open Metadata

-
+
{Object.values(dataSummary).map((data, index) => (
= ({ key={index}> {data.link ? ( - + @@ -121,7 +150,7 @@ const MyDataHeader: FunctionComponent = ({ ))}
-
+
{LANDING_STATES.map((d, i) => (
{ + return jest + .fn() + .mockReturnValue(

TableDataCard

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

Pagination

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

Onboarding

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

ErrorPlaceHolderES

); +}); + +describe('Test SearchedData Component', () => { + it('Component should render', () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + const searchedDataContainer = getByTestId(container, 'fluid-container'); + + expect(searchedDataContainer).toBeInTheDocument(); + }); + + it('Should display table card according to data provided in props', () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + const searchedDataContainer = getAllByTestId(container, 'table-data-card'); + + expect(searchedDataContainer.length).toBe(3); + }); + + it('If children is provided it should display', () => { + const { container } = render( + +

hello world

+
, + { + wrapper: MemoryRouter, + } + ); + + expect(getByText(container, /hello world/i)).toBeInTheDocument(); + }); + + it('Pagination Should be there if data is more than 10 count', () => { + const { container } = render( + +

hello world

+
, + { + wrapper: MemoryRouter, + } + ); + + expect(getByText(container, /Pagination/i)).toBeInTheDocument(); + }); + + it('Onboarding component should display if there is showOnboardingTemplate is true', () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + expect(getByText(container, /Onboarding/i)).toBeInTheDocument(); + }); + + it('ErrorPlaceHolderES component should display if there is no data', () => { + const { container } = render( + , + { + wrapper: MemoryRouter, + } + ); + + expect(getByText(container, /ErrorPlaceHolderES/i)).toBeInTheDocument(); + }); +}); diff --git a/catalog-rest-service/src/main/resources/ui/src/pages/teams/index.test.tsx b/catalog-rest-service/src/main/resources/ui/src/pages/teams/index.test.tsx index c769cf8b240..0e9f4427421 100644 --- a/catalog-rest-service/src/main/resources/ui/src/pages/teams/index.test.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/pages/teams/index.test.tsx @@ -15,10 +15,85 @@ * limitations under the License. */ -import { findByTestId, render } from '@testing-library/react'; +import { findByTestId, fireEvent, render } from '@testing-library/react'; import React, { ReactNode } from 'react'; import TeamsPage from './index'; +const mockTeamsData = [ + { + description: '', + displayName: 'Cloud Infra', + href: 'href1', + id: 'id1', + name: 'Cloud_Infra', + }, + { + description: '', + displayName: 'Cloud Infra', + href: 'href1', + id: 'id1', + name: 'Cloud_Infra', + }, + { + description: '', + displayName: 'Cloud Infra', + href: 'href1', + id: 'id1', + name: 'Cloud_Infra', + }, +]; + +const mockDataTeamByName = { + description: '', + displayName: 'Customer Support', + href: 'http://localhost:8585/api/v1/teams/f6b906cc-005b-4d68-b7f7-62d591a8d9dd', + id: 'f6b906cc-005b-4d68-b7f7-62d591a8d9dd', + name: 'Customer_Support', + owns: [ + { + description: 'Robert Mitchell', + href: 'href', + id: 'id1', + name: 'robert_mitchell6', + type: 'user', + }, + { + description: 'Shane Davis', + href: 'href', + id: 'id2', + name: 'shane_davis8', + type: 'user', + }, + ], + users: [ + { + description: 'Robert Mitchell', + href: 'href', + id: 'id1', + name: 'robert_mitchell6', + type: 'user', + }, + { + description: 'Shane Davis', + href: 'href', + id: 'id2', + name: 'shane_davis8', + type: 'user', + }, + ], +}; + +jest.mock('../../axiosAPIs/teamsAPI', () => ({ + createTeam: jest.fn(), + getTeamByName: jest + .fn() + .mockImplementation(() => Promise.resolve({ data: mockDataTeamByName })), + getTeams: jest + .fn() + .mockImplementation(() => Promise.resolve({ data: mockTeamsData })), + patchTeamDetail: jest.fn(), +})); + jest.mock( '../../components/common/rich-text-editor/RichTextEditorPreviewer', () => { @@ -26,6 +101,10 @@ jest.mock( } ); +jest.mock('../../components/Modals/FormModal', () => { + return jest.fn().mockReturnValue(

FormModal

); +}); + jest.mock( '../../components/containers/PageContainer', () => @@ -44,6 +123,27 @@ jest.mock( ) ); +jest.mock('./AddUsersModal', () => { + return jest + .fn() + .mockReturnValue(

AddUsersModal

); +}); + +jest.mock('../../components/common/non-admin-action/NonAdminAction', () => { + return jest + .fn() + .mockImplementation(({ children }: { children: ReactNode }) => ( +
{children}
+ )); +}); + +jest.mock( + '../../components/Modals/ModalWithMarkdownEditor/ModalWithMarkdownEditor', + () => ({ + ModalWithMarkdownEditor: jest.fn(), + }) +); + describe('Test Teams page', () => { it('Check for heading', async () => { const { container } = render(); @@ -52,8 +152,90 @@ describe('Test Teams page', () => { container, 'left-panel-content' ); + const header = await findByTestId(container, 'header'); + const userCard = await findByTestId(container, 'user-card-container'); expect(teamComponent).toBeInTheDocument(); expect(leftPanelContent).toBeInTheDocument(); + expect(header).toBeInTheDocument(); + expect(userCard).toBeInTheDocument(); + }); + + it('OnClick of assets tab, assets tab should display', async () => { + const { container } = render(); + const assets = await findByTestId(container, 'assets'); + + fireEvent.click( + assets, + new MouseEvent('click', { + bubbles: true, + cancelable: true, + }) + ); + + expect(await findByTestId(container, 'dataset-card')).toBeInTheDocument(); + }); + + it('OnClick of add new user, AddUsersModal should display', async () => { + const { container } = render(); + const addNewUser = await findByTestId(container, 'add-new-user-button'); + + expect(addNewUser).toBeInTheDocument(); + + fireEvent.click( + addNewUser, + new MouseEvent('click', { + bubbles: true, + cancelable: true, + }) + ); + + expect(await findByTestId(container, 'add-user-modal')).toBeInTheDocument(); + }); + + it('Should have 2 tabs in the page', async () => { + const { container } = render(); + + const tabs = await findByTestId(container, 'tabs'); + const user = await findByTestId(container, 'users'); + const asstes = await findByTestId(container, 'assets'); + + expect(tabs.childElementCount).toBe(2); + expect(user).toBeInTheDocument(); + expect(asstes).toBeInTheDocument(); + }); + + it('Description should be in document', async () => { + const { container } = render(); + + const descriptionContainer = await findByTestId( + container, + 'description-container' + ); + + const description = await findByTestId(container, 'description'); + const addDescription = await findByTestId(container, 'add-description'); + + expect(descriptionContainer).toBeInTheDocument(); + expect(addDescription).toBeInTheDocument(); + expect(description).toBeInTheDocument(); + }); + + it('onClick of add team button, FormModal should open', async () => { + const { container } = render(); + + const addButton = await findByTestId(container, 'add-teams'); + + expect(addButton).toBeInTheDocument(); + + fireEvent.click( + addButton, + new MouseEvent('click', { + bubbles: true, + cancelable: true, + }) + ); + + expect(await findByTestId(container, 'form-modal')).toBeInTheDocument(); }); }); diff --git a/catalog-rest-service/src/main/resources/ui/src/pages/teams/index.tsx b/catalog-rest-service/src/main/resources/ui/src/pages/teams/index.tsx index 2f49da4a10f..1421c1250cb 100644 --- a/catalog-rest-service/src/main/resources/ui/src/pages/teams/index.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/pages/teams/index.tsx @@ -149,9 +149,12 @@ const TeamsPage = () => { const getTabs = () => { return (
-
-
+
Description @@ -377,6 +391,7 @@ const TeamsPage = () => { title={TITLE_FOR_NON_ADMIN_ACTION}>