diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2019-05-13 15:27:11 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-05-22 20:21:15 +0200 |
commit | 582503f4b16b06b08f043f70f6972e9d3d93610d (patch) | |
tree | 7802646b9cd314f6fdc6316d7fa3a069b723f22b /server/sonar-web | |
parent | cb3d8324f859cf5733646616e1e20efbd07ffebb (diff) | |
download | sonarqube-582503f4b16b06b08f043f70f6972e9d3d93610d.tar.gz sonarqube-582503f4b16b06b08f043f70f6972e9d3d93610d.zip |
SONAR-12026 Update transition names and description for Vulnerability coming from a hotspot
Diffstat (limited to 'server/sonar-web')
6 files changed, 100 insertions, 20 deletions
diff --git a/server/sonar-web/src/main/js/components/issue/components/IssueTransition.tsx b/server/sonar-web/src/main/js/components/issue/components/IssueTransition.tsx index f464ccab2ce..cc4bba9c6b8 100644 --- a/server/sonar-web/src/main/js/components/issue/components/IssueTransition.tsx +++ b/server/sonar-web/src/main/js/components/issue/components/IssueTransition.tsx @@ -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" diff --git a/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueTransition-test.tsx b/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueTransition-test.tsx index 74d1f133129..3324d049d70 100644 --- a/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueTransition-test.tsx +++ b/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueTransition-test.tsx @@ -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(); diff --git a/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueTransition-test.tsx.snap b/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueTransition-test.tsx.snap index f5decbbd71b..e17d30f0a59 100644 --- a/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueTransition-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueTransition-test.tsx.snap @@ -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" /> } > diff --git a/server/sonar-web/src/main/js/components/issue/popups/SetTransitionPopup.tsx b/server/sonar-web/src/main/js/components/issue/popups/SetTransitionPopup.tsx index 28e3b37478b..d6e1dc388c8 100644 --- a/server/sonar-web/src/main/js/components/issue/popups/SetTransitionPopup.tsx +++ b/server/sonar-web/src/main/js/components/issue/popups/SetTransitionPopup.tsx @@ -20,25 +20,26 @@ 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') + ]; +} diff --git a/server/sonar-web/src/main/js/components/issue/popups/__tests__/SetTransitionPopup-test.tsx b/server/sonar-web/src/main/js/components/issue/popups/__tests__/SetTransitionPopup-test.tsx index bb6bc6b72fb..dc197d693e4 100644 --- a/server/sonar-web/src/main/js/components/issue/popups/__tests__/SetTransitionPopup-test.tsx +++ b/server/sonar-web/src/main/js/components/issue/popups/__tests__/SetTransitionPopup-test.tsx @@ -19,14 +19,36 @@ */ 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(); -}); +} diff --git a/server/sonar-web/src/main/js/components/issue/popups/__tests__/__snapshots__/SetTransitionPopup-test.tsx.snap b/server/sonar-web/src/main/js/components/issue/popups/__tests__/__snapshots__/SetTransitionPopup-test.tsx.snap index a9728b1687a..915afea770c 100644 --- a/server/sonar-web/src/main/js/components/issue/popups/__tests__/__snapshots__/SetTransitionPopup-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/issue/popups/__tests__/__snapshots__/SetTransitionPopup-test.tsx.snap @@ -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> +`; |