Commit 4173d77d authored by Dave Pisek's avatar Dave Pisek

Review suggestions: Optional chain, url util

* Adds optional chaining when reaching into `this.vulnerability`
* Uses `visitUrl` helper from url utils
* Updates specs
parent c1deee21
......@@ -2,6 +2,7 @@
import { mapActions, mapState } from 'vuex';
import { GlTooltipDirective, GlButton } from '@gitlab/ui';
import { VULNERABILITY_MODAL_ID } from 'ee/vue_shared/security_reports/components/constants';
import { visitUrl } from '~/lib/utils/url_utility';
import { BV_SHOW_MODAL } from '~/lib/utils/constants';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { s__ } from '~/locale';
......@@ -49,7 +50,8 @@ export default {
...mapState('vulnerabilities', ['isCreatingIssue', 'isDismissingVulnerability']),
isJiraVulnerabilityIssuesEnabled() {
return (
this.glFeatures.jiraForVulnerabilities && Boolean(this.vulnerability.create_jira_issue_url)
this.glFeatures?.jiraForVulnerabilities &&
Boolean(this?.vulnerability?.create_jira_issue_url)
);
},
createIssueButtonLabel() {
......@@ -76,7 +78,7 @@ export default {
}
},
createNewJiraIssue({ create_jira_issue_url }) {
window.open(create_jira_issue_url, '_blank');
visitUrl(create_jira_issue_url, true);
},
handleDismissVulnerability() {
const { vulnerability } = this;
......
......@@ -6,10 +6,15 @@ import VulnerabilityActionButtons, {
} from 'ee/security_dashboard/components/vulnerability_action_buttons.vue';
import createStore from 'ee/security_dashboard/store';
import { VULNERABILITY_MODAL_ID } from 'ee/vue_shared/security_reports/components/constants';
import { visitUrl } from '~/lib/utils/url_utility';
import { BV_SHOW_MODAL } from '~/lib/utils/constants';
import { resetStore } from '../helpers';
import mockDataVulnerabilities from '../store/modules/vulnerabilities/data/mock_data_vulnerabilities';
jest.mock('~/lib/utils/url_utility', () => ({
visitUrl: jest.fn(),
}));
describe('Security Dashboard Action Buttons', () => {
let store;
let wrapper;
......@@ -110,14 +115,13 @@ describe('Security Dashboard Action Buttons', () => {
});
it('should open a new window when the create-issue button is clicked', async () => {
jest.spyOn(window, 'open').mockReturnValueOnce();
expect(visitUrl).not.toHaveBeenCalled();
expect(window.open).not.toHaveBeenCalled();
await findCreateIssueButton().trigger('click');
expect(window.open).toHaveBeenCalledWith(
expect(visitUrl).toHaveBeenCalledWith(
mockDataVulnerabilities[8].create_jira_issue_url,
'_blank',
true, // external link flag
);
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment