From 28c0b22f1830517bb5249e271e51cf64bf8a7787 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Mon, 4 Dec 2023 20:21:14 +0530 Subject: [PATCH] Minor: fixed KPI was showing success even the target did not met (#14220) --- .../KPILatestResultsV1.test.tsx | 87 +++++++++++++++++++ .../DataInsightDetail/KPILatestResultsV1.tsx | 20 +++-- 2 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/KPILatestResultsV1.test.tsx diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/KPILatestResultsV1.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/KPILatestResultsV1.test.tsx new file mode 100644 index 00000000000..12192a85279 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/KPILatestResultsV1.test.tsx @@ -0,0 +1,87 @@ +/* + * Copyright 2023 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 { findByTestId, render, screen } from '@testing-library/react'; +import React from 'react'; +import { UIKpiResult } from '../../interface/data-insight.interface'; +import KPILatestResultsV1 from './KPILatestResultsV1'; + +const mockProps = { + 'description-coverage-completed-description-fraction': { + timestamp: 1701396413075, + kpiFqn: 'description-coverage-completed-description-fraction', + targetResult: [ + { + name: 'completedDescriptionFraction', + value: '0.011024667232034217', + targetMet: false, + }, + ], + target: '0.5', + metricType: 'PERCENTAGE', + startDate: 1682578800000, + endDate: 1701417599999, + displayName: 'Description coverage', + }, + 'ownership-coverage-has-owner-fraction': { + timestamp: 1701657483456, + kpiFqn: 'ownership-coverage-has-owner-fraction', + targetResult: [ + { + name: 'hasOwnerFraction', + value: '0.65', + targetMet: true, + }, + ], + target: '0.6', + metricType: 'PERCENTAGE', + startDate: 1696876200000, + endDate: 1706725799999, + displayName: 'Ownership Coverage', + }, +} as Record; + +describe('KPILatestResultsV1', () => { + it('Component. should render', async () => { + render(); + + const [descriptionKPI, ownerKPI] = Object.keys(mockProps); + + expect( + await screen.findByTestId('kpi-latest-result-container') + ).toBeInTheDocument(); + expect(await screen.findByTestId(descriptionKPI)).toBeInTheDocument(); + expect(await screen.findByTestId(ownerKPI)).toBeInTheDocument(); + }); + + it('If target is not met withing the time frame, it should show the 0 days left', async () => { + render(); + const [descriptionKPI] = Object.keys(mockProps); + const kpi = await screen.findByTestId(descriptionKPI); + + expect(kpi).toBeInTheDocument(); + + expect(await findByTestId(kpi, 'kpi-days-remaining')).toHaveTextContent( + '0' + ); + }); + + it('If target is met withing the time frame, it should show the success icon', async () => { + render(); + const [, ownerKip] = Object.keys(mockProps); + const kpi = await screen.findByTestId(ownerKip); + + expect(kpi).toBeInTheDocument(); + + expect(await findByTestId(kpi, 'kpi-success')).toBeInTheDocument(); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/KPILatestResultsV1.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/KPILatestResultsV1.tsx index 38aab981ef8..35aaaafa870 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/KPILatestResultsV1.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataInsightDetail/KPILatestResultsV1.tsx @@ -37,7 +37,11 @@ const KPILatestResultsV1: FC = ({ kpiLatestResultsRecord }) => { }, [kpiLatestResultsRecord]); return ( - + {latestResultsList.map((result, index) => { const name = result[0]; const resultData = result[1]; @@ -65,7 +69,7 @@ const KPILatestResultsV1: FC = ({ kpiLatestResultsRecord }) => { const isTargetMet = targetResult.targetMet; return ( - +
= ({ kpiLatestResultsRecord }) => { color: KPI_WIDGET_GRAPH_COLORS[index], backgroundColor: KPI_WIDGET_GRAPH_BG_COLORS[index], }}> - {daysLeft <= 0 ? ( + {isTargetMet ? ( <> - + ) : ( <> - - {daysLeft} + + {daysLeft <= 0 ? 0 : daysLeft} {t('label.day-left', { day: 'days' })}