From ce77e99565acad8ae1124ec7d4ead2d7fd9d07c6 Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Wed, 18 Dec 2019 16:26:25 +0100 Subject: [PATCH] SONAR-12721 Display Security Hotspots page on branches and pull requests --- .../src/main/js/api/security-hotspots.ts | 13 ++++++++----- .../securityHotspots/SecurityHotspotsApp.tsx | 10 +++++++++- .../__tests__/SecurityHotspotsApp-test.tsx | 12 +++++++++--- .../SecurityHotspotsApp-test.tsx.snap | 4 ++-- .../components/HotspotSnippetContainer.tsx | 7 +++++-- .../__tests__/HotspotSnippetContainer-test.tsx | 16 ++++++++++++++-- .../HotspotSnippetContainer-test.tsx.snap | 8 ++++++++ 7 files changed, 55 insertions(+), 15 deletions(-) diff --git a/server/sonar-web/src/main/js/api/security-hotspots.ts b/server/sonar-web/src/main/js/api/security-hotspots.ts index 9971cdd6c2e..316166e0f8d 100644 --- a/server/sonar-web/src/main/js/api/security-hotspots.ts +++ b/server/sonar-web/src/main/js/api/security-hotspots.ts @@ -19,6 +19,7 @@ */ import { getJSON, post } from 'sonar-ui-common/helpers/request'; import throwGlobalError from '../app/utils/throwGlobalError'; +import { BranchParameters } from '../types/branch-like'; import { DetailedHotspot, HotspotSearchResponse, @@ -29,11 +30,13 @@ export function setSecurityHotspotStatus(data: HotspotSetStatusRequest): Promise return post('/api/hotspots/change_status', data).catch(throwGlobalError); } -export function getSecurityHotspots(data: { - projectKey: string; - p: number; - ps: number; -}): Promise { +export function getSecurityHotspots( + data: { + projectKey: string; + p: number; + ps: number; + } & BranchParameters +): Promise { return getJSON('/api/hotspots/search', data).catch(throwGlobalError); } diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/SecurityHotspotsApp.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/SecurityHotspotsApp.tsx index 78d3ddf7d53..768643395e2 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/SecurityHotspotsApp.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/SecurityHotspotsApp.tsx @@ -20,6 +20,7 @@ import * as React from 'react'; import { addNoFooterPageClass, removeNoFooterPageClass } from 'sonar-ui-common/helpers/pages'; import { getSecurityHotspots } from '../../api/security-hotspots'; +import { getBranchLikeQuery } from '../../helpers/branch-like'; import { getStandards } from '../../helpers/security-standard'; import { BranchLike } from '../../types/branch-like'; import { HotspotUpdate, RawHotspot } from '../../types/security-hotspots'; @@ -68,9 +69,16 @@ export default class SecurityHotspotsApp extends React.PureComponent { if (!this.mounted) { diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/SecurityHotspotsApp-test.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/SecurityHotspotsApp-test.tsx index 1b43fe4cfcc..9e73887780f 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/SecurityHotspotsApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/SecurityHotspotsApp-test.tsx @@ -22,7 +22,7 @@ import * as React from 'react'; import { addNoFooterPageClass } from 'sonar-ui-common/helpers/pages'; import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils'; import { getSecurityHotspots } from '../../../api/security-hotspots'; -import { mockMainBranch } from '../../../helpers/mocks/branch-like'; +import { mockBranch } from '../../../helpers/mocks/branch-like'; import { mockRawHotspot } from '../../../helpers/mocks/security-hotspots'; import { getStandards } from '../../../helpers/security-standard'; import { mockComponent } from '../../../helpers/testMocks'; @@ -43,6 +43,8 @@ jest.mock('../../../helpers/security-standard', () => ({ getStandards: jest.fn() })); +const branch = mockBranch(); + it('should render correctly', () => { expect(shallowRender()).toMatchSnapshot(); }); @@ -62,7 +64,11 @@ it('should load data correctly', async () => { expect(addNoFooterPageClass).toBeCalled(); expect(getStandards).toBeCalled(); - expect(getSecurityHotspots).toBeCalled(); + expect(getSecurityHotspots).toBeCalledWith( + expect.objectContaining({ + branch: branch.name + }) + ); await waitAndUpdate(wrapper); @@ -100,6 +106,6 @@ it('should handle hotspot update', async () => { function shallowRender(props: Partial = {}) { return shallow( - + ); } diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap b/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap index 56682f1ba2e..b2a09e10b46 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/securityHotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap @@ -6,8 +6,8 @@ exports[`should render correctly 1`] = ` Object { "analysisDate": "2018-01-01", "excludedFromPurge": true, - "isMain": true, - "name": "master", + "isMain": false, + "name": "branch-6.7", } } hotspots={Array []} diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotSnippetContainer.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotSnippetContainer.tsx index bc6839740c0..5974f278b7f 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotSnippetContainer.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/HotspotSnippetContainer.tsx @@ -77,14 +77,17 @@ export default class HotspotSnippetContainer extends React.Component { if (this.mounted) { const lastLine = this.checkLastLine(sourceLines, to); diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotSnippetContainer-test.tsx b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotSnippetContainer-test.tsx index 4000d8ed8dd..622840289f8 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotSnippetContainer-test.tsx +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/HotspotSnippetContainer-test.tsx @@ -22,6 +22,7 @@ import { range } from 'lodash'; import * as React from 'react'; import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils'; import { getSources } from '../../../../api/components'; +import { mockBranch } from '../../../../helpers/mocks/branch-like'; import { mockDetailledHotspot } from '../../../../helpers/mocks/security-hotspots'; import { mockSourceLine } from '../../../../helpers/testMocks'; import HotspotSnippetContainer from '../HotspotSnippetContainer'; @@ -31,6 +32,8 @@ jest.mock('../../../../api/components', () => ({ getSources: jest.fn().mockResolvedValue([]) })); +const branch = mockBranch(); + it('should render correctly', () => { expect(shallowRender()).toMatchSnapshot(); }); @@ -48,7 +51,11 @@ it('should load sources on mount', async () => { await waitAndUpdate(wrapper); - expect(getSources).toBeCalled(); + expect(getSources).toBeCalledWith( + expect.objectContaining({ + branch: branch.name + }) + ); expect(wrapper.state().lastLine).toBeUndefined(); expect(wrapper.state().sourceLines).toHaveLength(12); }); @@ -97,6 +104,11 @@ describe('Expansion', () => { await waitAndUpdate(wrapper); + expect(getSources).toBeCalledWith( + expect.objectContaining({ + branch: branch.name + }) + ); expect(wrapper.state().sourceLines).toHaveLength(16); }); @@ -181,6 +193,6 @@ it('should handle symbol click', () => { function shallowRender(props?: Partial) { return shallow( - + ); } diff --git a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap index 1d94193a839..0d5e1ad75b4 100644 --- a/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/securityHotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap @@ -2,6 +2,14 @@ exports[`should render correctly 1`] = `