From: Jeremy Davis Date: Thu, 12 Mar 2020 13:31:59 +0000 (+0100) Subject: SONAR-13185 Remove hardcoded 'source' and 'sink' X-Git-Tag: 8.3.0.34182~130 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2dbdc4f2a1bd9ee2700fcaba693977b742b47459;p=sonarqube.git SONAR-13185 Remove hardcoded 'source' and 'sink' --- diff --git a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigator.tsx b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigator.tsx index 1b5c62eb2e9..f19ce0f7731 100644 --- a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigator.tsx +++ b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigator.tsx @@ -39,9 +39,6 @@ export default class ConciseIssueLocationsNavigator extends React.PureComponent< return null; } - const isTaintAnalysis = - this.props.issue.type === 'VULNERABILITY' && this.props.issue.flows.length > 0; - const locationComponents = [ this.props.issue.component, ...locations.map(location => location.component) @@ -51,7 +48,6 @@ export default class ConciseIssueLocationsNavigator extends React.PureComponent< if (isCrossFile) { return ( ( ))} diff --git a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigatorLocation.tsx b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigatorLocation.tsx index d83b66e9e7d..4d8f7da36aa 100644 --- a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigatorLocation.tsx +++ b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigatorLocation.tsx @@ -23,12 +23,10 @@ import LocationMessage from '../../../components/common/LocationMessage'; interface Props { index: number; - isTaintAnalysis: boolean; message: string | undefined; onClick: (index: number) => void; scroll: (element: Element) => void; selected: boolean; - totalCount: number; } export default class ConciseIssueLocationsNavigatorLocation extends React.PureComponent { @@ -51,19 +49,8 @@ export default class ConciseIssueLocationsNavigatorLocation extends React.PureCo this.props.onClick(this.props.index); }; - prefixMessage(index: number, message = '', totalCount: number) { - switch (index) { - case 0: - return 'source: ' + message; - case totalCount - 1: - return 'sink: ' + message; - default: - return message; - } - } - render() { - const { index, isTaintAnalysis, message, selected, totalCount } = this.props; + const { index, message, selected } = this.props; return (
(this.node = node)}> @@ -72,9 +59,7 @@ export default class ConciseIssueLocationsNavigatorLocation extends React.PureCo href="#" onClick={this.handleClick}> {index + 1} - - {isTaintAnalysis ? this.prefixMessage(index, message, totalCount) : message} - + {message}
); diff --git a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/CrossFileLocationsNavigator.tsx b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/CrossFileLocationsNavigator.tsx index 1e4b043b155..5e21ddc08ae 100644 --- a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/CrossFileLocationsNavigator.tsx +++ b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/CrossFileLocationsNavigator.tsx @@ -23,7 +23,6 @@ import { collapsePath } from 'sonar-ui-common/helpers/path'; import ConciseIssueLocationsNavigatorLocation from './ConciseIssueLocationsNavigatorLocation'; interface Props { - isTaintAnalysis: boolean; issue: Pick; locations: T.FlowLocation[]; onLocationSelect: (index: number) => void; @@ -42,6 +41,8 @@ interface LocationGroup { locations: T.FlowLocation[]; } +const MAX_PATH_LENGTH = 15; + export default class CrossFileLocationsNavigator extends React.PureComponent { state: State = { collapsed: true }; @@ -112,13 +113,11 @@ export default class CrossFileLocationsNavigator extends React.PureComponent ); }; @@ -134,7 +133,7 @@ export default class CrossFileLocationsNavigator extends React.PureComponent
- {collapsePath(group.componentName || '', 15)} + {collapsePath(group.componentName || '', MAX_PATH_LENGTH)}
{group.locations.length > 0 && (
diff --git a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/ConciseIssueLocationsNavigatorLocation-test.tsx b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/ConciseIssueLocationsNavigatorLocation-test.tsx index 8ea8d7ee1c2..0717fa84fe0 100644 --- a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/ConciseIssueLocationsNavigatorLocation-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/ConciseIssueLocationsNavigatorLocation-test.tsx @@ -22,25 +22,19 @@ import * as React from 'react'; import ConciseIssueLocationsNavigatorLocation from '../ConciseIssueLocationsNavigatorLocation'; it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); -it('should render vulnerabilities correctly', () => { - expect(shallowRender({ index: 0, isTaintAnalysis: true, totalCount: 4 })).toMatchSnapshot(); - expect(shallowRender({ index: 1, isTaintAnalysis: true, totalCount: 4 })).toMatchSnapshot(); - expect(shallowRender({ index: 3, isTaintAnalysis: true, totalCount: 4 })).toMatchSnapshot(); + expect(shallowRender()).toMatchSnapshot('index 1'); + expect(shallowRender({ index: 1 })).toMatchSnapshot('index 2'); }); -const shallowRender = (props: Partial = {}) => { +function shallowRender(props: Partial = {}) { return shallow( ); -}; +} diff --git a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/CrossFileLocationsNavigator-test.tsx b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/CrossFileLocationsNavigator-test.tsx index eaf14a97b8c..a3cadc60f35 100644 --- a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/CrossFileLocationsNavigator-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/CrossFileLocationsNavigator-test.tsx @@ -20,6 +20,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { click } from 'sonar-ui-common/helpers/testUtils'; +import { mockFlowLocation } from '../../../../helpers/testMocks'; import CrossFileLocationsNavigator from '../CrossFileLocationsNavigator'; const location1: T.FlowLocation = { @@ -43,17 +44,17 @@ const location3: T.FlowLocation = { textRange: { startLine: 15, endLine: 16, startOffset: 4, endOffset: 6 } }; +it('should render with no locations', () => { + expect(shallowRender({ locations: [] })).toMatchSnapshot(); +}); + +it('should render locations with no component name', () => { + expect(shallowRender({ locations: [mockFlowLocation({ componentName: '' })] })).toMatchSnapshot(); +}); + it('should render', () => { - const wrapper = shallow( - - ); + const wrapper = shallowRender(); + expect(wrapper).toMatchSnapshot(); expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(2); @@ -62,30 +63,13 @@ it('should render', () => { }); it('should render all locations', () => { - const wrapper = shallow( - - ); + const wrapper = shallowRender({ locations: [location1, location2] }); + expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(2); }); it('should expand all locations', () => { - const wrapper = shallow( - - ); + const wrapper = shallowRender(); expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(2); wrapper.setProps({ selectedLocationIndex: 1 }); @@ -93,19 +77,24 @@ it('should expand all locations', () => { }); it('should collapse locations when issue changes', () => { - const wrapper = shallow( + const wrapper = shallowRender(); + + wrapper.setProps({ selectedLocationIndex: 1 }); + expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(3); + + wrapper.setProps({ issue: { key: 'def', type: 'BUG' }, selectedLocationIndex: undefined }); + expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(2); +}); + +function shallowRender(props: Partial = {}) { + return shallow( ); - wrapper.setProps({ selectedLocationIndex: 1 }); - expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(3); - - wrapper.setProps({ issue: { key: 'def' }, selectedLocationIndex: undefined }); - expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(2); -}); +} diff --git a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/ConciseIssueLocationsNavigator-test.tsx.snap b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/ConciseIssueLocationsNavigator-test.tsx.snap index 4e2b7044f5d..d90ab990817 100644 --- a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/ConciseIssueLocationsNavigator-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/ConciseIssueLocationsNavigator-test.tsx.snap @@ -2,7 +2,6 @@ exports[`should render flow locations in different file 1`] = `
`; @@ -125,23 +120,19 @@ exports[`should render secondary locations in the same file 1`] = ` > `; @@ -152,30 +143,25 @@ exports[`should render selected flow locations in the same file 1`] = ` > `; exports[`should render taint analysis issues correctly 1`] = ` @@ -21,30 +21,7 @@ exports[`should render correctly 1`] = ` `; -exports[`should render vulnerabilities correctly 1`] = ` - -`; - -exports[`should render vulnerabilities correctly 2`] = ` +exports[`should render correctly: index 2 1`] = `
@@ -64,26 +41,3 @@ exports[`should render vulnerabilities correctly 2`] = `
`; - -exports[`should render vulnerabilities correctly 3`] = ` - -`; diff --git a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/CrossFileLocationsNavigator-test.tsx.snap b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/CrossFileLocationsNavigator-test.tsx.snap index 5485b0d6e37..fd78ea74a5c 100644 --- a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/CrossFileLocationsNavigator-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/CrossFileLocationsNavigator-test.tsx.snap @@ -21,13 +21,11 @@ exports[`should render 1`] = ` > @@ -66,15 +64,49 @@ exports[`should render 1`] = ` > `; + +exports[`should render locations with no component name 1`] = ` +
+
+
+ +
+
+ +
+
+
+`; + +exports[`should render with no locations 1`] = ` +
+`;