--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+import { shallow } from 'enzyme';
+import * as React from 'react';
+import { mockBranch } from '../../../helpers/mocks/branch-like';
+import { mockIssue, mockSourceLine } from '../../../helpers/testMocks';
+import { MetricKey } from '../../../types/metrics';
+import Line from '../components/Line';
+import SourceViewerCode from '../SourceViewerCode';
+
+it('should render correctly', () => {
+ expect(shallowRender()).toMatchSnapshot('default');
+ expect(shallowRender({ issues: [mockIssue(false, { textRange: undefined })] })).toMatchSnapshot(
+ 'has file level issues'
+ );
+ expect(shallowRender({ hasSourcesAfter: true, hasSourcesBefore: true })).toMatchSnapshot(
+ 'has more sources'
+ );
+});
+
+it('should correctly flag a line for scrolling', () => {
+ const sources = [
+ mockSourceLine({ line: 1, coverageStatus: 'covered', isNew: false }),
+ mockSourceLine({ line: 2, coverageStatus: 'partially-covered', isNew: false }),
+ mockSourceLine({ line: 3, coverageStatus: 'uncovered', isNew: true })
+ ];
+ let wrapper = shallowRender({ sources, metricKey: MetricKey.uncovered_lines });
+
+ expect(
+ wrapper
+ .find(Line)
+ .at(1)
+ .props().scrollToUncoveredLine
+ ).toBe(true);
+ expect(
+ wrapper
+ .find(Line)
+ .at(2)
+ .props().scrollToUncoveredLine
+ ).toBe(false);
+
+ wrapper = shallowRender({
+ sources,
+ metricKey: MetricKey.new_uncovered_lines
+ });
+
+ expect(
+ wrapper
+ .find(Line)
+ .at(1)
+ .props().scrollToUncoveredLine
+ ).toBe(false);
+ expect(
+ wrapper
+ .find(Line)
+ .at(2)
+ .props().scrollToUncoveredLine
+ ).toBe(true);
+});
+
+function shallowRender(props: Partial<SourceViewerCode['props']> = {}) {
+ return shallow<SourceViewerCode>(
+ <SourceViewerCode
+ branchLike={mockBranch()}
+ componentKey="foo"
+ duplications={[]}
+ duplicationsByLine={[]}
+ hasSourcesAfter={false}
+ hasSourcesBefore={false}
+ highlightedLine={undefined}
+ highlightedLocationMessage={undefined}
+ highlightedLocations={undefined}
+ highlightedSymbols={[]}
+ issueLocationsByLine={{}}
+ issuePopup={undefined}
+ issues={[mockIssue(), mockIssue()]}
+ issuesByLine={{}}
+ loadDuplications={jest.fn()}
+ loadingSourcesAfter={false}
+ loadingSourcesBefore={false}
+ loadSourcesAfter={jest.fn()}
+ loadSourcesBefore={jest.fn()}
+ onIssueChange={jest.fn()}
+ onIssuePopupToggle={jest.fn()}
+ onIssuesClose={jest.fn()}
+ onIssueSelect={jest.fn()}
+ onIssuesOpen={jest.fn()}
+ onIssueUnselect={jest.fn()}
+ onLocationSelect={jest.fn()}
+ onSymbolClick={jest.fn()}
+ openIssuesByLine={{}}
+ renderDuplicationPopup={jest.fn()}
+ selectedIssue={undefined}
+ sources={[mockSourceLine(), mockSourceLine(), mockSourceLine()]}
+ symbolsByLine={{}}
+ {...props}
+ />
+ );
+}
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly: default 1`] = `
+<div
+ className="source-viewer-code"
+>
+ <table
+ className="source-table"
+ >
+ <tbody>
+ <Line
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
+ displayCoverage={true}
+ displayDuplications={false}
+ displayIssues={true}
+ duplications={Array []}
+ duplicationsCount={0}
+ highlighted={false}
+ issueLocations={Array []}
+ issues={Array []}
+ key="16"
+ last={false}
+ line={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ loadDuplications={[MockFunction]}
+ onIssueChange={[MockFunction]}
+ onIssuePopupToggle={[MockFunction]}
+ onIssueSelect={[MockFunction]}
+ onIssueUnselect={[MockFunction]}
+ onIssuesClose={[MockFunction]}
+ onIssuesOpen={[MockFunction]}
+ onLocationSelect={[MockFunction]}
+ onSymbolClick={[MockFunction]}
+ openIssues={false}
+ renderDuplicationPopup={[MockFunction]}
+ scrollToUncoveredLine={false}
+ secondaryIssueLocations={Array []}
+ />
+ <Line
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
+ displayCoverage={true}
+ displayDuplications={false}
+ displayIssues={true}
+ duplications={Array []}
+ duplicationsCount={0}
+ highlighted={false}
+ issueLocations={Array []}
+ issues={Array []}
+ key="16"
+ last={false}
+ line={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ loadDuplications={[MockFunction]}
+ onIssueChange={[MockFunction]}
+ onIssuePopupToggle={[MockFunction]}
+ onIssueSelect={[MockFunction]}
+ onIssueUnselect={[MockFunction]}
+ onIssuesClose={[MockFunction]}
+ onIssuesOpen={[MockFunction]}
+ onLocationSelect={[MockFunction]}
+ onSymbolClick={[MockFunction]}
+ openIssues={false}
+ previousLine={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ renderDuplicationPopup={[MockFunction]}
+ scrollToUncoveredLine={false}
+ secondaryIssueLocations={Array []}
+ />
+ <Line
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
+ displayCoverage={true}
+ displayDuplications={false}
+ displayIssues={true}
+ duplications={Array []}
+ duplicationsCount={0}
+ highlighted={false}
+ issueLocations={Array []}
+ issues={Array []}
+ key="16"
+ last={true}
+ line={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ loadDuplications={[MockFunction]}
+ onIssueChange={[MockFunction]}
+ onIssuePopupToggle={[MockFunction]}
+ onIssueSelect={[MockFunction]}
+ onIssueUnselect={[MockFunction]}
+ onIssuesClose={[MockFunction]}
+ onIssuesOpen={[MockFunction]}
+ onLocationSelect={[MockFunction]}
+ onSymbolClick={[MockFunction]}
+ openIssues={false}
+ previousLine={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ renderDuplicationPopup={[MockFunction]}
+ scrollToUncoveredLine={false}
+ secondaryIssueLocations={Array []}
+ />
+ </tbody>
+ </table>
+</div>
+`;
+
+exports[`should render correctly: has file level issues 1`] = `
+<div
+ className="source-viewer-code"
+>
+ <table
+ className="source-table"
+ >
+ <tbody>
+ <Line
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
+ displayCoverage={true}
+ displayDuplications={false}
+ displayIssues={true}
+ duplications={Array []}
+ duplicationsCount={0}
+ highlighted={false}
+ issueLocations={Array []}
+ issues={Array []}
+ key="0"
+ last={false}
+ line={
+ Object {
+ "code": "",
+ "duplicated": false,
+ "isNew": false,
+ "line": 0,
+ }
+ }
+ loadDuplications={[MockFunction]}
+ onIssueChange={[MockFunction]}
+ onIssuePopupToggle={[MockFunction]}
+ onIssueSelect={[MockFunction]}
+ onIssueUnselect={[MockFunction]}
+ onIssuesClose={[MockFunction]}
+ onIssuesOpen={[MockFunction]}
+ onLocationSelect={[MockFunction]}
+ onSymbolClick={[MockFunction]}
+ openIssues={false}
+ renderDuplicationPopup={[MockFunction]}
+ scrollToUncoveredLine={false}
+ secondaryIssueLocations={Array []}
+ />
+ <Line
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
+ displayCoverage={true}
+ displayDuplications={false}
+ displayIssues={true}
+ duplications={Array []}
+ duplicationsCount={0}
+ highlighted={false}
+ issueLocations={Array []}
+ issues={Array []}
+ key="16"
+ last={false}
+ line={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ loadDuplications={[MockFunction]}
+ onIssueChange={[MockFunction]}
+ onIssuePopupToggle={[MockFunction]}
+ onIssueSelect={[MockFunction]}
+ onIssueUnselect={[MockFunction]}
+ onIssuesClose={[MockFunction]}
+ onIssuesOpen={[MockFunction]}
+ onLocationSelect={[MockFunction]}
+ onSymbolClick={[MockFunction]}
+ openIssues={false}
+ renderDuplicationPopup={[MockFunction]}
+ scrollToUncoveredLine={false}
+ secondaryIssueLocations={Array []}
+ />
+ <Line
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
+ displayCoverage={true}
+ displayDuplications={false}
+ displayIssues={true}
+ duplications={Array []}
+ duplicationsCount={0}
+ highlighted={false}
+ issueLocations={Array []}
+ issues={Array []}
+ key="16"
+ last={false}
+ line={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ loadDuplications={[MockFunction]}
+ onIssueChange={[MockFunction]}
+ onIssuePopupToggle={[MockFunction]}
+ onIssueSelect={[MockFunction]}
+ onIssueUnselect={[MockFunction]}
+ onIssuesClose={[MockFunction]}
+ onIssuesOpen={[MockFunction]}
+ onLocationSelect={[MockFunction]}
+ onSymbolClick={[MockFunction]}
+ openIssues={false}
+ previousLine={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ renderDuplicationPopup={[MockFunction]}
+ scrollToUncoveredLine={false}
+ secondaryIssueLocations={Array []}
+ />
+ <Line
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
+ displayCoverage={true}
+ displayDuplications={false}
+ displayIssues={true}
+ duplications={Array []}
+ duplicationsCount={0}
+ highlighted={false}
+ issueLocations={Array []}
+ issues={Array []}
+ key="16"
+ last={true}
+ line={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ loadDuplications={[MockFunction]}
+ onIssueChange={[MockFunction]}
+ onIssuePopupToggle={[MockFunction]}
+ onIssueSelect={[MockFunction]}
+ onIssueUnselect={[MockFunction]}
+ onIssuesClose={[MockFunction]}
+ onIssuesOpen={[MockFunction]}
+ onLocationSelect={[MockFunction]}
+ onSymbolClick={[MockFunction]}
+ openIssues={false}
+ previousLine={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ renderDuplicationPopup={[MockFunction]}
+ scrollToUncoveredLine={false}
+ secondaryIssueLocations={Array []}
+ />
+ </tbody>
+ </table>
+</div>
+`;
+
+exports[`should render correctly: has more sources 1`] = `
+<div
+ className="source-viewer-code"
+>
+ <div
+ className="source-viewer-more-code"
+ >
+ <Button
+ className="js-component-viewer-source-before"
+ onClick={[MockFunction]}
+ >
+ source_viewer.load_more_code
+ </Button>
+ </div>
+ <table
+ className="source-table"
+ >
+ <tbody>
+ <Line
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
+ displayCoverage={true}
+ displayDuplications={false}
+ displayIssues={true}
+ duplications={Array []}
+ duplicationsCount={0}
+ highlighted={false}
+ issueLocations={Array []}
+ issues={Array []}
+ key="16"
+ last={false}
+ line={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ loadDuplications={[MockFunction]}
+ onIssueChange={[MockFunction]}
+ onIssuePopupToggle={[MockFunction]}
+ onIssueSelect={[MockFunction]}
+ onIssueUnselect={[MockFunction]}
+ onIssuesClose={[MockFunction]}
+ onIssuesOpen={[MockFunction]}
+ onLocationSelect={[MockFunction]}
+ onSymbolClick={[MockFunction]}
+ openIssues={false}
+ renderDuplicationPopup={[MockFunction]}
+ scrollToUncoveredLine={false}
+ secondaryIssueLocations={Array []}
+ />
+ <Line
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
+ displayCoverage={true}
+ displayDuplications={false}
+ displayIssues={true}
+ duplications={Array []}
+ duplicationsCount={0}
+ highlighted={false}
+ issueLocations={Array []}
+ issues={Array []}
+ key="16"
+ last={false}
+ line={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ loadDuplications={[MockFunction]}
+ onIssueChange={[MockFunction]}
+ onIssuePopupToggle={[MockFunction]}
+ onIssueSelect={[MockFunction]}
+ onIssueUnselect={[MockFunction]}
+ onIssuesClose={[MockFunction]}
+ onIssuesOpen={[MockFunction]}
+ onLocationSelect={[MockFunction]}
+ onSymbolClick={[MockFunction]}
+ openIssues={false}
+ previousLine={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ renderDuplicationPopup={[MockFunction]}
+ scrollToUncoveredLine={false}
+ secondaryIssueLocations={Array []}
+ />
+ <Line
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
+ displayCoverage={true}
+ displayDuplications={false}
+ displayIssues={true}
+ duplications={Array []}
+ duplicationsCount={0}
+ highlighted={false}
+ issueLocations={Array []}
+ issues={Array []}
+ key="16"
+ last={false}
+ line={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ loadDuplications={[MockFunction]}
+ onIssueChange={[MockFunction]}
+ onIssuePopupToggle={[MockFunction]}
+ onIssueSelect={[MockFunction]}
+ onIssueUnselect={[MockFunction]}
+ onIssuesClose={[MockFunction]}
+ onIssuesOpen={[MockFunction]}
+ onLocationSelect={[MockFunction]}
+ onSymbolClick={[MockFunction]}
+ openIssues={false}
+ previousLine={
+ 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": 16,
+ "scmAuthor": "simon.brandhof@sonarsource.com",
+ "scmDate": "2018-12-11T10:48:39+0100",
+ "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0",
+ }
+ }
+ renderDuplicationPopup={[MockFunction]}
+ scrollToUncoveredLine={false}
+ secondaryIssueLocations={Array []}
+ />
+ </tbody>
+ </table>
+ <div
+ className="source-viewer-more-code"
+ >
+ <Button
+ className="js-component-viewer-source-after"
+ onClick={[MockFunction]}
+ >
+ source_viewer.load_more_code
+ </Button>
+ </div>
+</div>
+`;