]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12720 Ignore the creation event in the review history tab's count
authorPhilippe Perrin <philippe.perrin@sonarsource.com>
Tue, 7 Jan 2020 10:10:25 +0000 (11:10 +0100)
committerSonarTech <sonartech@sonarsource.com>
Mon, 13 Jan 2020 19:46:37 +0000 (20:46 +0100)
server/sonar-web/src/main/js/apps/securityHotspots/__tests__/utils-test.ts
server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerTabs.tsx
server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotViewerTabs-test.tsx
server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotViewerTabs-test.tsx.snap
server/sonar-web/src/main/js/apps/securityHotspots/utils.ts

index c93b4e01bcbfd5aa913b419735e7010f55940880..a837324eba8da1267ee8983209cd2f9e45ae64f4 100644 (file)
@@ -182,17 +182,18 @@ describe('getHotspotReviewHistory', () => {
       changelog: [changelogElement],
       comment: [commentElement, commentElement1]
     });
-    const history = getHotspotReviewHistory(hotspot);
+    const reviewHistory = getHotspotReviewHistory(hotspot);
 
-    expect(history.length).toBe(4);
-    expect(history[0]).toEqual(
+    expect(reviewHistory.history.length).toBe(4);
+    expect(reviewHistory.functionalCount).toBe(3);
+    expect(reviewHistory.history[0]).toEqual(
       expect.objectContaining({
         type: ReviewHistoryType.Creation,
         date: hotspot.creationDate,
         user: hotspot.authorUser
       })
     );
-    expect(history[1]).toEqual(
+    expect(reviewHistory.history[1]).toEqual(
       expect.objectContaining({
         type: ReviewHistoryType.Comment,
         date: commentElement.createdAt,
@@ -200,7 +201,7 @@ describe('getHotspotReviewHistory', () => {
         html: commentElement.htmlText
       })
     );
-    expect(history[2]).toEqual(
+    expect(reviewHistory.history[2]).toEqual(
       expect.objectContaining({
         type: ReviewHistoryType.Comment,
         date: commentElement1.createdAt,
@@ -208,7 +209,7 @@ describe('getHotspotReviewHistory', () => {
         html: commentElement1.htmlText
       })
     );
-    expect(history[3]).toEqual(
+    expect(reviewHistory.history[3]).toEqual(
       expect.objectContaining({
         type: ReviewHistoryType.Diff,
         date: changelogElement.creationDate,
index a52facf28bf8eca6488ca7e2419f38551346fed7..484f525c8df46c427d49e887fc6faabc2bedd445 100644 (file)
@@ -62,11 +62,15 @@ export default function HotspotViewerTabs(props: HotspotViewerTabsProps) {
       label: (
         <>
           <span>{translate('hotspots.tabs.review_history')}</span>
-          <span className="counter-badge spacer-left">{hotspotReviewHistory.length}</span>
+          {hotspotReviewHistory.functionalCount > 0 && (
+            <span className="counter-badge spacer-left">
+              {hotspotReviewHistory.functionalCount}
+            </span>
+          )}
         </>
       ),
-      content: hotspotReviewHistory.length > 0 && (
-        <HotspotViewerReviewHistoryTab history={hotspotReviewHistory} />
+      content: hotspotReviewHistory.history.length > 0 && (
+        <HotspotViewerReviewHistoryTab history={hotspotReviewHistory.history} />
       )
     }
   ].filter(tab => Boolean(tab.content));
index a28be0a541ba7ad4a9bdefece01b61b46f2f9ac6..42f7266255a97cc661f97441334d9d9e2ffe9be8 100644 (file)
@@ -21,6 +21,7 @@ import { shallow } from 'enzyme';
 import * as React from 'react';
 import BoxedTabs from 'sonar-ui-common/components/controls/BoxedTabs';
 import { mockHotspot, mockHotspotRule } from '../../../../helpers/mocks/security-hotspots';
+import { mockUser } from '../../../../helpers/testMocks';
 import HotspotViewerTabs, { HotspotViewerTabsProps, Tabs } from '../HotspotViewerTabs';
 
 it('should render correctly', () => {
@@ -60,8 +61,26 @@ it('should render correctly', () => {
           vulnerabilityDescription: undefined
         })
       })
+    }).type()
+  ).toBeNull();
+
+  expect(
+    shallowRender({
+      hotspot: mockHotspot({
+        comment: [
+          {
+            createdAt: '2019-01-01',
+            htmlText: '<strong>test</strong>',
+            key: 'comment-key',
+            login: 'me',
+            markdown: '*test*',
+            updatable: false,
+            user: mockUser()
+          }
+        ]
+      })
     })
-  ).toMatchSnapshot('no tabs');
+  ).toMatchSnapshot('with comments or changelog element');
 });
 
 function shallowRender(props?: Partial<HotspotViewerTabsProps>) {
index 9b33f4ab30b984f1a4faddbbae0b175fbf774be8..26ead486bb705f178663dbc4467de603fa9ca295 100644 (file)
@@ -39,11 +39,6 @@ exports[`should render correctly: empty tab 1`] = `
             <span>
               hotspots.tabs.review_history
             </span>
-            <span
-              className="counter-badge spacer-left"
-            >
-              1
-            </span>
           </React.Fragment>,
         },
       ]
@@ -108,11 +103,6 @@ exports[`should render correctly: fix 1`] = `
             <span>
               hotspots.tabs.review_history
             </span>
-            <span
-              className="counter-badge spacer-left"
-            >
-              1
-            </span>
           </React.Fragment>,
         },
       ]
@@ -133,8 +123,6 @@ exports[`should render correctly: fix 1`] = `
 </Fragment>
 `;
 
-exports[`should render correctly: no tabs 1`] = `""`;
-
 exports[`should render correctly: review 1`] = `
 <Fragment>
   <BoxedTabs
@@ -179,11 +167,6 @@ exports[`should render correctly: review 1`] = `
             <span>
               hotspots.tabs.review_history
             </span>
-            <span
-              className="counter-badge spacer-left"
-            >
-              1
-            </span>
           </React.Fragment>,
         },
       ]
@@ -256,11 +239,6 @@ exports[`should render correctly: risk 1`] = `
             <span>
               hotspots.tabs.review_history
             </span>
-            <span
-              className="counter-badge spacer-left"
-            >
-              1
-            </span>
           </React.Fragment>,
         },
       ]
@@ -321,6 +299,81 @@ exports[`should render correctly: vulnerability 1`] = `
             }
           />,
           "key": "review",
+          "label": <React.Fragment>
+            <span>
+              hotspots.tabs.review_history
+            </span>
+          </React.Fragment>,
+        },
+      ]
+    }
+  />
+  <div
+    className="bordered"
+  >
+    <div
+      className="markdown big-padded"
+      dangerouslySetInnerHTML={
+        Object {
+          "__html": "<p>This a <strong>strong</strong> message about vulnerability !</p>",
+        }
+      }
+    />
+  </div>
+</Fragment>
+`;
+
+exports[`should render correctly: with comments or changelog element 1`] = `
+<Fragment>
+  <BoxedTabs
+    onSelect={[Function]}
+    selected="risk"
+    tabs={
+      Array [
+        Object {
+          "content": "<p>This a <strong>strong</strong> message about risk !</p>",
+          "key": "risk",
+          "label": "hotspots.tabs.risk_description",
+        },
+        Object {
+          "content": "<p>This a <strong>strong</strong> message about vulnerability !</p>",
+          "key": "vulnerability",
+          "label": "hotspots.tabs.vulnerability_description",
+        },
+        Object {
+          "content": "<p>This a <strong>strong</strong> message about fixing !</p>",
+          "key": "fix",
+          "label": "hotspots.tabs.fix_recommendations",
+        },
+        Object {
+          "content": <HotspotViewerReviewHistoryTab
+            history={
+              Array [
+                Object {
+                  "date": "2013-05-13T17:55:41+0200",
+                  "type": 0,
+                  "user": Object {
+                    "active": true,
+                    "local": true,
+                    "login": "author",
+                    "name": "John Doe",
+                  },
+                },
+                Object {
+                  "date": "2019-01-01",
+                  "html": "<strong>test</strong>",
+                  "type": 2,
+                  "user": Object {
+                    "active": true,
+                    "local": true,
+                    "login": "john.doe",
+                    "name": "John Doe",
+                  },
+                },
+              ]
+            }
+          />,
+          "key": "review",
           "label": <React.Fragment>
             <span>
               hotspots.tabs.review_history
@@ -342,7 +395,7 @@ exports[`should render correctly: vulnerability 1`] = `
       className="markdown big-padded"
       dangerouslySetInnerHTML={
         Object {
-          "__html": "<p>This a <strong>strong</strong> message about vulnerability !</p>",
+          "__html": "<p>This a <strong>strong</strong> message about risk !</p>",
         }
       }
     />
index 7d1de26d4859295ff94149fa11defb75817e90e5..cfa1e81f5ed517fe50ae374600d4bb1b1f441b2a 100644 (file)
@@ -81,8 +81,14 @@ export function constructSourceViewerFile(
   };
 }
 
-export function getHotspotReviewHistory(hotspot: Hotspot): ReviewHistoryElement[] {
+export function getHotspotReviewHistory(
+  hotspot: Hotspot
+): {
+  history: ReviewHistoryElement[];
+  functionalCount: number;
+} {
   const history: ReviewHistoryElement[] = [];
+  let functionalCount = 0;
 
   if (hotspot.creationDate) {
     history.push({
@@ -96,6 +102,7 @@ export function getHotspotReviewHistory(hotspot: Hotspot): ReviewHistoryElement[
   }
 
   if (hotspot.changelog && hotspot.changelog.length > 0) {
+    functionalCount += hotspot.changelog.length;
     history.push(
       ...hotspot.changelog.map(log => ({
         type: ReviewHistoryType.Diff,
@@ -111,6 +118,7 @@ export function getHotspotReviewHistory(hotspot: Hotspot): ReviewHistoryElement[
   }
 
   if (hotspot.comment && hotspot.comment.length > 0) {
+    functionalCount += hotspot.comment.length;
     history.push(
       ...hotspot.comment.map(comment => ({
         type: ReviewHistoryType.Comment,
@@ -124,5 +132,8 @@ export function getHotspotReviewHistory(hotspot: Hotspot): ReviewHistoryElement[
     );
   }
 
-  return sortBy(history, elt => elt.date);
+  return {
+    history: sortBy(history, elt => elt.date),
+    functionalCount
+  };
 }