From fe9e0593f10876376d34f4569e953e86cec06110 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Tue, 25 Feb 2020 14:12:00 +0100 Subject: [PATCH] SONAR-12961 Fix Coverage facet regression --- .../apps/projects/filters/CoverageFilter.tsx | 36 ++++++++++--------- .../filters/__tests__/CoverageFilter-test.tsx | 10 +++++- .../CoverageFilter-test.tsx.snap | 13 +++---- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.tsx b/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.tsx index 5f77b8c4441..b3e6b4ac240 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.tsx +++ b/server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.tsx @@ -19,6 +19,10 @@ */ import * as React from 'react'; import { translate } from 'sonar-ui-common/helpers/l10n'; +import { + getCoverageRatingAverageValue, + getCoverageRatingLabel +} from 'sonar-ui-common/helpers/ratings'; import CoverageRating from '../../../components/ui/CoverageRating'; import { Facet } from '../types'; import Filter from './Filter'; @@ -35,16 +39,6 @@ export interface Props { value?: any; } -const NO_DATA = 'NO_DATA'; -const slices: { [key: string]: { label: string; average: number } } = { - '80.0-*': { label: '≥ 80%', average: 90 }, - '70.0-80.0': { label: '70% - 80%', average: 75 }, - '50.0-70.0': { label: '50% - 70%', average: 60 }, - '30.0-50.0': { label: '30% - 50%', average: 40 }, - '*-30.0': { label: '< 30%', average: 15 }, - [NO_DATA]: { label: '', average: NaN } -}; - export default function CoverageFilter(props: Props) { const { property = 'coverage' } = props; @@ -52,12 +46,13 @@ export default function CoverageFilter(props: Props) { } highlightUnder={1} highlightUnderMax={5} maxFacetValue={props.maxFacetValue} onQueryChange={props.onQueryChange} - options={Object.keys(slices)} + options={[1, 2, 3, 4, 5, 6]} organization={props.organization} property={property} query={props.query} @@ -67,15 +62,24 @@ export default function CoverageFilter(props: Props) { ); } -function renderOption(option: string, selected: boolean) { +function getFacetValueForOption(facet: Facet, option: number): number { + const map = ['80.0-*', '70.0-80.0', '50.0-70.0', '30.0-50.0', '*-30.0', 'NO_DATA']; + return facet[map[option - 1]]; +} + +function renderOption(option: number, selected: boolean) { return ( - {option !== NO_DATA && ( - + {option < 6 && ( + )} - {option !== NO_DATA ? ( - slices[option].label + {option < 6 ? ( + getCoverageRatingLabel(option) ) : ( {translate('no_data')} )} diff --git a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/CoverageFilter-test.tsx b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/CoverageFilter-test.tsx index 73a95399c90..e39cbd85d43 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/CoverageFilter-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/CoverageFilter-test.tsx @@ -26,5 +26,13 @@ it('renders', () => { expect(wrapper).toMatchSnapshot(); const renderOption = wrapper.prop('renderOption'); - expect(renderOption('70.0-80.0', false)).toMatchSnapshot(); + expect(renderOption(2, false)).toMatchSnapshot(); + + const getFacetValueForOption = wrapper.prop('getFacetValueForOption'); + expect( + getFacetValueForOption( + { '80.0-*': 1, '70.0-80.0': 42, '50.0-70.0': 14, '30.0-50.0': 13, '*-30.0': 8, NO_DATA: 3 }, + 2 + ) + ).toBe(42); }); diff --git a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/__snapshots__/CoverageFilter-test.tsx.snap b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/__snapshots__/CoverageFilter-test.tsx.snap index e3653077d8a..9ce9bc4f614 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/__snapshots__/CoverageFilter-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/__snapshots__/CoverageFilter-test.tsx.snap @@ -2,6 +2,7 @@ exports[`renders 1`] = `