From cc5128fcb3baf23e532d0ddecd18dc761dd5f072 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Fri, 8 Sep 2023 14:40:18 +0530 Subject: [PATCH] fix ui: Percentage of Service with Owners graph in DI calculating wrong data #13084 (#13091) --- .../e2e/Features/RecentlyViewed.spec.js | 6 +- .../EditTestCaseModal.test.tsx | 8 + .../AddDataQualityTest/EditTestCaseModal.tsx | 1 + .../resources/ui/src/mocks/TestSuite.mock.ts | 1 + .../ui/src/pages/DataInsightPage/KPIList.tsx | 14 +- .../ui/src/utils/DataInsightUtils.test.tsx | 149 ++++++++++++++++++ .../ui/src/utils/DataInsightUtils.tsx | 4 + 7 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.test.tsx diff --git a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Features/RecentlyViewed.spec.js b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Features/RecentlyViewed.spec.js index 66156b17c90..6c0c21f89d3 100644 --- a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Features/RecentlyViewed.spec.js +++ b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Features/RecentlyViewed.spec.js @@ -58,11 +58,13 @@ describe('Recently viwed data assets', () => { interceptURL( 'GET', '/api/v1/feed?type=Announcement&activeAnnouncement=true', - 'getAnnoucemenets' + 'getAnnouncements' ); + interceptURL('GET', '/api/v1/users/*?fields=owns', 'ownerDetails'); cy.clickOnLogo(); - verifyResponseStatusCode('@getAnnoucemenets', 200); + verifyResponseStatusCode('@ownerDetails', 200); + verifyResponseStatusCode('@getAnnouncements', 200); cy.get( `[data-testid="recently-viewed-container"] [title="${entity.displayName}"]` diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AddDataQualityTest/EditTestCaseModal.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AddDataQualityTest/EditTestCaseModal.test.tsx index c15314c6831..b157d811a4b 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AddDataQualityTest/EditTestCaseModal.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AddDataQualityTest/EditTestCaseModal.test.tsx @@ -118,4 +118,12 @@ describe('EditTestCaseModal Component', () => { expect(mockProps.onUpdate).toHaveBeenCalled(); }); + + it('displayName should be visible in input field', async () => { + render(); + const displayName = await screen.findByLabelText('label.display-name'); + + expect(displayName).toBeInTheDocument(); + expect(displayName).toHaveValue(MOCK_TEST_CASE[0].displayName); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AddDataQualityTest/EditTestCaseModal.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AddDataQualityTest/EditTestCaseModal.tsx index 0d6c8f7a6c1..cfafccc1cbb 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AddDataQualityTest/EditTestCaseModal.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AddDataQualityTest/EditTestCaseModal.tsx @@ -173,6 +173,7 @@ const EditTestCaseModal: React.FC = ({ form.setFieldsValue({ name: testCase?.name, testDefinition: testCase?.testDefinition?.name, + displayName: testCase?.displayName, params: getParamsValue(), table: getNameFromFQN(tableFqn), column: getNameFromFQN( diff --git a/openmetadata-ui/src/main/resources/ui/src/mocks/TestSuite.mock.ts b/openmetadata-ui/src/main/resources/ui/src/mocks/TestSuite.mock.ts index 885a03e7251..fa034419e75 100644 --- a/openmetadata-ui/src/main/resources/ui/src/mocks/TestSuite.mock.ts +++ b/openmetadata-ui/src/main/resources/ui/src/mocks/TestSuite.mock.ts @@ -344,6 +344,7 @@ export const MOCK_TEST_CASE = [ { id: '5f83c798-91ac-4289-aeb0-99ef372e7e96', name: 'column_values_to_match_regex', + displayName: 'column values to match regex', fullyQualifiedName: 'sample_data.ecommerce_db.shopify.dim_address.last_name.column_values_to_match_regex', description: 'test value of a column match regex', diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/DataInsightPage/KPIList.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/DataInsightPage/KPIList.tsx index abc7ed96296..0738c7802dc 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/DataInsightPage/KPIList.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/DataInsightPage/KPIList.tsx @@ -116,9 +116,13 @@ const KPIList = ({ viewKPIPermission }: { viewKPIPermission: boolean }) => { title: t('label.target'), dataIndex: 'targetDefinition', key: 'targetDefinition', - render: (targetDefinition: Kpi['targetDefinition']) => { + render: (targetDefinition: Kpi['targetDefinition'], record: Kpi) => { + const isPercentageMetric = + record.metricType === KpiTargetType.Percentage; const targetValue = targetDefinition?.length - ? `${+targetDefinition[0].value * 100}%` + ? isPercentageMetric + ? `${+targetDefinition[0].value * 100}%` + : targetDefinition[0].value : '-'; return {targetValue}; @@ -242,9 +246,9 @@ const KPIList = ({ viewKPIPermission }: { viewKPIPermission: boolean }) => { { + it('getGraphDataByEntityType fn should provide result for entity type graph', () => { + const entityDescription = getGraphDataByEntityType( + mockEntityDescriptionData, + DataInsightChartType.PercentageOfEntitiesWithDescriptionByType + ); + const entityOwner = getGraphDataByEntityType( + mockEntityOwnerData, + DataInsightChartType.PercentageOfEntitiesWithOwnerByType + ); + + expect(entityDescription).toStrictEqual({ + data: [ + { + Table: 11, + timestamp: 'Sep 05', + timestampValue: 1693872000000, + }, + ], + entities: ['Table'], + isPercentageGraph: true, + latestData: { + Table: 11, + timestamp: 'Sep 05', + timestampValue: 1693872000000, + }, + relativePercentage: 0, + total: '11.00', + }); + expect(entityOwner).toStrictEqual({ + data: [ + { + Table: 8, + timestamp: 'Sep 05', + timestampValue: 1693872000000, + }, + ], + entities: ['Table'], + isPercentageGraph: true, + latestData: { + Table: 8, + timestamp: 'Sep 05', + timestampValue: 1693872000000, + }, + relativePercentage: 0, + total: '8.00', + }); + }); + + it('getGraphDataByEntityType fn should provide result for service type graph', () => { + const serviceDescription = getGraphDataByEntityType( + mockServiceDescriptionData, + DataInsightChartType.PercentageOfServicesWithDescription + ); + const serviceOwner = getGraphDataByEntityType( + mockServiceOwnerData, + DataInsightChartType.PercentageOfServicesWithOwner + ); + + expect(serviceDescription).toStrictEqual({ + data: [ + { + mySQL: 0, + timestamp: 'Sep 05', + timestampValue: 1693872000000, + }, + ], + entities: ['mySQL'], + isPercentageGraph: true, + latestData: { + mySQL: 0, + timestamp: 'Sep 05', + timestampValue: 1693872000000, + }, + relativePercentage: 0, + total: '0.00', + }); + expect(serviceOwner).toStrictEqual({ + data: [ + { + mySQL: 5.617977528089887, + timestamp: 'Sep 05', + timestampValue: 1693872000000, + }, + ], + entities: ['mySQL'], + isPercentageGraph: true, + latestData: { + mySQL: 5.617977528089887, + timestamp: 'Sep 05', + timestampValue: 1693872000000, + }, + relativePercentage: 0, + total: '5.62', + }); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx index e5ecc5344d2..eed54175681 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/DataInsightUtils.tsx @@ -283,11 +283,13 @@ const getLatestPercentage = ( }); switch (dataInsightChartType) { case DataInsightChartType.PercentageOfEntitiesWithDescriptionByType: + case DataInsightChartType.PercentageOfServicesWithDescription: return ((totalEntityWithDescription / totalEntityCount) * 100).toFixed( 2 ); case DataInsightChartType.PercentageOfEntitiesWithOwnerByType: + case DataInsightChartType.PercentageOfServicesWithOwner: return ((totalEntityWithOwner / totalEntityCount) * 100).toFixed(2); default: @@ -339,11 +341,13 @@ const getOldestPercentage = ( }); switch (dataInsightChartType) { case DataInsightChartType.PercentageOfEntitiesWithDescriptionByType: + case DataInsightChartType.PercentageOfServicesWithDescription: return ((totalEntityWithDescription / totalEntityCount) * 100).toFixed( 2 ); case DataInsightChartType.PercentageOfEntitiesWithOwnerByType: + case DataInsightChartType.PercentageOfServicesWithOwner: return ((totalEntityWithOwner / totalEntityCount) * 100).toFixed(2); default: