]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12334 Fix issue
authorJeremy Davis <jeremy.davis@sonarsource.com>
Tue, 13 Aug 2019 13:16:57 +0000 (15:16 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 21 Aug 2019 18:21:04 +0000 (20:21 +0200)
server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx
server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/__snapshots__/ComponentSourceSnippetViewer-test.tsx.snap
server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/utils-test.ts
server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/utils.ts

index 334a1edfe1b206f1e2979f1b670e6d01c822a6d2..0f5f5ecbaf3213a6887c8fd1a08270631d73a217 100644 (file)
@@ -65,7 +65,11 @@ it('should render correctly with secondary locations', () => {
     ],
     ...mockSnippetsByComponent('a', [...range(3, 15), 32, 33, 34, 35, 36, 52, 53, 54, 55, 56])
   };
-  expect(shallowRender({ issue, snippetGroup })).toMatchSnapshot();
+  const wrapper = shallowRender({ issue, snippetGroup });
+  expect(wrapper.state('snippets')).toHaveLength(3);
+  expect(wrapper.state('snippets')[0]).toEqual({ index: 0, start: 3, end: 14 });
+  expect(wrapper.state('snippets')[1]).toEqual({ index: 1, start: 32, end: 36 });
+  expect(wrapper.state('snippets')[2]).toEqual({ index: 2, start: 52, end: 56 });
 });
 
 it('should expand block', async () => {
index ba353d16b39e4ad0ced143610d1b1456c564cb7c..136d07a4e9e1c24be2f1d38b1f2ee2dff5bc1158 100644 (file)
@@ -34,610 +34,3 @@ exports[`should render correctly 1`] = `
   />
 </div>
 `;
-
-exports[`should render correctly with secondary locations 1`] = `
-<div
-  className="component-source-container"
->
-  <SourceViewerHeaderSlim
-    branchLike={
-      Object {
-        "analysisDate": "2018-01-01",
-        "isMain": true,
-        "name": "master",
-      }
-    }
-    expandable={true}
-    loading={false}
-    onExpand={[Function]}
-    sourceViewerFile={
-      Object {
-        "key": "a",
-        "measures": Object {
-          "coverage": "85.2",
-          "duplicationDensity": "1.0",
-          "issues": "12",
-          "lines": "56",
-        },
-        "path": "a",
-        "project": "my-project",
-        "projectName": "MyProject",
-        "q": "FIL",
-        "uuid": "foo-bar",
-      }
-    }
-  />
-  <div
-    id="snippet-wrapper-0"
-    key="0"
-  >
-    <SnippetViewer
-      branchLike={
-        Object {
-          "analysisDate": "2018-01-01",
-          "isMain": true,
-          "name": "master",
-        }
-      }
-      component={
-        Object {
-          "key": "a",
-          "measures": Object {
-            "coverage": "85.2",
-            "duplicationDensity": "1.0",
-            "issues": "12",
-            "lines": "56",
-          },
-          "path": "a",
-          "project": "my-project",
-          "projectName": "MyProject",
-          "q": "FIL",
-          "uuid": "foo-bar",
-        }
-      }
-      expandBlock={[Function]}
-      handleCloseIssues={[Function]}
-      handleLinePopupToggle={[Function]}
-      handleOpenIssues={[Function]}
-      handleSymbolClick={[Function]}
-      highlightedLocationMessage={
-        Object {
-          "index": 0,
-          "text": "",
-        }
-      }
-      highlightedSymbols={Array []}
-      index={0}
-      issue={
-        Object {
-          "actions": Array [],
-          "component": "main.js",
-          "componentLongName": "main.js",
-          "componentQualifier": "FIL",
-          "componentUuid": "foo1234",
-          "creationDate": "2017-03-01T09:36:01+0100",
-          "flows": Array [],
-          "fromHotspot": false,
-          "key": "AVsae-CQS-9G3txfbFN2",
-          "line": 25,
-          "message": "Reduce the number of conditional operators (4) used in the expression",
-          "organization": "myorg",
-          "project": "myproject",
-          "projectKey": "foo",
-          "projectName": "Foo",
-          "projectOrganization": "org",
-          "rule": "javascript:S1067",
-          "ruleName": "foo",
-          "secondaryLocations": 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,
-                "startOffset": 1,
-              },
-            },
-          ],
-          "severity": "MAJOR",
-          "status": "OPEN",
-          "textRange": Object {
-            "endLine": 5,
-            "endOffset": 10,
-            "startLine": 5,
-            "startOffset": 5,
-          },
-          "transitions": Array [],
-          "type": "BUG",
-        }
-      }
-      issuesByLine={Object {}}
-      last={false}
-      loadDuplications={[Function]}
-      locations={Array []}
-      locationsByLine={Object {}}
-      onIssueChange={[MockFunction]}
-      onIssuePopupToggle={[MockFunction]}
-      onLocationSelect={[MockFunction]}
-      openIssuesByLine={Object {}}
-      renderDuplicationPopup={[Function]}
-      scroll={[MockFunction]}
-      snippet={
-        Array [
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 3,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 4,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 5,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 6,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 7,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 8,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 9,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 10,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 11,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 12,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 13,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 14,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-        ]
-      }
-    />
-  </div>
-  <div
-    id="snippet-wrapper-1"
-    key="1"
-  >
-    <SnippetViewer
-      branchLike={
-        Object {
-          "analysisDate": "2018-01-01",
-          "isMain": true,
-          "name": "master",
-        }
-      }
-      component={
-        Object {
-          "key": "a",
-          "measures": Object {
-            "coverage": "85.2",
-            "duplicationDensity": "1.0",
-            "issues": "12",
-            "lines": "56",
-          },
-          "path": "a",
-          "project": "my-project",
-          "projectName": "MyProject",
-          "q": "FIL",
-          "uuid": "foo-bar",
-        }
-      }
-      expandBlock={[Function]}
-      handleCloseIssues={[Function]}
-      handleLinePopupToggle={[Function]}
-      handleOpenIssues={[Function]}
-      handleSymbolClick={[Function]}
-      highlightedLocationMessage={
-        Object {
-          "index": 0,
-          "text": "",
-        }
-      }
-      highlightedSymbols={Array []}
-      index={1}
-      issue={
-        Object {
-          "actions": Array [],
-          "component": "main.js",
-          "componentLongName": "main.js",
-          "componentQualifier": "FIL",
-          "componentUuid": "foo1234",
-          "creationDate": "2017-03-01T09:36:01+0100",
-          "flows": Array [],
-          "fromHotspot": false,
-          "key": "AVsae-CQS-9G3txfbFN2",
-          "line": 25,
-          "message": "Reduce the number of conditional operators (4) used in the expression",
-          "organization": "myorg",
-          "project": "myproject",
-          "projectKey": "foo",
-          "projectName": "Foo",
-          "projectOrganization": "org",
-          "rule": "javascript:S1067",
-          "ruleName": "foo",
-          "secondaryLocations": 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,
-                "startOffset": 1,
-              },
-            },
-          ],
-          "severity": "MAJOR",
-          "status": "OPEN",
-          "textRange": Object {
-            "endLine": 5,
-            "endOffset": 10,
-            "startLine": 5,
-            "startOffset": 5,
-          },
-          "transitions": Array [],
-          "type": "BUG",
-        }
-      }
-      issuesByLine={Object {}}
-      last={false}
-      loadDuplications={[Function]}
-      locations={Array []}
-      locationsByLine={Object {}}
-      onIssueChange={[MockFunction]}
-      onIssuePopupToggle={[MockFunction]}
-      onLocationSelect={[MockFunction]}
-      openIssuesByLine={Object {}}
-      renderDuplicationPopup={[Function]}
-      scroll={[MockFunction]}
-      snippet={
-        Array [
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 32,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 33,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 34,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 35,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 36,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-        ]
-      }
-    />
-  </div>
-  <div
-    id="snippet-wrapper-2"
-    key="2"
-  >
-    <SnippetViewer
-      branchLike={
-        Object {
-          "analysisDate": "2018-01-01",
-          "isMain": true,
-          "name": "master",
-        }
-      }
-      component={
-        Object {
-          "key": "a",
-          "measures": Object {
-            "coverage": "85.2",
-            "duplicationDensity": "1.0",
-            "issues": "12",
-            "lines": "56",
-          },
-          "path": "a",
-          "project": "my-project",
-          "projectName": "MyProject",
-          "q": "FIL",
-          "uuid": "foo-bar",
-        }
-      }
-      expandBlock={[Function]}
-      handleCloseIssues={[Function]}
-      handleLinePopupToggle={[Function]}
-      handleOpenIssues={[Function]}
-      handleSymbolClick={[Function]}
-      highlightedLocationMessage={
-        Object {
-          "index": 0,
-          "text": "",
-        }
-      }
-      highlightedSymbols={Array []}
-      index={2}
-      issue={
-        Object {
-          "actions": Array [],
-          "component": "main.js",
-          "componentLongName": "main.js",
-          "componentQualifier": "FIL",
-          "componentUuid": "foo1234",
-          "creationDate": "2017-03-01T09:36:01+0100",
-          "flows": Array [],
-          "fromHotspot": false,
-          "key": "AVsae-CQS-9G3txfbFN2",
-          "line": 25,
-          "message": "Reduce the number of conditional operators (4) used in the expression",
-          "organization": "myorg",
-          "project": "myproject",
-          "projectKey": "foo",
-          "projectName": "Foo",
-          "projectOrganization": "org",
-          "rule": "javascript:S1067",
-          "ruleName": "foo",
-          "secondaryLocations": 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,
-                "startOffset": 1,
-              },
-            },
-          ],
-          "severity": "MAJOR",
-          "status": "OPEN",
-          "textRange": Object {
-            "endLine": 5,
-            "endOffset": 10,
-            "startLine": 5,
-            "startOffset": 5,
-          },
-          "transitions": Array [],
-          "type": "BUG",
-        }
-      }
-      issuesByLine={Object {}}
-      last={false}
-      loadDuplications={[Function]}
-      locations={Array []}
-      locationsByLine={Object {}}
-      onIssueChange={[MockFunction]}
-      onIssuePopupToggle={[MockFunction]}
-      onLocationSelect={[MockFunction]}
-      openIssuesByLine={Object {}}
-      renderDuplicationPopup={[Function]}
-      scroll={[MockFunction]}
-      snippet={
-        Array [
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 52,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 53,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 54,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 55,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-          Object {
-            "code": "<span class=\\"k\\">import</span> java.util.<span class=\\"sym-9 sym\\">ArrayList</span>;",
-            "coverageStatus": "covered",
-            "coveredConditions": 2,
-            "duplicated": false,
-            "isNew": true,
-            "line": 56,
-            "scmAuthor": "simon.brandhof@sonarsource.com",
-            "scmDate": "2018-12-11T10:48:39+0100",
-            "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
-          },
-        ]
-      }
-    />
-  </div>
-</div>
-`;
index a682cf767d2b5fb3dd69ab12c120d943e2821e48..f33a99bccbf16c04f7fe48ac4d08f69213144785 100644 (file)
@@ -160,6 +160,23 @@ describe('createSnippets', () => {
     expect(results).toHaveLength(3);
     expect(results[0]).toEqual({ index: 0, start: 3, end: 14 });
   });
+
+  it('should handle last component', () => {
+    const results = createSnippets(
+      [
+        mockFlowLocation({
+          textRange: { startLine: 16, startOffset: 10, endLine: 16, endOffset: 14 }
+        }),
+        mockFlowLocation({
+          textRange: { startLine: 19, startOffset: 2, endLine: 19, endOffset: 3 }
+        })
+      ],
+      true
+    );
+
+    expect(results).toHaveLength(1);
+    expect(results[0]).toEqual({ index: 0, start: 14, end: 28 });
+  });
 });
 
 describe('expandSnippet', () => {
index fb31d71156390d5a59224b2aa4c75155faae890c..b8938650d5fd6b26d0c1f7363ac098ba5920ded9 100644 (file)
@@ -66,7 +66,9 @@ export function createSnippets(
       const startIndex = Math.max(1, loc.textRange.startLine - LINES_ABOVE);
       const endIndex =
         loc.textRange.endLine +
-        (issue || (last && index === locations.length - 1) ? LINES_BELOW_LAST : LINES_BELOW);
+        ((issue && index === 0) || (last && index === locations.length - 1)
+          ? LINES_BELOW_LAST
+          : LINES_BELOW);
 
       let firstCollision: { start: number; end: number } | undefined;