From 19a3f1f47b46b7dbc316946e6854669de3014cc2 Mon Sep 17 00:00:00 2001 From: Sachin Chaurasiya Date: Tue, 1 Nov 2022 19:07:08 +0530 Subject: [PATCH] Add Unit tests for data insight component (#8469) --- .../DataInsightSummary.test.tsx | 53 ++++++++++ .../DataInsightDetail/DataInsightSummary.tsx | 5 +- .../DescriptionInsight.test.tsx | 79 ++++++++++++++ .../DataInsightDetail/DescriptionInsight.tsx | 4 +- .../DataInsightPage.component.tsx | 2 +- .../DataInsightPage/DataInsightPage.test.tsx | 100 ++++++++++++++++++ 6 files changed, 239 insertions(+), 4 deletions(-) create mode 100644 openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DataInsightSummary.test.tsx create mode 100644 openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DescriptionInsight.test.tsx create mode 100644 openmetadata-ui/src/main/resources/ui/src/pages/DataInsightPage/DataInsightPage.test.tsx diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DataInsightSummary.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DataInsightSummary.test.tsx new file mode 100644 index 00000000000..5f8cd891ac9 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DataInsightSummary.test.tsx @@ -0,0 +1,53 @@ +/* + * Copyright 2021 Collate + * Licensed 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 { render, screen } from '@testing-library/react'; +import React from 'react'; +import DataInsightSummary from './DataInsightSummary'; + +jest.mock('react-i18next', () => ({ + useTranslation: jest.fn().mockReturnValue({ + t: (label: string) => label, + }), +})); + +describe('Test DataInsightSummary Component', () => { + it('Should render the overview data', async () => { + render(); + + const summaryCard = screen.getByTestId('summary-card'); + + const allEntityCount = screen.getByTestId('summary-item-All'); + const usersCount = screen.getByTestId('summary-item-Users'); + const sessionCount = screen.getByTestId('summary-item-Sessions'); + const activityCount = screen.getByTestId('summary-item-Activity'); + const activeUsersCount = screen.getByTestId('summary-item-ActiveUsers'); + const tablesCount = screen.getByTestId('summary-item-Tables'); + const topicsCount = screen.getByTestId('summary-item-Topics'); + const dashboardCount = screen.getByTestId('summary-item-Dashboards'); + const mlModelsCount = screen.getByTestId('summary-item-MlModels'); + const testCasesCount = screen.getByTestId('summary-item-TestCases'); + + expect(summaryCard).toBeInTheDocument(); + expect(allEntityCount).toBeInTheDocument(); + expect(usersCount).toBeInTheDocument(); + expect(sessionCount).toBeInTheDocument(); + expect(activityCount).toBeInTheDocument(); + expect(activeUsersCount).toBeInTheDocument(); + expect(tablesCount).toBeInTheDocument(); + expect(topicsCount).toBeInTheDocument(); + expect(dashboardCount).toBeInTheDocument(); + expect(mlModelsCount).toBeInTheDocument(); + expect(testCasesCount).toBeInTheDocument(); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DataInsightSummary.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DataInsightSummary.tsx index 92be07627ea..37e07cb2df5 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DataInsightSummary.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DataInsightSummary.tsx @@ -31,7 +31,10 @@ const DataInsightSummary = () => { }> {OVERVIEW.map((summary, id) => ( - + {summary.entityType} {summary.count} diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DescriptionInsight.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DescriptionInsight.test.tsx new file mode 100644 index 00000000000..84f766fddad --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DescriptionInsight.test.tsx @@ -0,0 +1,79 @@ +/* + * Copyright 2021 Collate + * Licensed 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 { act, queryByAttribute, render, screen } from '@testing-library/react'; +import React from 'react'; + +import DescriptionInsight from './DescriptionInsight'; + +jest.mock('../../pages/DataInsightPage/DataInsight.mock', () => ({ + getEntityDescriptionData: jest.fn().mockReturnValue({ + data: [ + { + timestamp: '27/Oct', + Table: 0.5674, + Topic: 0.0453, + Database: 0.9874, + Pipeline: 0.5432, + Messaging: 0.3215, + }, + { + timestamp: '25/Oct', + Table: 0.3674, + Topic: 0.0353, + Database: 0.9874, + Pipeline: 0.4432, + Messaging: 0.3115, + }, + { + timestamp: '24/Oct', + Table: 0.3374, + Topic: 0.0353, + Database: 0.9774, + Pipeline: 0.4482, + Messaging: 0.3105, + }, + ], + entities: ['Table', 'Topic', 'Database', 'Pipeline', 'Messaging'], + }), +})); + +jest.mock('../../utils/DataInsightUtils', () => ({ + renderLegend: jest + .fn() + .mockReturnValue(
    Graph Legend
), +})); + +jest.mock('react-i18next', () => ({ + useTranslation: jest.fn().mockReturnValue({ + t: (label: string) => label, + }), +})); + +describe('Test DescriptionInsight Component', () => { + it('Should render the graph', async () => { + await act(async () => { + const { container } = render(); + const card = screen.getByTestId('entity-description-percentage-card'); + + const graph = queryByAttribute( + 'id', + container, + 'description-summary-graph' + ); + + expect(card).toBeInTheDocument(); + expect(graph).toBeInTheDocument(); + }); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DescriptionInsight.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DescriptionInsight.tsx index 979cd945a6e..ed195e3c0c2 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DescriptionInsight.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/DescriptionInsight.tsx @@ -41,13 +41,13 @@ const DescriptionInsight = () => { return ( {t('label.data-insight-description-summary')} }> - + diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/DataInsightPage/DataInsightPage.component.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/DataInsightPage/DataInsightPage.component.tsx index 9cbdcde4a14..e68dc97e0ee 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/DataInsightPage/DataInsightPage.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/DataInsightPage/DataInsightPage.component.tsx @@ -43,7 +43,7 @@ const DropDownLabel = ({ children, ...rest }: { children: ReactNode }) => { const DataInsightPage = () => { return ( - + + jest.fn().mockImplementation(({ children }) => <>{children}) +); + +jest.mock('../../components/DataInsightDetail/DataInsightSummary', () => + jest + .fn() + .mockReturnValue( +
DataInsight Summary
+ ) +); + +jest.mock('../../components/DataInsightDetail/DescriptionInsight', () => + jest + .fn() + .mockReturnValue( +
DescriptionInsight
+ ) +); + +jest.mock('../../components/DataInsightDetail/OwnerInsight', () => + jest.fn().mockReturnValue(
OwnerInsight
) +); + +jest.mock('../../components/DataInsightDetail/TierInsight', () => + jest.fn().mockReturnValue(
TierInsight
) +); + +jest.mock('../../components/DataInsightDetail/TopActiveUsers', () => + jest + .fn() + .mockReturnValue(
TopActiveUsers
) +); + +jest.mock('../../components/DataInsightDetail/TopViewEntities', () => + jest + .fn() + .mockReturnValue( +
TopViewEntities
+ ) +); + +jest.mock('../../components/DataInsightDetail/TotalEntityInsight', () => + jest + .fn() + .mockReturnValue( +
TotalEntityInsight
+ ) +); + +jest.mock('../../utils/DataInsightUtils', () => ({ + getMenuItems: jest.fn().mockReturnValue( + + ), +})); + +describe('Test DataInsightPage Component', () => { + it('Should render all child elements', async () => { + render(); + + const container = screen.getByTestId('data-insight-container'); + const insightSummary = screen.getByTestId('data-insight-summary'); + const descriptionInsight = screen.getByTestId('description-insight'); + const ownerInsight = screen.getByTestId('owner-insight'); + const tierInsight = screen.getByTestId('tier-insight'); + const topActiveUser = screen.getByTestId('top-active-user'); + const topViewedEntities = screen.getByTestId('top-viewed-entities'); + const totalEntityInsight = screen.getByTestId('total-entity-insight'); + + expect(container).toBeInTheDocument(); + + expect(insightSummary).toBeInTheDocument(); + expect(descriptionInsight).toBeInTheDocument(); + expect(ownerInsight).toBeInTheDocument(); + expect(tierInsight).toBeInTheDocument(); + expect(topActiveUser).toBeInTheDocument(); + expect(topViewedEntities).toBeInTheDocument(); + expect(totalEntityInsight).toBeInTheDocument(); + }); +});