]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22464 Hide Software qualities impacted in hotspots
authorViktor Vorona <viktor.vorona@sonarsource.com>
Wed, 3 Jul 2024 13:11:13 +0000 (15:11 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 5 Jul 2024 20:02:32 +0000 (20:02 +0000)
server/sonar-web/src/main/js/api/mocks/data/rules.ts
server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRules-it.ts
server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsHeaderSide.tsx
server/sonar-web/src/main/js/apps/coding-rules/utils-tests.tsx

index 472a90d49baa9551caccf6a3b67f16b549e0d08c..37acd30ad075eafdf09d60b857a6b8e69f455afc 100644 (file)
@@ -119,6 +119,9 @@ export function mockRuleDetailsList() {
           content: resourceContent,
         },
       ],
+      impacts: [],
+      cleanCodeAttributeCategory: undefined,
+      cleanCodeAttribute: undefined,
       langName: 'JavaScript',
     }),
     mockRuleDetails({
index 193053a36606a0c7236d6cd700e86ab9ca5b1ccf..d17faa7d4ed263588ac92f6733f1a8627b1bdda9 100644 (file)
@@ -177,16 +177,16 @@ describe('Rules app list', () => {
       // Filter by clean code category
       await user.click(ui.facetItem('issue.clean_code_attribute_category.INTENTIONAL').get());
 
-      expect(ui.getAllRuleListItems()).toHaveLength(10);
+      expect(ui.getAllRuleListItems()).toHaveLength(9);
 
       // Filter by software quality
       await user.click(ui.facetItem('software_quality.MAINTAINABILITY').get());
-      expect(ui.getAllRuleListItems()).toHaveLength(10);
+      expect(ui.getAllRuleListItems()).toHaveLength(9);
 
       // Filter by severity
       await user.click(ui.severetiesFacet.get());
       await user.click(ui.facetItem(/severity.HIGH/).get());
-      expect(ui.getAllRuleListItems()).toHaveLength(9);
+      expect(ui.getAllRuleListItems()).toHaveLength(8);
     });
 
     it('filter by standards', async () => {
@@ -529,6 +529,8 @@ describe('Rule app details', () => {
       // Check params data
       expect(screen.getByText('html description for key 1')).toBeInTheDocument();
       expect(screen.getByText('default value for key 2')).toBeInTheDocument();
+      expect(ui.softwareQualitiesSection.get()).toBeInTheDocument();
+      expect(ui.cleanCodeAttributeSection.get()).toBeInTheDocument();
     });
 
     it('shows external rule', async () => {
@@ -545,6 +547,8 @@ describe('Rule app details', () => {
       await ui.detailsloaded();
       expect(ui.ruleTitle('Hot hotspot').get()).toBeInTheDocument();
       expect(ui.introTitle.get()).toBeInTheDocument();
+      expect(ui.softwareQualitiesSection.query()).not.toBeInTheDocument();
+      expect(ui.cleanCodeAttributeSection.query()).not.toBeInTheDocument();
 
       // Shows correct tabs
       [ui.whatRiskTab, ui.assessTab, ui.moreInfoTab].forEach((tab) => {
index 69a76df022b2cf3523cf0f4d11fd8670243ee67e..4b1a4ee55220c61ec74422832451ace654dfc539 100644 (file)
@@ -30,6 +30,14 @@ interface Props {
 }
 
 export default function RuleDetailsHeaderSide({ ruleDetails }: Readonly<Props>) {
+  const hasCleanCodeAttribute =
+    ruleDetails.cleanCodeAttributeCategory && ruleDetails.cleanCodeAttribute;
+  const hasSoftwareImpact = ruleDetails.impacts.length > 0;
+
+  if (!hasCleanCodeAttribute && !hasSoftwareImpact) {
+    return null;
+  }
+
   return (
     <StyledSection className="sw-flex sw-flex-col sw-pl-4 sw-gap-6 sw-max-w-[250px]">
       {ruleDetails.cleanCodeAttributeCategory && ruleDetails.cleanCodeAttribute && (
@@ -42,13 +50,15 @@ export default function RuleDetailsHeaderSide({ ruleDetails }: Readonly<Props>)
         </RuleHeaderInfo>
       )}
 
-      <RuleHeaderInfo title={translate('coding_rules.software_qualities.label')}>
-        <SoftwareImpactPillList
-          className="sw-flex-wrap"
-          softwareImpacts={ruleDetails.impacts}
-          type="rule"
-        />
-      </RuleHeaderInfo>
+      {hasSoftwareImpact && (
+        <RuleHeaderInfo title={translate('coding_rules.software_qualities.label')}>
+          <SoftwareImpactPillList
+            className="sw-flex-wrap"
+            softwareImpacts={ruleDetails.impacts}
+            type="rule"
+          />
+        </RuleHeaderInfo>
+      )}
     </StyledSection>
   );
 }
index eec6400700a1f94971a1731bdc206fce0aed13c1..b2dedfd2226bee704385d4c942f9114a18594c9f 100644 (file)
@@ -198,6 +198,8 @@ const selectors = {
   createButton: byRole('button', { name: 'create' }),
   reactivateButton: byRole('button', { name: 'coding_rules.reactivate' }),
   deleteButton: byRole('button', { name: 'delete' }),
+  softwareQualitiesSection: byText('coding_rules.software_qualities.label'),
+  cleanCodeAttributeSection: byText('coding_rules.cct_attribute.label'),
 };
 
 export function getPageObjects() {