From 09cc3b5dd27c55477729f48b80dc02490a48c3dc Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Mon, 18 Oct 2021 20:32:59 +0530 Subject: [PATCH] Fixes: fixed failing unit tests (#844) * fixed all failing test for UI * fixed 1 breaking change bcz of merging main branch --- .../FrequentlyJoinedTables.test.tsx | 34 +++++++++---------- .../my-data-details/SchemaTab.test.tsx | 8 +++-- .../src/pages/my-data-details/index.test.tsx | 13 +++++-- .../ui/src/pages/my-data/index.test.tsx | 1 + .../ui/src/pages/services/index.test.tsx | 31 +++++++++++++++-- .../ui/src/pages/teams/index.test.tsx | 12 +++++++ 6 files changed, 74 insertions(+), 25 deletions(-) diff --git a/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/FrequentlyJoinedTables.test.tsx b/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/FrequentlyJoinedTables.test.tsx index e6b9cfe5bfe..fb19b061ff0 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/FrequentlyJoinedTables.test.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/FrequentlyJoinedTables.test.tsx @@ -22,23 +22,23 @@ import FrequentlyJoinedTables from './FrequentlyJoinedTables'; const mockTableList = [ { - name: 'dim_customer', - fqn: 'string.1', + fullyQualifiedName: 'bigquery.shopify.fact_order', + joinCount: 150, + name: 'shopify/fact_order', + }, + { + fullyQualifiedName: 'bigquery.shopify.fact_sale', + joinCount: 55, + name: 'shopify/fact_sale', + }, + { + name: 'shopify/dim_product', + fullyQualifiedName: 'string.3', joinCount: 1, }, { - name: 'fact_sale', - fqn: 'string.2', - joinCount: 1, - }, - { - name: 'dim_product', - fqn: 'string.3', - joinCount: 1, - }, - { - name: 'dim_address', - fqn: 'string.4', + name: 'shopify/dim_address', + fullyQualifiedName: 'string.4', joinCount: 1, }, ]; @@ -69,9 +69,9 @@ describe('Test QueryDetails Component', () => { expect(tableData.length).toBe(4); expect(tableData.map((tableName) => tableName.textContent)).toStrictEqual([ - 'dim_address1', - 'dim_product1', - 'fact_sale1', + 'shopify/fact_order150', + 'shopify/fact_sale55', + 'shopify/dim_address1', '+ 1 more', ]); }); diff --git a/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/SchemaTab.test.tsx b/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/SchemaTab.test.tsx index d83922e3f3f..a7ba5acef42 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/SchemaTab.test.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/SchemaTab.test.tsx @@ -15,7 +15,7 @@ * limitations under the License. */ -import { getByTestId, render } from '@testing-library/react'; +import { getByTestId, getByText, render } from '@testing-library/react'; import { TableDetail } from 'Models'; import React from 'react'; import { MemoryRouter } from 'react-router-dom'; @@ -60,6 +60,10 @@ jest.mock('./SampleDataTable', () => { return jest.fn().mockReturnValue(

SampleDataTable

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

EntityTable

); +}); + jest.mock('./SchemaTable', () => { return jest .fn() @@ -86,7 +90,7 @@ describe('Test SchemaTab Component', () => { expect(searchBar).toBeInTheDocument(); - const schemaTable = getByTestId(container, 'schema-table'); + const schemaTable = getByText(container, /EntityTable/i); expect(schemaTable).toBeInTheDocument(); expect(queryByTestId('sample-data-table')).toBeNull(); diff --git a/catalog-rest-service/src/main/resources/ui/src/pages/my-data-details/index.test.tsx b/catalog-rest-service/src/main/resources/ui/src/pages/my-data-details/index.test.tsx index f0ae717107a..acf2ba7fa3f 100644 --- a/catalog-rest-service/src/main/resources/ui/src/pages/my-data-details/index.test.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/pages/my-data-details/index.test.tsx @@ -43,6 +43,14 @@ jest.mock('../../components/my-data-details/ManageTab', () => { return jest.fn().mockReturnValue(

ManageTab

); }); +jest.mock('../../components/dataset-lineage/EntityLineage', () => { + return jest.fn().mockReturnValue(

Lineage

); +}); + +jest.mock('../../components/my-data-details/ProfilerTable', () => { + return jest.fn().mockReturnValue(

ProfilerTable

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

Description

); }); @@ -60,7 +68,6 @@ jest.mock('../../utils/CommonUtils', () => ({ })); describe('Test MyDataDetailsPage page', () => { - // Rewrite this test as component has actual data from api and api is not mocked here it('Checks if the page has all the proper components rendered', () => { const { container } = render(, { wrapper: MemoryRouter, @@ -71,7 +78,7 @@ describe('Test MyDataDetailsPage page', () => { expect(followButton).toBeInTheDocument(); expect(relatedTables).toBeInTheDocument(); - // we only have 2 for now => schema and manage - expect(tabs.length).toBe(3); + // we have 4 for now => schema, Profiler, Lineage & manage + expect(tabs.length).toBe(4); }); }); diff --git a/catalog-rest-service/src/main/resources/ui/src/pages/my-data/index.test.tsx b/catalog-rest-service/src/main/resources/ui/src/pages/my-data/index.test.tsx index 383a7bcc633..66f60039658 100644 --- a/catalog-rest-service/src/main/resources/ui/src/pages/my-data/index.test.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/pages/my-data/index.test.tsx @@ -216,6 +216,7 @@ jest.mock('../../utils/ServiceUtils', () => ({ getEntityCountByService: jest .fn() .mockReturnValue({ tableCount: 4, topicCount: 5, dashboardCount: 6 }), + getTotalEntityCountByService: jest.fn().mockReturnValue(2), })); describe('Test MyData page', () => { diff --git a/catalog-rest-service/src/main/resources/ui/src/pages/services/index.test.tsx b/catalog-rest-service/src/main/resources/ui/src/pages/services/index.test.tsx index b2315626539..07c22c9fc47 100644 --- a/catalog-rest-service/src/main/resources/ui/src/pages/services/index.test.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/pages/services/index.test.tsx @@ -48,6 +48,13 @@ const mockServiceDetails = { name: 'dashboardServices', }, }, + { + collection: { + name: 'pipelineServices', + documentation: 'Pipeline service collection', + href: 'http://pipelineServices', + }, + }, ], }; @@ -113,6 +120,22 @@ const mockDashboardService = { }, }; +const mockPipelineService = { + data: { + data: [ + { + id: '7576944e-2921-4c15-9edc-b9bada93338a', + name: 'sample_airflow', + serviceType: 'Airflow', + description: 'Airflow service', + version: 0.1, + pipelineUrl: 'http://localhost:8080', + href: 'http://localhost:8585/api/v1/services/pipelineServices/7576944e-2921-4c15-9edc-b9bada93338a', + }, + ], + }, +}; + jest.mock('../../axiosAPIs/serviceAPI', () => ({ deleteService: jest.fn(), getServiceDetails: jest @@ -126,6 +149,9 @@ jest.mock('../../axiosAPIs/serviceAPI', () => ({ case 'messagingServices': return Promise.resolve(mockMessagingService); + case 'pipelineServices': + return Promise.resolve(mockPipelineService); + default: return Promise.resolve(mockDashboardService); } @@ -168,9 +194,8 @@ describe('Test Service page', () => { expect(tabs.length).toBe(mockServiceDetails.data.length); expect(dataContainer).toBeInTheDocument(); - // mockService.data.data.length + 1 because it has add service card as well expect(dataContainer.childElementCount).toBe( - mockDatabaseService.data.data.length + 1 + mockDatabaseService.data.data.length ); }); @@ -209,7 +234,7 @@ describe('Test Service page', () => { const { container } = render(, { wrapper: MemoryRouter, }); - const addService = await findByTestId(container, 'add-services'); + const addService = await findByTestId(container, 'add-new-user-button'); fireEvent.click(addService); expect( 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 e77904371b6..57287513c67 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 @@ -123,6 +123,14 @@ jest.mock( ) ); +jest.mock('react-router-dom', () => ({ + Link: jest.fn(({ children }: { children: ReactNode }) => ( + {children} + )), + useHistory: jest.fn(), + useParams: jest.fn().mockReturnValue({ team: 'team' }), +})); + jest.mock('./AddUsersModal', () => { return jest .fn() @@ -144,6 +152,10 @@ jest.mock( }) ); +jest.mock('./UserCard', () => { + return jest.fn().mockReturnValue(
UserCard
); +}); + describe('Test Teams page', () => { it('Component should render', async () => { const { container } = render();