]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16365 Adding title to rule description section
authorMathieu Suen <mathieu.suen@sonarsource.com>
Wed, 25 May 2022 14:13:25 +0000 (16:13 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 25 May 2022 20:03:17 +0000 (20:03 +0000)
server/sonar-web/src/main/js/api/mocks/CodingRulesMock.ts
server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRules-it.ts
server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 30934b14f667aba8ab016763781d786222b8544b..5214c7e0bb2ebb747cac79fbd6bc5b7f62235ab7 100644 (file)
@@ -80,6 +80,15 @@ export default class CodingRulesMock {
         name: 'Hot hotspot',
         type: 'SECURITY_HOTSPOT',
         lang: 'js',
+        descriptionSections: [
+          { key: RuleDescriptionSections.INTRODUCTION, content: 'Introduction to this rule' },
+          { key: RuleDescriptionSections.ROOT_CAUSE, content: 'This how to fix' },
+          { key: RuleDescriptionSections.ASSESS_THE_PROBLEM, content: 'Assess' },
+          {
+            key: RuleDescriptionSections.RESOURCES,
+            content: 'Some link <a href="http://example.com">Awsome Reading</a>'
+          }
+        ],
         langName: 'JavaScript'
       }),
       mockRuleDetails({ key: 'rule3', name: 'Unknown rule', lang: 'js', langName: 'JavaScript' }),
index 8386c527c4592154cf626283fc436f9341fa204b..5331ba52c24cc3c865d13d1ea9994cae34343c62 100644 (file)
@@ -68,7 +68,7 @@ it('should show open rule with default description section', async () => {
     await screen.findByRole('heading', { level: 3, name: 'Awsome java rule' })
   ).toBeInTheDocument();
   expect(
-    screen.getByRole('region', { name: 'coding_rules.description_section.title.root_cause' })
+    screen.getByRole('heading', { name: 'coding_rules.description_section.title.root_cause' })
   ).toBeInTheDocument();
 });
 
@@ -80,19 +80,52 @@ it('should show open rule with no description', async () => {
   expect(screen.getByText('issue.external_issue_description.Bad Python rule')).toBeInTheDocument();
 });
 
-it('should show open rule advance section', async () => {
+it('should show hotspot rule section', async () => {
+  renderCodingRulesApp(undefined, 'coding_rules?open=rule2');
+  expect(await screen.findByRole('heading', { level: 3, name: 'Hot hotspot' })).toBeInTheDocument();
+  expect(
+    screen.getByRole('heading', {
+      name: 'coding_rules.description_section.title.introduction'
+    })
+  ).toBeInTheDocument();
+  expect(
+    screen.getByRole('heading', {
+      name: 'coding_rules.description_section.title.root_cause.SECURITY_HOTSPOT'
+    })
+  ).toBeInTheDocument();
+  expect(
+    screen.getByRole('heading', {
+      name: 'coding_rules.description_section.title.assess_the_problem'
+    })
+  ).toBeInTheDocument();
+  expect(
+    screen.getByRole('heading', {
+      name: 'coding_rules.description_section.title.resources'
+    })
+  ).toBeInTheDocument();
+  // Check that we render plain html
+  expect(screen.getByRole('link', { name: 'Awsome Reading' })).toBeInTheDocument();
+});
+
+it('should show rule advanced section', async () => {
   renderCodingRulesApp(undefined, 'coding_rules?open=rule5');
   expect(
     await screen.findByRole('heading', { level: 3, name: 'Awsome Python rule' })
   ).toBeInTheDocument();
   expect(
-    screen.getByRole('region', { name: 'coding_rules.description_section.title.introduction' })
+    screen.getByRole('heading', {
+      name: 'coding_rules.description_section.title.introduction'
+    })
   ).toBeInTheDocument();
   expect(
-    screen.getByRole('region', { name: 'coding_rules.description_section.title.how_to_fix' })
+    screen.getByRole('heading', {
+      name: 'coding_rules.description_section.title.how_to_fix'
+    })
   ).toBeInTheDocument();
   expect(
-    screen.getByRole('region', { name: 'coding_rules.description_section.title.resources' })
+    screen.getByRole('heading', {
+      name: 'coding_rules.description_section.title.resources'
+    })
   ).toBeInTheDocument();
   // Check that we render plain html
   expect(screen.getByRole('link', { name: 'Awsome Reading' })).toBeInTheDocument();
index 2799bc26383c48f9129f11d4ce7bad59d6998f35..a400ae0e4022c9e3628da06e91d30fb49c3589f5 100644 (file)
@@ -207,17 +207,34 @@ export default class RuleDetailsDescription extends React.PureComponent<Props, S
     </div>
   );
 
-  renderDescription(section: RuleDescriptionSection) {
+  renderDescription = (section: RuleDescriptionSection) => {
+    if (section.key === RuleDescriptionSections.DEFAULT) {
+      return (
+        <section
+          className="coding-rules-detail-description rule-desc markdown"
+          key={section.key}
+          /* eslint-disable-next-line react/no-danger */
+          dangerouslySetInnerHTML={{ __html: sanitizeString(section.content) }}
+        />
+      );
+    }
+
+    const { ruleDetails } = this.props;
+    const title =
+      section.key === RuleDescriptionSections.ROOT_CAUSE && ruleDetails.type === 'SECURITY_HOTSPOT'
+        ? translate('coding_rules.description_section.title', section.key, ruleDetails.type)
+        : translate('coding_rules.description_section.title', section.key);
+
     return (
-      <section
-        aria-label={translate('coding_rules.description_section.title', section.key)}
-        className="coding-rules-detail-description rule-desc markdown"
-        key={section.key}
-        /* eslint-disable-next-line react/no-danger */
-        dangerouslySetInnerHTML={{ __html: sanitizeString(section.content) }}
-      />
+      <section className="coding-rules-detail-description rule-desc markdown" key={section.key}>
+        <h2>{title}</h2>
+        <div
+          /* eslint-disable-next-line react/no-danger */
+          dangerouslySetInnerHTML={{ __html: sanitizeString(section.content) }}
+        />
+      </section>
     );
-  }
+  };
 
   render() {
     const { ruleDetails } = this.props;
index 5a0b00d333cad3f34457cf9a702f28a4e5dd8878..3333fd74db096ba89cb8c8affb089d79a19fb7fe 100644 (file)
@@ -1897,9 +1897,9 @@ coding_rules.remediation_function.constant=Constant
 
 coding_rules.external_rule.engine=Rule provided by an external rule engine: {0}
 
-coding_rules.description_section.title.default= 
 coding_rules.description_section.title.introduction=Introduction
 coding_rules.description_section.title.root_cause=Why is this an issue?
+coding_rules.description_section.title.root_cause.SECURITY_HOTSPOT=What is the risk?
 coding_rules.description_section.title.assess_the_problem=Assess the risk?
 coding_rules.description_section.title.how_to_fix=How to fix it?
 coding_rules.description_section.title.resources=Resources