]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12026 Update transition names and description for Vulnerability coming from...
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 13 May 2019 13:27:11 +0000 (15:27 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 22 May 2019 18:21:15 +0000 (20:21 +0200)
server/sonar-web/src/main/js/components/issue/components/IssueTransition.tsx
server/sonar-web/src/main/js/components/issue/components/__tests__/IssueTransition-test.tsx
server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueTransition-test.tsx.snap
server/sonar-web/src/main/js/components/issue/popups/SetTransitionPopup.tsx
server/sonar-web/src/main/js/components/issue/popups/__tests__/SetTransitionPopup-test.tsx
server/sonar-web/src/main/js/components/issue/popups/__tests__/__snapshots__/SetTransitionPopup-test.tsx.snap
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index f464ccab2ceffc6af879afe4a0132ca953894ccc..cc4bba9c6b82367ac84a6747ccef52713830d80b 100644 (file)
@@ -29,7 +29,7 @@ import { updateIssue } from '../actions';
 interface Props {
   hasTransitions: boolean;
   isOpen: boolean;
-  issue: Pick<T.Issue, 'key' | 'resolution' | 'status' | 'transitions'>;
+  issue: Pick<T.Issue, 'fromHotspot' | 'key' | 'resolution' | 'status' | 'transitions' | 'type'>;
   onChange: (issue: T.Issue) => void;
   togglePopup: (popup: string, show?: boolean) => void;
 }
@@ -61,7 +61,12 @@ export default class IssueTransition extends React.PureComponent<Props> {
             onRequestClose={this.handleClose}
             open={this.props.isOpen && this.props.hasTransitions}
             overlay={
-              <SetTransitionPopup onSelect={this.setTransition} transitions={issue.transitions} />
+              <SetTransitionPopup
+                fromHotspot={issue.fromHotspot}
+                onSelect={this.setTransition}
+                transitions={issue.transitions}
+                type={issue.type}
+              />
             }>
             <ButtonLink
               className="issue-action issue-action-with-options js-issue-transition"
index 74d1f1331291e0ec9a143eb915ff39a25c32d1b6..3324d049d7079ecde91515d5f84060325b2bafab 100644 (file)
@@ -22,17 +22,19 @@ import { shallow } from 'enzyme';
 import IssueTransition from '../IssueTransition';
 import { click } from '../../../../helpers/testUtils';
 
-const issue = {
+const issue: IssueTransition['props']['issue'] = {
+  fromHotspot: false,
   key: 'foo1234',
   transitions: ['confirm', 'resolve', 'falsepositive', 'wontfix'],
-  status: 'OPEN'
+  status: 'OPEN',
+  type: 'BUG'
 };
 
 it('should render without the action when there is no transitions', () => {
   expect(
     shallowRender({
       hasTransitions: false,
-      issue: { key: 'foo1234', transitions: [], status: 'CLOSED' }
+      issue: { fromHotspot: false, key: 'foo1234', transitions: [], status: 'CLOSED', type: 'BUG' }
     })
   ).toMatchSnapshot();
 });
@@ -45,10 +47,12 @@ it('should render with a resolution', () => {
   expect(
     shallowRender({
       issue: {
+        fromHotspot: false,
         key: 'foo1234',
         transitions: ['reopen'],
         status: 'RESOLVED',
-        resolution: 'FIXED'
+        resolution: 'FIXED',
+        type: 'BUG'
       }
     })
   ).toMatchSnapshot();
index f5decbbd71b1e00b4d0faf0bd636c5a6827f4633..e17d30f0a596f421e2b472a3cbeb26147db6df40 100644 (file)
@@ -18,6 +18,7 @@ exports[`should open the popup when the button is clicked 2`] = `
     open={true}
     overlay={
       <SetTransitionPopup
+        fromHotspot={false}
         onSelect={[Function]}
         transitions={
           Array [
@@ -27,6 +28,7 @@ exports[`should open the popup when the button is clicked 2`] = `
             "wontfix",
           ]
         }
+        type="BUG"
       />
     }
   >
@@ -55,12 +57,14 @@ exports[`should render with a resolution 1`] = `
     open={false}
     overlay={
       <SetTransitionPopup
+        fromHotspot={false}
         onSelect={[Function]}
         transitions={
           Array [
             "reopen",
           ]
         }
+        type="BUG"
       />
     }
   >
@@ -90,6 +94,7 @@ exports[`should render with the action 1`] = `
     open={false}
     overlay={
       <SetTransitionPopup
+        fromHotspot={false}
         onSelect={[Function]}
         transitions={
           Array [
@@ -99,6 +104,7 @@ exports[`should render with the action 1`] = `
             "wontfix",
           ]
         }
+        type="BUG"
       />
     }
   >
index 28e3b37478be2938a740d22dcf51408c922d9fa8..d6e1dc388c8dccbe7460173fa57578ea7fc89bca 100644 (file)
 import * as React from 'react';
 import SelectList from '../../common/SelectList';
 import SelectListItem from '../../common/SelectListItem';
-import { translate } from '../../../helpers/l10n';
+import { translate, hasMessage } from '../../../helpers/l10n';
 import { DropdownOverlay } from '../../controls/Dropdown';
 
-interface Props {
+export interface Props {
+  fromHotspot: boolean;
   onSelect: (transition: string) => void;
   transitions: string[];
+  type: T.IssueType;
 }
 
-export default function SetTransitionPopup({ onSelect, transitions }: Props) {
+export default function SetTransitionPopup({ fromHotspot, onSelect, transitions, type }: Props) {
+  const isManualVulnerability = fromHotspot && type === 'VULNERABILITY';
   return (
     <DropdownOverlay>
       <SelectList currentItem={transitions[0]} items={transitions} onSelect={onSelect}>
         {transitions.map(transition => {
+          const [name, description] = translateTransition(transition, isManualVulnerability);
           return (
-            <SelectListItem
-              item={transition}
-              key={transition}
-              title={translate('issue.transition', transition, 'description')}>
-              {translate('issue.transition', transition)}
+            <SelectListItem item={transition} key={transition} title={description}>
+              {name}
             </SelectListItem>
           );
         })}
@@ -46,3 +47,15 @@ export default function SetTransitionPopup({ onSelect, transitions }: Props) {
     </DropdownOverlay>
   );
 }
+
+function translateTransition(transition: string, isManualVulnerability: boolean) {
+  return isManualVulnerability && hasMessage('vulnerability.transition', transition)
+    ? [
+        translate('vulnerability.transition', transition),
+        translate('vulnerability.transition', transition, 'description')
+      ]
+    : [
+        translate('issue.transition', transition),
+        translate('issue.transition', transition, 'description')
+      ];
+}
index bb6bc6b72fb7b8dca169f801d21a2c5b929d72e7..dc197d693e4109d9911e612395130a50029aa63f 100644 (file)
  */
 import * as React from 'react';
 import { shallow } from 'enzyme';
-import SetTransitionPopup from '../SetTransitionPopup';
+import SetTransitionPopup, { Props } from '../SetTransitionPopup';
+import { hasMessage } from '../../../../helpers/l10n';
 
-it('should render tags popup correctly', () => {
-  const element = shallow(
+jest.mock('../../../../helpers/l10n', () => ({
+  ...jest.requireActual('../../../../helpers/l10n'),
+  hasMessage: jest.fn().mockReturnValue(false)
+}));
+
+it('should render transition popup correctly', () => {
+  expect(shallowRender()).toMatchSnapshot();
+});
+
+it('should render transition popup correctly for vulnerability', () => {
+  (hasMessage as jest.Mock).mockReturnValueOnce('true');
+  expect(
+    shallowRender({
+      fromHotspot: true,
+      transitions: ['resolveasreviewed', 'confirm']
+    })
+  ).toMatchSnapshot();
+});
+
+function shallowRender(props: Partial<Props> = {}) {
+  return shallow(
     <SetTransitionPopup
+      fromHotspot={false}
       onSelect={jest.fn()}
       transitions={['confirm', 'resolve', 'falsepositive', 'wontfix']}
+      type="VULNERABILITY"
+      {...props}
     />
   );
-  expect(element).toMatchSnapshot();
-});
+}
index a9728b1687a06606cce0583ac7d4471120a2f4f7..915afea770c7480a5b6f8c74d8a55f5a409650a8 100644 (file)
@@ -1,6 +1,6 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
-exports[`should render tags popup correctly 1`] = `
+exports[`should render transition popup correctly 1`] = `
 <DropdownOverlay>
   <SelectList
     currentItem="confirm"
@@ -45,3 +45,33 @@ exports[`should render tags popup correctly 1`] = `
   </SelectList>
 </DropdownOverlay>
 `;
+
+exports[`should render transition popup correctly for vulnerability 1`] = `
+<DropdownOverlay>
+  <SelectList
+    currentItem="resolveasreviewed"
+    items={
+      Array [
+        "resolveasreviewed",
+        "confirm",
+      ]
+    }
+    onSelect={[MockFunction]}
+  >
+    <SelectListItem
+      item="resolveasreviewed"
+      key="resolveasreviewed"
+      title="vulnerability.transition.resolveasreviewed.description"
+    >
+      vulnerability.transition.resolveasreviewed
+    </SelectListItem>
+    <SelectListItem
+      item="confirm"
+      key="confirm"
+      title="issue.transition.confirm.description"
+    >
+      issue.transition.confirm
+    </SelectListItem>
+  </SelectList>
+</DropdownOverlay>
+`;
index d089f70e9d4f3fc624ca4cd134a646df9755c02e..0990e9f1e5a733a72d408288f48d79ec324192f5 100644 (file)
@@ -618,14 +618,19 @@ issue.transition.close=Close
 issue.transition.close.description=
 issue.transition.wontfix=Resolve as won't fix
 issue.transition.wontfix.description=This issue can be ignored because the rule is irrelevant in this context. Its effort won't be counted.
-issue.transition.setinreview = Set as In Review
-issue.transition.setinreview.description = A review is required to check for a vulnerability
-issue.transition.resolveasreviewed = Resolve as Reviewed
-issue.transition.resolveasreviewed.description = There is no vulnerability in the code
-issue.transition.openasvulnerability = Open as Vulnerability
-issue.transition.openasvulnerability.description = There's a vulnerability in the code that must be fixed
-issue.transition.resetastoreview = Reset as security hotspot To Review
-issue.transition.resetastoreview.description = The security hotspot should be analyzed again
+issue.transition.setinreview=Set as In Review
+issue.transition.setinreview.description=A review is required to check for a Vulnerability
+issue.transition.openasvulnerability=Open as Vulnerability
+issue.transition.openasvulnerability.description=There's a Vulnerability in the code that must be fixed
+issue.transition.resolveasreviewed=Resolve as Reviewed
+issue.transition.resolveasreviewed.description=There is no Vulnerability in the code
+issue.transition.resetastoreview=Reset as To Review
+issue.transition.resetastoreview.description=The Security Hotspot should be analyzed again
+vulnerability.transition.resetastoreview=Reset as Security Hotspot To Review
+vulnerability.transition.resetastoreview.description=The Vulnerability can't be fixed as is and needs more details
+vulnerability.transition.resolveasreviewed=Resolve as Reviewed Security Hotspot
+vulnerability.transition.resolveasreviewed.description=The Vulnerability has been fixed
+
 issue.set_severity=Change Severity
 issue.set_type=Change Type