diff options
author | Jeremy Davis <jeremy.davis@sonarsource.com> | 2020-02-25 14:12:00 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2020-02-26 10:41:19 +0100 |
commit | fe9e0593f10876376d34f4569e953e86cec06110 (patch) | |
tree | ca976389dddac173deaf8d3a6cb4b6829ab0ca67 /server | |
parent | 64a32002abceb8ce6d133ece93a15c1ef0997f75 (diff) | |
download | sonarqube-fe9e0593f10876376d34f4569e953e86cec06110.tar.gz sonarqube-fe9e0593f10876376d34f4569e953e86cec06110.zip |
SONAR-12961 Fix Coverage facet regression
Diffstat (limited to 'server')
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) { <Filter className={props.className} facet={props.facet} + getFacetValueForOption={getFacetValueForOption} header={<FilterHeader name={translate('metric_domain.Coverage')} />} 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 ( <span> - {option !== NO_DATA && ( - <CoverageRating muted={!selected} size="small" value={slices[option].average} /> + {option < 6 && ( + <CoverageRating + muted={!selected} + size="small" + value={getCoverageRatingAverageValue(option)} + /> )} <span className="spacer-left"> - {option !== NO_DATA ? ( - slices[option].label + {option < 6 ? ( + getCoverageRatingLabel(option) ) : ( <span className="big-spacer-left">{translate('no_data')}</span> )} 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`] = ` <Filter + getFacetValueForOption={[Function]} header={ <FilterHeader name="metric_domain.Coverage" @@ -12,12 +13,12 @@ exports[`renders 1`] = ` onQueryChange={[MockFunction]} options={ Array [ - "80.0-*", - "70.0-80.0", - "50.0-70.0", - "30.0-50.0", - "*-30.0", - "NO_DATA", + 1, + 2, + 3, + 4, + 5, + 6, ] } property="coverage" |