]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12961 Fix Coverage facet regression
authorJeremy Davis <jeremy.davis@sonarsource.com>
Tue, 25 Feb 2020 13:12:00 +0000 (14:12 +0100)
committerSonarTech <sonartech@sonarsource.com>
Wed, 26 Feb 2020 09:41:19 +0000 (10:41 +0100)
server/sonar-web/src/main/js/apps/projects/filters/CoverageFilter.tsx
server/sonar-web/src/main/js/apps/projects/filters/__tests__/CoverageFilter-test.tsx
server/sonar-web/src/main/js/apps/projects/filters/__tests__/__snapshots__/CoverageFilter-test.tsx.snap

index 5f77b8c44412db308f96975d54275898a8bfc0da..b3e6b4ac240cd7a413a0adc499553ca49a754109 100644 (file)
  */
 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>
         )}
index 73a95399c90c1dafc410c7663ef2cf5f726839b6..e39cbd85d4322eeb61e20efc56b740f1ce37889a 100644 (file)
@@ -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);
 });
index e3653077d8a87a54535d6673c86a956fb834f9e1..9ce9bc4f61498cc3e02c228cf52bcf53a8e34787 100644 (file)
@@ -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"