]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13185 Remove hardcoded 'source' and 'sink'
authorJeremy Davis <jeremy.davis@sonarsource.com>
Thu, 12 Mar 2020 13:31:59 +0000 (14:31 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 19 Mar 2020 20:03:53 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigator.tsx
server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigatorLocation.tsx
server/sonar-web/src/main/js/apps/issues/conciseIssuesList/CrossFileLocationsNavigator.tsx
server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/ConciseIssueLocationsNavigatorLocation-test.tsx
server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/CrossFileLocationsNavigator-test.tsx
server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/ConciseIssueLocationsNavigator-test.tsx.snap
server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/ConciseIssueLocationsNavigatorLocation-test.tsx.snap
server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/__snapshots__/CrossFileLocationsNavigator-test.tsx.snap

index 1b5c62eb2e9cbd1a47b5c2907f8898db870443ec..f19ce0f77316eedffb550739aa12e33a60996804 100644 (file)
@@ -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 (
         <CrossFileLocationsNavigator
-          isTaintAnalysis={isTaintAnalysis}
           issue={this.props.issue}
           locations={locations}
           onLocationSelect={this.props.onLocationSelect}
@@ -65,13 +61,11 @@ export default class ConciseIssueLocationsNavigator extends React.PureComponent<
           {locations.map((location, index) => (
             <ConciseIssueLocationsNavigatorLocation
               index={index}
-              isTaintAnalysis={isTaintAnalysis}
               key={index}
               message={location.msg}
               onClick={this.props.onLocationSelect}
               scroll={this.props.scroll}
               selected={index === this.props.selectedLocationIndex}
-              totalCount={locations.length}
             />
           ))}
         </div>
index d83b66e9e7d25760e8d988c39a9b3c6b6767232c..4d8f7da36aaae9405009cd607963812c00cc11df 100644 (file)
@@ -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<Props> {
@@ -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 (
       <div className="little-spacer-top" ref={node => (this.node = node)}>
@@ -72,9 +59,7 @@ export default class ConciseIssueLocationsNavigatorLocation extends React.PureCo
           href="#"
           onClick={this.handleClick}>
           <LocationIndex selected={selected}>{index + 1}</LocationIndex>
-          <LocationMessage selected={selected}>
-            {isTaintAnalysis ? this.prefixMessage(index, message, totalCount) : message}
-          </LocationMessage>
+          <LocationMessage selected={selected}>{message}</LocationMessage>
         </a>
       </div>
     );
index 1e4b043b15577858b6c9ccc025f2850508cd0b02..5e21ddc08ae6ff76029b07b9eecb1a15df8db826 100644 (file)
@@ -23,7 +23,6 @@ import { collapsePath } from 'sonar-ui-common/helpers/path';
 import ConciseIssueLocationsNavigatorLocation from './ConciseIssueLocationsNavigatorLocation';
 
 interface Props {
-  isTaintAnalysis: boolean;
   issue: Pick<T.Issue, 'key' | 'type'>;
   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<Props, State> {
   state: State = { collapsed: true };
 
@@ -112,13 +113,11 @@ export default class CrossFileLocationsNavigator extends React.PureComponent<Pro
     return (
       <ConciseIssueLocationsNavigatorLocation
         index={index}
-        isTaintAnalysis={this.props.isTaintAnalysis}
         key={index}
         message={message}
         onClick={this.props.onLocationSelect}
         scroll={this.props.scroll}
         selected={index === this.props.selectedLocationIndex}
-        totalCount={this.props.locations.length}
       />
     );
   };
@@ -134,7 +133,7 @@ export default class CrossFileLocationsNavigator extends React.PureComponent<Pro
       <div className="concise-issue-locations-navigator-file" key={groupIndex}>
         <div className="concise-issue-location-file">
           <i className="concise-issue-location-file-circle little-spacer-right" />
-          {collapsePath(group.componentName || '', 15)}
+          {collapsePath(group.componentName || '', MAX_PATH_LENGTH)}
         </div>
         {group.locations.length > 0 && (
           <div className="concise-issue-location-file-locations">
index 8ea8d7ee1c2e25674d9e9f830ae2d0233217c0ec..0717fa84fe071fdbec12771b1c55b7acfef7646b 100644 (file)
@@ -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<ConciseIssueLocationsNavigatorLocation['props']> = {}) => {
+function shallowRender(props: Partial<ConciseIssueLocationsNavigatorLocation['props']> = {}) {
   return shallow(
     <ConciseIssueLocationsNavigatorLocation
       index={0}
-      isTaintAnalysis={false}
       message=""
       onClick={jest.fn()}
       scroll={jest.fn()}
       selected={true}
-      totalCount={5}
       {...props}
     />
   );
-};
+}
index eaf14a97b8cdc530eab8ac6c0929fc794c5304f5..a3cadc60f35bb5b76f14bac0d8ca925d48c04c3c 100644 (file)
@@ -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(
-    <CrossFileLocationsNavigator
-      isTaintAnalysis={false}
-      issue={{ key: 'abcd', type: 'BUG' }}
-      locations={[location1, location2, location3]}
-      onLocationSelect={jest.fn()}
-      scroll={jest.fn()}
-      selectedLocationIndex={undefined}
-    />
-  );
+  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(
-    <CrossFileLocationsNavigator
-      isTaintAnalysis={false}
-      issue={{ key: 'abcd', type: 'BUG' }}
-      locations={[location1, location2]}
-      onLocationSelect={jest.fn()}
-      scroll={jest.fn()}
-      selectedLocationIndex={undefined}
-    />
-  );
+  const wrapper = shallowRender({ locations: [location1, location2] });
+
   expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(2);
 });
 
 it('should expand all locations', () => {
-  const wrapper = shallow(
-    <CrossFileLocationsNavigator
-      isTaintAnalysis={false}
-      issue={{ key: 'abcd', type: 'BUG' }}
-      locations={[location1, location2, location3]}
-      onLocationSelect={jest.fn()}
-      scroll={jest.fn()}
-      selectedLocationIndex={undefined}
-    />
-  );
+  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<CrossFileLocationsNavigator['props']> = {}) {
+  return shallow<CrossFileLocationsNavigator>(
     <CrossFileLocationsNavigator
-      isTaintAnalysis={false}
       issue={{ key: 'abcd', type: 'BUG' }}
       locations={[location1, location2, location3]}
       onLocationSelect={jest.fn()}
       scroll={jest.fn()}
       selectedLocationIndex={undefined}
+      {...props}
     />
   );
-  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);
-});
+}
index 4e2b7044f5d46ca8c83fe3396eb7a2bb57bab211..d90ab99081782e8ddd6280f6930ef5820e70bcc6 100644 (file)
@@ -2,7 +2,6 @@
 
 exports[`should render flow locations in different file 1`] = `
 <CrossFileLocationsNavigator
-  isTaintAnalysis={false}
   issue={
     Object {
       "actions": Array [],
@@ -98,23 +97,19 @@ exports[`should render flow locations in the same file 1`] = `
 >
   <ConciseIssueLocationsNavigatorLocation
     index={0}
-    isTaintAnalysis={false}
     key="0"
     message="Do not use foo"
     onClick={[MockFunction]}
     scroll={[MockFunction]}
     selected={false}
-    totalCount={2}
   />
   <ConciseIssueLocationsNavigatorLocation
     index={1}
-    isTaintAnalysis={false}
     key="1"
     message="Do not use foo"
     onClick={[MockFunction]}
     scroll={[MockFunction]}
     selected={false}
-    totalCount={2}
   />
 </div>
 `;
@@ -125,23 +120,19 @@ exports[`should render secondary locations in the same file 1`] = `
 >
   <ConciseIssueLocationsNavigatorLocation
     index={0}
-    isTaintAnalysis={false}
     key="0"
     message="Do not use foo"
     onClick={[MockFunction]}
     scroll={[MockFunction]}
     selected={false}
-    totalCount={2}
   />
   <ConciseIssueLocationsNavigatorLocation
     index={1}
-    isTaintAnalysis={false}
     key="1"
     message="Do not use foo"
     onClick={[MockFunction]}
     scroll={[MockFunction]}
     selected={false}
-    totalCount={2}
   />
 </div>
 `;
@@ -152,30 +143,25 @@ exports[`should render selected flow locations in the same file 1`] = `
 >
   <ConciseIssueLocationsNavigatorLocation
     index={0}
-    isTaintAnalysis={false}
     key="0"
     message="Do not use foo"
     onClick={[MockFunction]}
     scroll={[MockFunction]}
     selected={false}
-    totalCount={2}
   />
   <ConciseIssueLocationsNavigatorLocation
     index={1}
-    isTaintAnalysis={false}
     key="1"
     message="Do not use foo"
     onClick={[MockFunction]}
     scroll={[MockFunction]}
     selected={false}
-    totalCount={2}
   />
 </div>
 `;
 
 exports[`should render taint analysis issues correctly 1`] = `
 <CrossFileLocationsNavigator
-  isTaintAnalysis={true}
   issue={
     Object {
       "actions": Array [],
index 9ca42296767d5f3fa0bd3491f6d3b9267b806502..a609334626a346ba762c08fb9597988e1afa882a 100644 (file)
@@ -1,6 +1,6 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
-exports[`should render correctly 1`] = `
+exports[`should render correctly: index 1 1`] = `
 <div
   className="little-spacer-top"
 >
@@ -21,30 +21,7 @@ exports[`should render correctly 1`] = `
 </div>
 `;
 
-exports[`should render vulnerabilities correctly 1`] = `
-<div
-  className="little-spacer-top"
->
-  <a
-    className="concise-issue-locations-navigator-location"
-    href="#"
-    onClick={[Function]}
-  >
-    <LocationIndex
-      selected={true}
-    >
-      1
-    </LocationIndex>
-    <LocationMessage
-      selected={true}
-    >
-      source: 
-    </LocationMessage>
-  </a>
-</div>
-`;
-
-exports[`should render vulnerabilities correctly 2`] = `
+exports[`should render correctly: index 2 1`] = `
 <div
   className="little-spacer-top"
 >
@@ -64,26 +41,3 @@ exports[`should render vulnerabilities correctly 2`] = `
   </a>
 </div>
 `;
-
-exports[`should render vulnerabilities correctly 3`] = `
-<div
-  className="little-spacer-top"
->
-  <a
-    className="concise-issue-locations-navigator-location"
-    href="#"
-    onClick={[Function]}
-  >
-    <LocationIndex
-      selected={true}
-    >
-      4
-    </LocationIndex>
-    <LocationMessage
-      selected={true}
-    >
-      sink: 
-    </LocationMessage>
-  </a>
-</div>
-`;
index 5485b0d6e37c07abde96942ab1be2356e94f771a..fd78ea74a5c5617f31c02971fe5e392dd0646aaa 100644 (file)
@@ -21,13 +21,11 @@ exports[`should render 1`] = `
     >
       <ConciseIssueLocationsNavigatorLocation
         index={0}
-        isTaintAnalysis={false}
         key="0"
         message="Do not use foo"
         onClick={[MockFunction]}
         scroll={[MockFunction]}
         selected={false}
-        totalCount={3}
       />
     </div>
   </div>
@@ -66,15 +64,49 @@ exports[`should render 1`] = `
     >
       <ConciseIssueLocationsNavigatorLocation
         index={2}
-        isTaintAnalysis={false}
         key="2"
         message="Do not use bar"
         onClick={[MockFunction]}
         scroll={[MockFunction]}
         selected={false}
-        totalCount={3}
       />
     </div>
   </div>
 </div>
 `;
+
+exports[`should render locations with no component name 1`] = `
+<div
+  className="concise-issue-locations-navigator spacer-top"
+>
+  <div
+    className="concise-issue-locations-navigator-file"
+    key="0"
+  >
+    <div
+      className="concise-issue-location-file"
+    >
+      <i
+        className="concise-issue-location-file-circle little-spacer-right"
+      />
+    </div>
+    <div
+      className="concise-issue-location-file-locations"
+    >
+      <ConciseIssueLocationsNavigatorLocation
+        index={0}
+        key="0"
+        onClick={[MockFunction]}
+        scroll={[MockFunction]}
+        selected={false}
+      />
+    </div>
+  </div>
+</div>
+`;
+
+exports[`should render with no locations 1`] = `
+<div
+  className="concise-issue-locations-navigator spacer-top"
+/>
+`;