]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13141 Standard code view for issues with secondary locations on same line
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Tue, 6 Apr 2021 11:47:10 +0000 (13:47 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 9 Apr 2021 20:03:53 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.tsx
server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesSourceViewer-test.tsx
server/sonar-web/src/main/js/apps/issues/components/__tests__/__snapshots__/IssuesSourceViewer-test.tsx.snap

index adc21921effeb7edc8c039fef86945b6309b34c2..6654a069a8756e838ecb24034fe85d10fbaa16ad 100644 (file)
@@ -89,7 +89,11 @@ export default class IssuesSourceViewer extends React.PureComponent<Props> {
         ? 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 (
         <div ref={node => (this.node = node)}>
           <CrossComponentSourceViewer
index c44d2ce236c67088b4c9f9f9b089862e0c800606..dbeb5f0b1c6a673d446d580bf9c079321f48a1a9 100644 (file)
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import { mockMainBranch } from '../../../../helpers/mocks/branch-like';
-import { mockIssue } from '../../../../helpers/testMocks';
+import { mockFlowLocation, mockIssue } from '../../../../helpers/testMocks';
 import IssuesSourceViewer from '../IssuesSourceViewer';
 
 it('should render SourceViewer correctly', () => {
-  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();
 });
 
index fe59402ddfe6cdb8e63f4e21e6b2a53f933aedca..2604418e147c2e7836b9bcbe42112f91f7509fcc 100644 (file)
@@ -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]}
+  />
+</div>
+`;
+
+exports[`should render SourceViewer correctly: all secondary locations on same line 1`] = `
+<div>
+  <SourceViewer
+    aroundLine={26}
+    branchLike={
+      Object {
+        "analysisDate": "2018-01-01",
+        "excludedFromPurge": true,
+        "isMain": true,
+        "name": "master",
+      }
+    }
+    component="main.js"
+    displayAllIssues={true}
+    displayIssueLocationsCount={true}
+    displayIssueLocationsLink={false}
+    displayLocationMarkers={false}
+    highlightedLocations={
       Array [
         Object {
           "component": "main.js",
@@ -250,15 +269,19 @@ exports[`should render CrossComponentSourceViewer correctly 1`] = `
         },
       ]
     }
+    loadIssues={[MockFunction]}
     onIssueChange={[MockFunction]}
+    onIssueSelect={[MockFunction]}
     onLoaded={[Function]}
     onLocationSelect={[MockFunction]}
     scroll={[Function]}
+    selectedIssue="AVsae-CQS-9G3txfbFN2"
+    slimHeader={true}
   />
 </div>
 `;
 
-exports[`should render SourceViewer correctly 1`] = `
+exports[`should render SourceViewer correctly: default 1`] = `
 <div>
   <SourceViewer
     aroundLine={26}
@@ -287,3 +310,46 @@ exports[`should render SourceViewer correctly 1`] = `
   />
 </div>
 `;
+
+exports[`should render SourceViewer correctly: single secondary location 1`] = `
+<div>
+  <SourceViewer
+    aroundLine={26}
+    branchLike={
+      Object {
+        "analysisDate": "2018-01-01",
+        "excludedFromPurge": true,
+        "isMain": true,
+        "name": "master",
+      }
+    }
+    component="main.js"
+    displayAllIssues={true}
+    displayIssueLocationsCount={true}
+    displayIssueLocationsLink={false}
+    displayLocationMarkers={false}
+    highlightedLocations={
+      Array [
+        Object {
+          "component": "main.js",
+          "index": 0,
+          "textRange": Object {
+            "endLine": 2,
+            "endOffset": 2,
+            "startLine": 1,
+            "startOffset": 1,
+          },
+        },
+      ]
+    }
+    loadIssues={[MockFunction]}
+    onIssueChange={[MockFunction]}
+    onIssueSelect={[MockFunction]}
+    onLoaded={[Function]}
+    onLocationSelect={[MockFunction]}
+    scroll={[Function]}
+    selectedIssue="AVsae-CQS-9G3txfbFN2"
+    slimHeader={true}
+  />
+</div>
+`;