]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21455 Rename software quailty measure usages to uppercase & Drop mocks
author7PH <benjamin.raymond@sonarsource.com>
Mon, 29 Jan 2024 14:35:46 +0000 (15:35 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 31 Jan 2024 20:03:37 +0000 (20:03 +0000)
server/sonar-web/src/main/js/api/measures.ts
server/sonar-web/src/main/js/api/mocks/data/measures.ts
server/sonar-web/src/main/js/apps/overview/branches/SoftwareImpactMeasureCard.tsx
server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx
server/sonar-web/src/main/js/apps/overview/branches/test-utils.ts
server/sonar-web/src/main/js/apps/overview/utils.tsx
server/sonar-web/src/main/js/types/clean-code-taxonomy.ts

index faa195c339b7a1989b492f7e90d97b8d3351e5a8..d1a15e7980812107ba973c6f25d92fe76dbc1ae9 100644 (file)
@@ -25,7 +25,6 @@ import {
   MeasuresAndMetaWithPeriod,
   MeasuresForProjects,
 } from '../types/measures';
-import { MetricKey, MetricType } from '../types/metrics';
 import { Measure } from '../types/types';
 
 const COMPONENT_URL = '/api/measures/component';
@@ -62,131 +61,25 @@ export function getMeasuresWithPeriod(
   }).catch(throwGlobalError);
 }
 
-export async function getMeasuresWithPeriodAndMetrics(
+export function getMeasuresWithPeriodAndMetrics(
   component: string,
   metrics: string[],
   branchParameters?: BranchParameters,
 ): Promise<MeasuresAndMetaWithPeriod & MeasuresAndMetaWithMetrics> {
-  // TODO: Remove this mock (SONAR-21488)
-  const mockedMetrics = metrics.filter(
-    (metric) =>
-      ![
-        MetricKey.maintainability_issues,
-        MetricKey.reliability_issues,
-        MetricKey.security_issues,
-      ].includes(metric as MetricKey),
-  );
-  const result = await getJSON(COMPONENT_URL, {
+  return getJSON(COMPONENT_URL, {
     additionalFields: 'period,metrics',
     component,
-    metricKeys: mockedMetrics.join(','),
+    metricKeys: metrics.join(','),
     ...branchParameters,
   }).catch(throwGlobalError);
-  if (metrics.includes(MetricKey.maintainability_issues)) {
-    result.metrics.push({
-      key: MetricKey.maintainability_issues,
-      name: 'Maintainability Issues',
-      description: 'Maintainability Issues',
-      domain: 'Maintainability',
-      type: MetricType.Data,
-      higherValuesAreBetter: false,
-      qualitative: true,
-      hidden: false,
-      bestValue: '0',
-    });
-    result.component.measures?.push({
-      metric: MetricKey.maintainability_issues,
-      value: JSON.stringify({
-        total: 3,
-        high: 1,
-        medium: 1,
-        low: 1,
-      }),
-    });
-  }
-  if (metrics.includes(MetricKey.reliability_issues)) {
-    result.metrics.push({
-      key: MetricKey.reliability_issues,
-      name: 'Reliability Issues',
-      description: 'Reliability Issues',
-      domain: 'Reliability',
-      type: MetricType.Data,
-      higherValuesAreBetter: false,
-      qualitative: true,
-      hidden: false,
-      bestValue: '0',
-    });
-    result.component.measures?.push({
-      metric: MetricKey.reliability_issues,
-      value: JSON.stringify({
-        total: 2,
-        high: 0,
-        medium: 1,
-        low: 1,
-      }),
-    });
-  }
-  if (metrics.includes(MetricKey.security_issues)) {
-    result.metrics.push({
-      key: MetricKey.security_issues,
-      name: 'Security Issues',
-      description: 'Security Issues',
-      domain: 'Security',
-      type: MetricType.Data,
-      higherValuesAreBetter: false,
-      qualitative: true,
-      hidden: false,
-      bestValue: '0',
-    });
-    result.component.measures?.push({
-      metric: MetricKey.security_issues,
-      value: JSON.stringify({
-        total: 1,
-        high: 0,
-        medium: 0,
-        low: 1,
-      }),
-    });
-  }
-  return result;
 }
 
-export async function getMeasuresForProjects(
+export function getMeasuresForProjects(
   projectKeys: string[],
   metricKeys: string[],
 ): Promise<MeasuresForProjects[]> {
-  // TODO: Remove this mock (SONAR-21488)
-  const mockedMetrics = metricKeys.filter(
-    (metric) =>
-      ![
-        MetricKey.maintainability_issues,
-        MetricKey.reliability_issues,
-        MetricKey.security_issues,
-      ].includes(metric as MetricKey),
-  );
-
-  const result = await getJSON('/api/measures/search', {
+  return getJSON('/api/measures/search', {
     projectKeys: projectKeys.join(),
-    metricKeys: mockedMetrics.join(),
+    metricKeys: metricKeys.join(),
   }).then((r) => r.measures);
-
-  [
-    MetricKey.maintainability_issues,
-    MetricKey.reliability_issues,
-    MetricKey.security_issues,
-  ].forEach((metric) => {
-    if (metricKeys.includes(metric)) {
-      projectKeys.forEach((projectKey) => {
-        result.push({
-          component: projectKey,
-          metric,
-          value: JSON.stringify({
-            total: 2,
-          }),
-        });
-      });
-    }
-  });
-
-  return result;
 }
index 964937323bddafaf68ff54dbd4c4f07f01e7786b..6c571bb07037493c4093728bf748daa3fd952cbd 100644 (file)
@@ -20,6 +20,7 @@
 import { keyBy } from 'lodash';
 import { isDiffMetric } from '../../../helpers/measures';
 import { mockMeasure } from '../../../helpers/testMocks';
+import { SoftwareImpactSeverity } from '../../../types/clean-code-taxonomy';
 import { IssueDeprecatedStatus, IssueType, RawIssue } from '../../../types/issues';
 import { MetricKey, MetricType } from '../../../types/metrics';
 import { Measure } from '../../../types/types';
@@ -61,9 +62,9 @@ function mockComponentMeasure(tree: ComponentTree, issueList: IssueData[], metri
         metric: metricKey,
         value: JSON.stringify({
           total: 1,
-          high: 0,
-          medium: 1,
-          low: 0,
+          [SoftwareImpactSeverity.High]: 0,
+          [SoftwareImpactSeverity.Medium]: 1,
+          [SoftwareImpactSeverity.Low]: 0,
         }),
       });
 
@@ -72,9 +73,9 @@ function mockComponentMeasure(tree: ComponentTree, issueList: IssueData[], metri
         metric: metricKey,
         value: JSON.stringify({
           total: 3,
-          high: 0,
-          medium: 2,
-          low: 1,
+          [SoftwareImpactSeverity.High]: 0,
+          [SoftwareImpactSeverity.Medium]: 2,
+          [SoftwareImpactSeverity.Low]: 1,
         }),
       });
 
@@ -83,9 +84,9 @@ function mockComponentMeasure(tree: ComponentTree, issueList: IssueData[], metri
         metric: metricKey,
         value: JSON.stringify({
           total: 2,
-          high: 0,
-          medium: 0,
-          low: 1,
+          [SoftwareImpactSeverity.High]: 0,
+          [SoftwareImpactSeverity.Medium]: 0,
+          [SoftwareImpactSeverity.Low]: 1,
         }),
       });
   }
index a3341ce2f5ec79513885511346315f81ed2b0f85..e6df00f3ac98ff9681975d07b4a06f20575e1b61 100644 (file)
@@ -39,7 +39,7 @@ import {
 } from '../../../types/clean-code-taxonomy';
 import { MetricKey, MetricType } from '../../../types/metrics';
 import { Component, MeasureEnhanced } from '../../../types/types';
-import { getSoftwareImpactSeverityValue, softwareQualityToMeasure } from '../utils';
+import { softwareQualityToMeasure } from '../utils';
 import SoftwareImpactMeasureBreakdownCard from './SoftwareImpactMeasureBreakdownCard';
 import SoftwareImpactMeasureRating from './SoftwareImpactMeasureRating';
 
@@ -58,7 +58,7 @@ export function SoftwareImpactMeasureCard(props: Readonly<SoftwareImpactBreakdow
   // Find measure for this software quality
   const metricKey = softwareQualityToMeasure(softwareQuality);
   const measureRaw = measures.find((m) => m.metric.key === metricKey);
-  const measure = JSON.parse(measureRaw?.value ?? 'null') as SoftwareImpactMeasureData | null;
+  const measure = JSON.parse(measureRaw?.value ?? 'null') as SoftwareImpactMeasureData;
 
   // Find rating measure
   const ratingMeasure = measures.find((m) => m.metric.key === ratingMetricKey);
@@ -72,12 +72,11 @@ export function SoftwareImpactMeasureCard(props: Readonly<SoftwareImpactBreakdow
   // We highlight the highest severity breakdown card with non-zero count if the rating is not A
   let highlightedSeverity: SoftwareImpactSeverity | undefined;
   if (measure && (!ratingLabel || ratingLabel !== 'A')) {
-    const issuesBySeverity: [SoftwareImpactSeverity, number][] = [
-      [SoftwareImpactSeverity.High, measure.high],
-      [SoftwareImpactSeverity.Medium, measure.medium],
-      [SoftwareImpactSeverity.Low, measure.low],
-    ];
-    highlightedSeverity = issuesBySeverity.find(([_, issuesCount]) => issuesCount > 0)?.[0];
+    highlightedSeverity = [
+      SoftwareImpactSeverity.High,
+      SoftwareImpactSeverity.Medium,
+      SoftwareImpactSeverity.Low,
+    ].find((severity) => measure[severity] > 0);
   }
 
   return (
@@ -134,7 +133,7 @@ export function SoftwareImpactMeasureCard(props: Readonly<SoftwareImpactBreakdow
               key={severity}
               component={component}
               softwareQuality={softwareQuality}
-              value={measure ? getSoftwareImpactSeverityValue(severity, measure) : undefined}
+              value={measure?.[severity]?.toString()}
               severity={severity}
               active={highlightedSeverity === severity}
             />
index 0b016f39d88a29fe95aeb14621aabd2c2be91212..a761cf832c1e10ab006868b528355d72a7901680 100644 (file)
@@ -38,7 +38,7 @@ import { mockQualityGateProjectStatus } from '../../../../helpers/mocks/quality-
 import { mockLoggedInUser, mockMeasure, mockPaging } from '../../../../helpers/testMocks';
 import { renderComponent } from '../../../../helpers/testReactTestingUtils';
 import { byRole, byText } from '../../../../helpers/testSelector';
-import { SoftwareQuality } from '../../../../types/clean-code-taxonomy';
+import { SoftwareImpactSeverity, SoftwareQuality } from '../../../../types/clean-code-taxonomy';
 import { ComponentQualifier } from '../../../../types/component';
 import { MetricKey } from '../../../../types/metrics';
 import { ProjectAnalysisEventCategory } from '../../../../types/project-activity';
@@ -266,9 +266,9 @@ describe('project overview', () => {
       'B',
       {
         total: 1,
-        high: 0,
-        medium: 1,
-        low: 0,
+        [SoftwareImpactSeverity.High]: 0,
+        [SoftwareImpactSeverity.Medium]: 1,
+        [SoftwareImpactSeverity.Low]: 0,
       },
       [false, true, false],
     );
@@ -277,9 +277,9 @@ describe('project overview', () => {
       'A',
       {
         total: 3,
-        high: 0,
-        medium: 2,
-        low: 1,
+        [SoftwareImpactSeverity.High]: 0,
+        [SoftwareImpactSeverity.Medium]: 2,
+        [SoftwareImpactSeverity.Low]: 1,
       },
       [false, false, false],
     );
@@ -288,9 +288,9 @@ describe('project overview', () => {
       'E',
       {
         total: 2,
-        high: 0,
-        medium: 0,
-        low: 1,
+        [SoftwareImpactSeverity.High]: 0,
+        [SoftwareImpactSeverity.Medium]: 0,
+        [SoftwareImpactSeverity.Low]: 1,
       },
       [false, false, true],
     );
@@ -312,9 +312,9 @@ describe('project overview', () => {
       'B',
       {
         total: 1,
-        high: 0,
-        medium: 1,
-        low: 0,
+        [SoftwareImpactSeverity.High]: 0,
+        [SoftwareImpactSeverity.Medium]: 1,
+        [SoftwareImpactSeverity.Low]: 0,
       },
       [false, true, false],
     );
@@ -323,9 +323,9 @@ describe('project overview', () => {
       'A',
       {
         total: 3,
-        high: 0,
-        medium: 2,
-        low: 1,
+        [SoftwareImpactSeverity.High]: 0,
+        [SoftwareImpactSeverity.Medium]: 2,
+        [SoftwareImpactSeverity.Low]: 1,
       },
       [false, false, false],
     );
index d9e676b2169a8105c5bde43631bc2e5b0e3f93ee..319831442db009f43e3f00cd6fec21dfb63d89fd 100644 (file)
@@ -51,17 +51,23 @@ export const getPageObjects = () => {
         ).toBeInTheDocument();
         expect(
           byRole('link', {
-            name: `overview.measures.software_impact.severity.see_x_open_issues.${data.high}.software_quality.${softwareQuality}.overview.measures.software_impact.severity.HIGH.tooltip`,
+            name: `overview.measures.software_impact.severity.see_x_open_issues.${
+              data[SoftwareImpactSeverity.High]
+            }.software_quality.${softwareQuality}.overview.measures.software_impact.severity.HIGH.tooltip`,
           }).get(),
         ).toBeInTheDocument();
         expect(
           byRole('link', {
-            name: `overview.measures.software_impact.severity.see_x_open_issues.${data.medium}.software_quality.${softwareQuality}.overview.measures.software_impact.severity.MEDIUM.tooltip`,
+            name: `overview.measures.software_impact.severity.see_x_open_issues.${
+              data[SoftwareImpactSeverity.Medium]
+            }.software_quality.${softwareQuality}.overview.measures.software_impact.severity.MEDIUM.tooltip`,
           }).get(),
         ).toBeInTheDocument();
         expect(
           byRole('link', {
-            name: `overview.measures.software_impact.severity.see_x_open_issues.${data.low}.software_quality.${softwareQuality}.overview.measures.software_impact.severity.LOW.tooltip`,
+            name: `overview.measures.software_impact.severity.see_x_open_issues.${
+              data[SoftwareImpactSeverity.Low]
+            }.software_quality.${softwareQuality}.overview.measures.software_impact.severity.LOW.tooltip`,
           }).get(),
         ).toBeInTheDocument();
       }
index 4510c2641df00e45ac8393f5b327d2b54c66b474..b6a894181f78137da6a8faae462645494c2f3701 100644 (file)
@@ -24,11 +24,7 @@ import { ISSUETYPE_METRIC_KEYS_MAP } from '../../helpers/issues';
 import { translate } from '../../helpers/l10n';
 import { formatMeasure } from '../../helpers/measures';
 import { parseAsString } from '../../helpers/query';
-import {
-  SoftwareImpactMeasureData,
-  SoftwareImpactSeverity,
-  SoftwareQuality,
-} from '../../types/clean-code-taxonomy';
+import { SoftwareQuality } from '../../types/clean-code-taxonomy';
 import { IssueType } from '../../types/issues';
 import { MetricKey } from '../../types/metrics';
 import { AnalysisMeasuresVariations, MeasureHistory } from '../../types/project-activity';
@@ -194,15 +190,6 @@ export function softwareQualityToMeasure(softwareQuality: SoftwareQuality): Metr
   return (softwareQuality.toLowerCase() + '_issues') as MetricKey;
 }
 
-// Extract the number of issues for a given severity in the software impact measure
-export function getSoftwareImpactSeverityValue(
-  severity: SoftwareImpactSeverity,
-  softwareImpactMeasure?: SoftwareImpactMeasureData,
-) {
-  const key = severity.toLowerCase() as keyof SoftwareImpactMeasureData;
-  return softwareImpactMeasure ? softwareImpactMeasure[key]?.toString() : '';
-}
-
 export function getIssueRatingName(type: IssueType) {
   return translate('metric_domain', ISSUETYPE_METRIC_KEYS_MAP[type].ratingName);
 }
index ea51bfbe928e7e1a8e80e426edec4127022fd448..120a753bc91359699fc2cbb25e2d9c4eecd59d06 100644 (file)
@@ -60,7 +60,7 @@ export interface SoftwareImpact {
 
 export interface SoftwareImpactMeasureData {
   total: number;
-  high: number;
-  medium: number;
-  low: number;
+  [SoftwareImpactSeverity.High]: number;
+  [SoftwareImpactSeverity.Medium]: number;
+  [SoftwareImpactSeverity.Low]: number;
 }