From bd0825ed81f4f105129b375054dd171d6e0850d3 Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Mon, 22 Feb 2021 15:25:02 +0100 Subject: [PATCH] SONAR-14486 Fix security hotspot information refresh --- .../components/HotspotViewer.tsx | 8 ++++++-- .../components/HotspotViewerRenderer.tsx | 4 ++-- .../components/__tests__/HotspotViewer-test.tsx | 17 +++++++++++++++-- .../HotspotViewerRenderer-test.tsx.snap | 10 +++++----- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewer.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewer.tsx index 839db3bdcc5..b538d2b21fb 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewer.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewer.tsx @@ -79,10 +79,14 @@ export default class HotspotViewer extends React.PureComponent { .catch(() => this.mounted && this.setState({ loading: false })); }; - handleHotspotUpdate = async () => { + handleHotspotUpdate = async (statusUpdate = false) => { const { hotspotKey } = this.props; - await this.props.onUpdateHotspot(hotspotKey); + if (statusUpdate) { + await this.props.onUpdateHotspot(hotspotKey); + } else { + await this.fetchHotspot(); + } }; handleOpenComment = () => { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewerRenderer.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewerRenderer.tsx index 4947981b877..fec84299eb5 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewerRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewerRenderer.tsx @@ -49,7 +49,7 @@ export interface HotspotViewerRendererProps { commentTextRef: React.RefObject; onOpenComment: () => void; onCloseComment: () => void; - onUpdateHotspot: () => Promise; + onUpdateHotspot: (statusUpdate?: boolean) => Promise; securityCategories: T.StandardSecurityCategories; } @@ -128,7 +128,7 @@ export function HotspotViewerRenderer(props: HotspotViewerRendererProps) {
- + props.onUpdateHotspot(true)} />
diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx index 022a4764aef..1839e8b419d 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx @@ -51,13 +51,26 @@ it('should render correctly', async () => { expect(getSecurityHotspotDetails).toHaveBeenCalledWith(newHotspotKey); }); -it('should refresh hotspot on update', () => { +it('should refresh hotspot list on status update', () => { const onUpdateHotspot = jest.fn(); const wrapper = shallowRender({ onUpdateHotspot }); - wrapper.find(HotspotViewerRenderer).simulate('updateHotspot'); + wrapper + .find(HotspotViewerRenderer) + .props() + .onUpdateHotspot(true); expect(onUpdateHotspot).toHaveBeenCalled(); }); +it('should NOT refresh hotspot list on assignee/comment updates', () => { + const onUpdateHotspot = jest.fn(); + const wrapper = shallowRender({ onUpdateHotspot }); + wrapper + .find(HotspotViewerRenderer) + .props() + .onUpdateHotspot(); + expect(onUpdateHotspot).not.toHaveBeenCalled(); +}); + it('should open comment form when scroll to comment', () => { const wrapper = shallowRender(); const mockTextRef = ({ current: { focus: jest.fn() } } as any) as React.RefObject< diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewerRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewerRenderer-test.tsx.snap index bc39771668f..957c63b84ac 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewerRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewerRenderer-test.tsx.snap @@ -296,7 +296,7 @@ exports[`should render correctly 1`] = ` ], } } - onStatusChange={[MockFunction]} + onStatusChange={[Function]} /> @@ -941,7 +941,7 @@ exports[`should render correctly: anonymous user 1`] = ` ], } } - onStatusChange={[MockFunction]} + onStatusChange={[Function]} /> @@ -1586,7 +1586,7 @@ exports[`should render correctly: assignee without name 1`] = ` ], } } - onStatusChange={[MockFunction]} + onStatusChange={[Function]} /> @@ -2231,7 +2231,7 @@ exports[`should render correctly: deleted assignee 1`] = ` ], } } - onStatusChange={[MockFunction]} + onStatusChange={[Function]} /> @@ -2883,7 +2883,7 @@ exports[`should render correctly: unassigned 1`] = ` ], } } - onStatusChange={[MockFunction]} + onStatusChange={[Function]} /> -- 2.39.5