]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23232 Fix analysis missing message showing on all Pull Requests
authorIsmail Cherri <ismail.cherri@sonarsource.com>
Mon, 21 Oct 2024 11:57:13 +0000 (13:57 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 22 Oct 2024 20:03:09 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/component-measures/__tests__/ComponentMeasures-it.tsx
server/sonar-web/src/main/js/apps/component-measures/components/ComponentMeasuresApp.tsx
server/sonar-web/src/main/js/helpers/measures.ts

index 1a0ccf0c4d19025448583889caed6f715345b871..a3f42dde545d828b1c0b47437c3fa42218b4143f 100644 (file)
@@ -176,7 +176,7 @@ describe('rendering', () => {
     ].forEach((measure) => {
       expect(ui.measureLink(measure).get()).toBeInTheDocument();
     });
-    expect(screen.getByText('overview.missing_project_dataTRK')).toBeInTheDocument();
+    expect(ui.analysisMissingMessage.get()).toBeInTheDocument();
   });
 
   it('should show new counts but not ratings if no rating measures', async () => {
@@ -208,7 +208,7 @@ describe('rendering', () => {
     ].forEach((measure) => {
       expect(ui.measureLink(measure).get()).toBeInTheDocument();
     });
-    expect(screen.getByText('overview.missing_project_dataTRK')).toBeInTheDocument();
+    expect(ui.analysisMissingMessage.get()).toBeInTheDocument();
   });
 
   it('should show old measures and no flag message if no rating measures and legacy mode', async () => {
@@ -345,6 +345,26 @@ describe('rendering', () => {
     expect(await ui.detailsUnavailableText.find()).toBeInTheDocument();
   });
 
+  it('should not render analysis missing if on a pull request and leak measure are available', async () => {
+    const { ui } = getPageObject();
+    renderMeasuresApp('component_measures?id=foo&pullRequest=01');
+    await ui.appLoaded();
+
+    expect(screen.queryByText('overview.missing_project_dataTRK')).not.toBeInTheDocument();
+  });
+
+  it('should render analysis missing if on a pull request and leak measure are missing', async () => {
+    const { ui } = getPageObject();
+    measuresHandler.deleteComponentMeasure(
+      'foo',
+      MetricKey.new_software_quality_maintainability_rating,
+    );
+    renderMeasuresApp('component_measures?id=foo&pullRequest=01');
+    await ui.appLoaded();
+
+    expect(ui.analysisMissingMessage.get()).toBeInTheDocument();
+  });
+
   it('should render a warning message if the user does not have access to all components', async () => {
     const { ui } = getPageObject();
     renderMeasuresApp('component_measures?id=foo&metric=code_smells', {
@@ -663,6 +683,7 @@ function getPageObject() {
     seeDataAsListLink: byRole('link', { name: 'component_measures.overview.see_data_as_list' }),
     bubbleChart: byTestId('bubble-chart'),
     newCodePeriodTxt: byText('component_measures.leak_legend.new_code'),
+    analysisMissingMessage: byText('overview.missing_project_dataTRK'),
 
     // Navigation
     overviewDomainLink: byRole('link', {
index f12e7111e682570cd7b064d5dc2882d77e89560a..f1a488cb6bdf746a974106fc0cc5044a522aec92 100644 (file)
@@ -46,6 +46,8 @@ import AnalysisMissingInfoMessage from '../../../components/shared/AnalysisMissi
 import { translate } from '../../../helpers/l10n';
 import {
   areCCTMeasuresComputed,
+  areLeakCCTMeasuresComputed,
+  areLeakSoftwareQualityRatingsComputed,
   areSoftwareQualityRatingsComputed,
 } from '../../../helpers/measures';
 import { useCurrentBranchQuery } from '../../../queries/branch';
@@ -104,6 +106,10 @@ export default function ComponentMeasuresApp() {
     componentWithMeasures?.qualifier === ComponentQualifier.Project ? period : undefined;
   const displayOverview = hasBubbleChart(bubblesByDomain, query.metric);
 
+  const showMissingAnalysisMessage = isPullRequest(branchLike)
+    ? !areLeakCCTMeasuresComputed(measures) || !areLeakSoftwareQualityRatingsComputed(measures)
+    : !areCCTMeasuresComputed(measures) || !areSoftwareQualityRatingsComputed(measures);
+
   if (!component) {
     return null;
   }
@@ -226,8 +232,7 @@ export default function ComponentMeasuresApp() {
                   />
                 </FlagMessage>
               )}
-              {(!areCCTMeasuresComputed(measures) ||
-                !areSoftwareQualityRatingsComputed(measures)) && (
+              {showMissingAnalysisMessage && (
                 <AnalysisMissingInfoMessage
                   className="sw-mb-4"
                   qualifier={component?.qualifier as ComponentQualifier}
index d7569bbb15dec795233d323eb378fc130ebf2843..c3fed3454e397fe996457d1517062f111bdcacd0 100644 (file)
@@ -129,6 +129,18 @@ export function areSoftwareQualityRatingsComputed(measures?: Measure[] | Measure
   );
 }
 
+export function areLeakSoftwareQualityRatingsComputed(measures?: Measure[] | MeasureEnhanced[]) {
+  return [
+    MetricKey.new_software_quality_reliability_rating,
+    MetricKey.new_software_quality_security_rating,
+    MetricKey.new_software_quality_maintainability_rating,
+  ].every((metric) =>
+    measures?.find((measure) =>
+      isMeasureEnhanced(measure) ? measure.metric.key === metric : measure.metric === metric,
+    ),
+  );
+}
+
 export function areLeakAndOverallCCTMeasuresComputed(measures?: Measure[] | MeasureEnhanced[]) {
   return areLeakCCTMeasuresComputed(measures) && areCCTMeasuresComputed(measures);
 }