From: Wouter Admiraal Date: Tue, 6 Apr 2021 11:47:10 +0000 (+0200) Subject: SONAR-13141 Standard code view for issues with secondary locations on same line X-Git-Tag: 8.9.0.43852~133 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=11c51cfe36bba19ec77f976ecfcf1ed4b5d41dbe;p=sonarqube.git SONAR-13141 Standard code view for issues with secondary locations on same line --- diff --git a/server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.tsx b/server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.tsx index adc21921eff..6654a069a87 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.tsx +++ b/server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.tsx @@ -89,7 +89,11 @@ export default class IssuesSourceViewer extends React.PureComponent { ? selectedLocation && { index: selectedLocationIndex, text: selectedLocation.msg } : undefined; - if (locations.length > 0) { + const startLines = locations.map(l => l.textRange.startLine); + const showCrossComponentSourceViewer = + startLines.length > 0 ? Math.max(...startLines) !== Math.min(...startLines) : false; + + if (showCrossComponentSourceViewer) { return (
(this.node = node)}> { - expect(shallowRender()).toMatchSnapshot(); + expect(shallowRender()).toMatchSnapshot('default'); + expect( + shallowRender({ + issues: [mockIssue(true)], + openIssue: mockIssue(true, { flows: [[mockFlowLocation()]] }) + }) + ).toMatchSnapshot('single secondary location'); + expect( + shallowRender({ + issues: [mockIssue(true)], + openIssue: mockIssue(true, { + flows: [[mockFlowLocation(), mockFlowLocation(), mockFlowLocation()]] + }) + }) + ).toMatchSnapshot('all secondary locations on same line'); }); it('should render CrossComponentSourceViewer correctly', () => { expect( - shallowRender({ issues: [mockIssue(true)], openIssue: mockIssue(true) }) + shallowRender({ + issues: [mockIssue(true)], + openIssue: mockIssue(true, { + flows: [ + [ + mockFlowLocation(), + mockFlowLocation({ + textRange: { + startLine: 10, + startOffset: 1, + endLine: 12, + endOffset: 2 + } + }) + ] + ] + }) + }) ).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/issues/components/__tests__/__snapshots__/IssuesSourceViewer-test.tsx.snap b/server/sonar-web/src/main/js/apps/issues/components/__tests__/__snapshots__/IssuesSourceViewer-test.tsx.snap index fe59402ddfe..2604418e147 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/__tests__/__snapshots__/IssuesSourceViewer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/issues/components/__tests__/__snapshots__/IssuesSourceViewer-test.tsx.snap @@ -35,39 +35,9 @@ exports[`should render CrossComponentSourceViewer correctly 1`] = ` "component": "main.js", "index": 1, "textRange": Object { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - Object { - "component": "main.js", - "index": 2, - "textRange": Object { - "endLine": 2, + "endLine": 12, "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - Array [ - Object { - "component": "main.js", - "textRange": Object { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - Object { - "component": "main.js", - "textRange": Object { - "endLine": 2, - "endOffset": 2, - "startLine": 1, + "startLine": 10, "startOffset": 1, }, }, @@ -217,6 +187,55 @@ exports[`should render CrossComponentSourceViewer correctly 1`] = ` ] } locations={ + Array [ + Object { + "component": "main.js", + "index": 0, + "textRange": Object { + "endLine": 2, + "endOffset": 2, + "startLine": 1, + "startOffset": 1, + }, + }, + Object { + "component": "main.js", + "index": 1, + "textRange": Object { + "endLine": 12, + "endOffset": 2, + "startLine": 10, + "startOffset": 1, + }, + }, + ] + } + onIssueChange={[MockFunction]} + onLoaded={[Function]} + onLocationSelect={[MockFunction]} + scroll={[Function]} + /> +
+`; + +exports[`should render SourceViewer correctly: all secondary locations on same line 1`] = ` +
+
`; -exports[`should render SourceViewer correctly 1`] = ` +exports[`should render SourceViewer correctly: default 1`] = `
`; + +exports[`should render SourceViewer correctly: single secondary location 1`] = ` +
+ +
+`;