? 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
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();
});
"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,
},
},
]
}
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",
},
]
}
+ 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}
/>
</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>
+`;