From 7426eafe00656852916ebe839858a6a9c7466d80 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Fri, 10 Nov 2023 11:49:03 +0530 Subject: [PATCH] fixed failing unit test --- .../DescriptionInsight.test.tsx | 51 ++++++++++--------- .../DataInsightDetail/OwnerInsight.test.tsx | 47 ++++++++--------- 2 files changed, 52 insertions(+), 46 deletions(-) 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 index da43d0958c6b..8fff542e6c30 100644 --- 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 @@ -39,6 +39,7 @@ jest.mock('../../utils/DataInsightUtils', () => ({ getGraphDataByEntityType: jest .fn() .mockImplementation(() => DUMMY_GRAPH_DATA), + sortEntityByValue: jest.fn().mockImplementation((entities) => entities), })); jest.mock('./EntitySummaryProgressBar.component', () => { return jest.fn().mockImplementation(({ label, entity }) => ( @@ -58,18 +59,20 @@ jest.mock('react-i18next', () => ({ describe('Test DescriptionInsight Component', () => { it('Should render the graph', async () => { await act(async () => { - const { container } = render(); - const card = screen.getByTestId('entity-description-percentage-card'); + render(); + }); + const card = await screen.findByTestId( + 'entity-description-percentage-card' + ); - const graph = queryByAttribute( - 'id', - container, - `${mockProps.dataInsightChartName}-graph` - ); + const graph = queryByAttribute( + 'id', + card, + `${mockProps.dataInsightChartName}-graph` + ); - expect(card).toBeInTheDocument(); - expect(graph).toBeInTheDocument(); - }); + expect(card).toBeInTheDocument(); + expect(graph).toBeInTheDocument(); }); it('Should render the graph and progress bar even if one entity dont have values', async () => { @@ -77,21 +80,23 @@ describe('Test DescriptionInsight Component', () => { () => DUMMY_GRAPH_DATA_WITH_MISSING_ENTITY ); await act(async () => { - const { container } = render(); - const card = screen.getByTestId('entity-description-percentage-card'); + render(); + }); + const card = await screen.findByTestId( + 'entity-description-percentage-card' + ); - const graph = queryByAttribute( - 'id', - container, - `${mockProps.dataInsightChartName}-graph` - ); - const missingEntityValue = await screen.findByTestId('Table'); + const graph = queryByAttribute( + 'id', + card, + `${mockProps.dataInsightChartName}-graph` + ); + const missingEntityValue = await screen.findByTestId('Table'); - expect(card).toBeInTheDocument(); - expect(graph).toBeInTheDocument(); - expect(missingEntityValue).toBeInTheDocument(); - expect(missingEntityValue.textContent).toBe('0'); - }); + expect(card).toBeInTheDocument(); + expect(graph).toBeInTheDocument(); + expect(missingEntityValue).toBeInTheDocument(); + expect(missingEntityValue.textContent).toBe('0'); }); it('Should fetch data based on dataInsightChartName props', async () => { diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/OwnerInsight.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/OwnerInsight.test.tsx index bc91ca975297..5bb05fc2214b 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/OwnerInsight.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/OwnerInsight.test.tsx @@ -37,6 +37,7 @@ jest.mock('../../utils/DataInsightUtils', () => ({ getGraphDataByEntityType: jest .fn() .mockImplementation(() => DUMMY_GRAPH_DATA), + sortEntityByValue: jest.fn().mockImplementation((entities) => entities), })); jest.mock('./EntitySummaryProgressBar.component', () => { return jest.fn().mockImplementation(({ label, entity }) => ( @@ -59,18 +60,18 @@ jest.mock('react-i18next', () => ({ describe('Test DescriptionInsight Component', () => { it('Should render the graph', async () => { await act(async () => { - const { container } = render(); - const card = screen.getByTestId('entity-summary-card-percentage'); + render(); + }); + const card = await screen.findByTestId('entity-summary-card-percentage'); - const graph = queryByAttribute( - 'id', - container, - `${mockProps.dataInsightChartName}-graph` - ); + const graph = queryByAttribute( + 'id', + card, + `${mockProps.dataInsightChartName}-graph` + ); - expect(card).toBeInTheDocument(); - expect(graph).toBeInTheDocument(); - }); + expect(card).toBeInTheDocument(); + expect(graph).toBeInTheDocument(); }); it('Should render the graph and progress bar even if one entity dont have values', async () => { @@ -78,21 +79,21 @@ describe('Test DescriptionInsight Component', () => { () => DUMMY_GRAPH_DATA_WITH_MISSING_ENTITY ); await act(async () => { - const { container } = render(); - const card = screen.getByTestId('entity-summary-card-percentage'); + render(); + }); + const card = await screen.findByTestId('entity-summary-card-percentage'); - const graph = queryByAttribute( - 'id', - container, - `${mockProps.dataInsightChartName}-graph` - ); - const missingEntityValue = await screen.findByTestId('Table'); + const graph = queryByAttribute( + 'id', + card, + `${mockProps.dataInsightChartName}-graph` + ); + const missingEntityValue = await screen.findByTestId('Table'); - expect(card).toBeInTheDocument(); - expect(graph).toBeInTheDocument(); - expect(missingEntityValue).toBeInTheDocument(); - expect(missingEntityValue.textContent).toBe('0'); - }); + expect(card).toBeInTheDocument(); + expect(graph).toBeInTheDocument(); + expect(missingEntityValue).toBeInTheDocument(); + expect(missingEntityValue.textContent).toBe('0'); }); it('Should fetch data based on dataInsightChartName props', async () => {