From: Philippe Perrin Date: Tue, 7 Jan 2020 10:10:25 +0000 (+0100) Subject: SONAR-12720 Ignore the creation event in the review history tab's count X-Git-Tag: 8.2.0.32929~141 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=21e86b4e115acf309ed10cc29e0ec58810270f39;p=sonarqube.git SONAR-12720 Ignore the creation event in the review history tab's count --- diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/utils-test.ts index c93b4e01bcb..a837324eba8 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/utils-test.ts +++ b/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/utils-test.ts @@ -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, diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerTabs.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerTabs.tsx index a52facf28bf..484f525c8df 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerTabs.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotViewerTabs.tsx @@ -62,11 +62,15 @@ export default function HotspotViewerTabs(props: HotspotViewerTabsProps) { label: ( <> {translate('hotspots.tabs.review_history')} - {hotspotReviewHistory.length} + {hotspotReviewHistory.functionalCount > 0 && ( + + {hotspotReviewHistory.functionalCount} + + )} ), - content: hotspotReviewHistory.length > 0 && ( - + content: hotspotReviewHistory.history.length > 0 && ( + ) } ].filter(tab => Boolean(tab.content)); diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotViewerTabs-test.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotViewerTabs-test.tsx index a28be0a541b..42f7266255a 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotViewerTabs-test.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotViewerTabs-test.tsx @@ -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: 'test', + key: 'comment-key', + login: 'me', + markdown: '*test*', + updatable: false, + user: mockUser() + } + ] + }) }) - ).toMatchSnapshot('no tabs'); + ).toMatchSnapshot('with comments or changelog element'); }); function shallowRender(props?: Partial) { diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotViewerTabs-test.tsx.snap b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotViewerTabs-test.tsx.snap index 9b33f4ab30b..26ead486bb7 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotViewerTabs-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotViewerTabs-test.tsx.snap @@ -39,11 +39,6 @@ exports[`should render correctly: empty tab 1`] = ` hotspots.tabs.review_history - - 1 - , }, ] @@ -108,11 +103,6 @@ exports[`should render correctly: fix 1`] = ` hotspots.tabs.review_history - - 1 - , }, ] @@ -133,8 +123,6 @@ exports[`should render correctly: fix 1`] = ` `; -exports[`should render correctly: no tabs 1`] = `""`; - exports[`should render correctly: review 1`] = ` hotspots.tabs.review_history - - 1 - , }, ] @@ -256,11 +239,6 @@ exports[`should render correctly: risk 1`] = ` hotspots.tabs.review_history - - 1 - , }, ] @@ -321,6 +299,81 @@ exports[`should render correctly: vulnerability 1`] = ` } />, "key": "review", + "label": + + hotspots.tabs.review_history + + , + }, + ] + } + /> +
+
This a strong message about vulnerability !

", + } + } + /> +
+ +`; + +exports[`should render correctly: with comments or changelog element 1`] = ` + + This a strong message about risk !

", + "key": "risk", + "label": "hotspots.tabs.risk_description", + }, + Object { + "content": "

This a strong message about vulnerability !

", + "key": "vulnerability", + "label": "hotspots.tabs.vulnerability_description", + }, + Object { + "content": "

This a strong message about fixing !

", + "key": "fix", + "label": "hotspots.tabs.fix_recommendations", + }, + Object { + "content": test", + "type": 2, + "user": Object { + "active": true, + "local": true, + "login": "john.doe", + "name": "John Doe", + }, + }, + ] + } + />, + "key": "review", "label": hotspots.tabs.review_history @@ -342,7 +395,7 @@ exports[`should render correctly: vulnerability 1`] = ` className="markdown big-padded" dangerouslySetInnerHTML={ Object { - "__html": "

This a strong message about vulnerability !

", + "__html": "

This a strong message about risk !

", } } /> diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/utils.ts b/server/sonar-web/src/main/js/apps/securityHotspots/utils.ts index 7d1de26d485..cfa1e81f5ed 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/utils.ts +++ b/server/sonar-web/src/main/js/apps/securityHotspots/utils.ts @@ -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 + }; }