Commit b7281a27 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '209790-improve-vulnerability-modal-s-test-coverage' into 'master'

Resolve "Improve vulnerability modal's test coverage"

Closes #209790

See merge request gitlab-org/gitlab!27852
parents 661afad0 e5c70871
...@@ -191,15 +191,15 @@ export default { ...@@ -191,15 +191,15 @@ export default {
:is-dismissing-vulnerability="isDismissingVulnerability" :is-dismissing-vulnerability="isDismissingVulnerability"
:is-creating-merge-request="isCreatingMergeRequest" :is-creating-merge-request="isCreatingMergeRequest"
@addDismissalComment="addDismissalComment({ vulnerability, comment: $event })" @addDismissalComment="addDismissalComment({ vulnerability, comment: $event })"
@editVulnerabilityDismissalComment="openDismissalCommentBox()" @editVulnerabilityDismissalComment="openDismissalCommentBox"
@showDismissalDeleteButtons="showDismissalDeleteButtons" @showDismissalDeleteButtons="showDismissalDeleteButtons"
@hideDismissalDeleteButtons="hideDismissalDeleteButtons" @hideDismissalDeleteButtons="hideDismissalDeleteButtons"
@deleteDismissalComment="deleteDismissalComment({ vulnerability })" @deleteDismissalComment="deleteDismissalComment({ vulnerability })"
@closeDismissalCommentBox="closeDismissalCommentBox()" @closeDismissalCommentBox="closeDismissalCommentBox"
@createMergeRequest="createMergeRequest({ vulnerability })" @createMergeRequest="createMergeRequest({ vulnerability })"
@createNewIssue="createIssue({ vulnerability })" @createNewIssue="createIssue({ vulnerability })"
@dismissVulnerability="dismissVulnerability({ vulnerability, comment: $event })" @dismissVulnerability="dismissVulnerability({ vulnerability, comment: $event })"
@openDismissalCommentBox="openDismissalCommentBox()" @openDismissalCommentBox="openDismissalCommentBox"
@revertDismissVulnerability="undoDismiss({ vulnerability })" @revertDismissVulnerability="undoDismiss({ vulnerability })"
@downloadPatch="downloadPatch({ vulnerability })" @downloadPatch="downloadPatch({ vulnerability })"
/> />
......
...@@ -4,6 +4,7 @@ import { TEST_HOST } from 'helpers/test_constants'; ...@@ -4,6 +4,7 @@ import { TEST_HOST } from 'helpers/test_constants';
import SecurityDashboard from 'ee/security_dashboard/components/security_dashboard_vuex.vue'; import SecurityDashboard from 'ee/security_dashboard/components/security_dashboard_vuex.vue';
import Filters from 'ee/security_dashboard/components/filters.vue'; import Filters from 'ee/security_dashboard/components/filters.vue';
import IssueModal from 'ee/vue_shared/security_reports/components/modal.vue';
import SecurityDashboardTable from 'ee/security_dashboard/components/security_dashboard_table.vue'; import SecurityDashboardTable from 'ee/security_dashboard/components/security_dashboard_table.vue';
import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue'; import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue';
import VulnerabilityChart from 'ee/security_dashboard/components/vulnerability_chart.vue'; import VulnerabilityChart from 'ee/security_dashboard/components/vulnerability_chart.vue';
...@@ -20,6 +21,7 @@ const vulnerabilitiesEndpoint = `${TEST_HOST}/vulnerabilities`; ...@@ -20,6 +21,7 @@ const vulnerabilitiesEndpoint = `${TEST_HOST}/vulnerabilities`;
const vulnerabilitiesCountEndpoint = `${TEST_HOST}/vulnerabilities_summary`; const vulnerabilitiesCountEndpoint = `${TEST_HOST}/vulnerabilities_summary`;
const vulnerabilitiesHistoryEndpoint = `${TEST_HOST}/vulnerabilities_history`; const vulnerabilitiesHistoryEndpoint = `${TEST_HOST}/vulnerabilities_history`;
const vulnerableProjectsEndpoint = `${TEST_HOST}/vulnerable_projects`; const vulnerableProjectsEndpoint = `${TEST_HOST}/vulnerable_projects`;
const vulnerabilityFeedbackHelpPath = `${TEST_HOST}/vulnerabilities_feedback_help`;
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
getParameterValues: jest.fn().mockReturnValue([]), getParameterValues: jest.fn().mockReturnValue([]),
...@@ -32,14 +34,7 @@ describe('Security Dashboard component', () => { ...@@ -32,14 +34,7 @@ describe('Security Dashboard component', () => {
let setPipelineIdSpy; let setPipelineIdSpy;
let store; let store;
const setup = () => {
mock = new MockAdapter(axios);
lockFilterSpy = jest.fn();
setPipelineIdSpy = jest.fn();
};
const createComponent = props => { const createComponent = props => {
store = createStore();
wrapper = shallowMount(SecurityDashboard, { wrapper = shallowMount(SecurityDashboard, {
store, store,
stubs: { stubs: {
...@@ -56,20 +51,28 @@ describe('Security Dashboard component', () => { ...@@ -56,20 +51,28 @@ describe('Security Dashboard component', () => {
vulnerabilitiesHistoryEndpoint, vulnerabilitiesHistoryEndpoint,
vulnerableProjectsEndpoint, vulnerableProjectsEndpoint,
pipelineId, pipelineId,
vulnerabilityFeedbackHelpPath: `${TEST_HOST}/vulnerabilities_feedback_help`, vulnerabilityFeedbackHelpPath,
...props, ...props,
}, },
}); });
}; };
beforeEach(() => {
mock = new MockAdapter(axios);
lockFilterSpy = jest.fn();
setPipelineIdSpy = jest.fn();
store = createStore();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
mock.restore(); mock.restore();
jest.clearAllMocks();
}); });
describe('default', () => { describe('default', () => {
beforeEach(() => { beforeEach(() => {
setup();
createComponent(); createComponent();
}); });
...@@ -112,6 +115,67 @@ describe('Security Dashboard component', () => { ...@@ -112,6 +115,67 @@ describe('Security Dashboard component', () => {
expect(wrapper.emitted('vulnerabilitiesCountChanged')).toEqual([[newCount]]); expect(wrapper.emitted('vulnerabilitiesCountChanged')).toEqual([[newCount]]);
}); });
}); });
it('renders the issue modal', () => {
expect(wrapper.contains(IssueModal)).toBe(true);
});
it('passes the "vulnerabilityFeedbackHelpPath" prop to the issue modal', () => {
expect(wrapper.find(IssueModal).props('vulnerabilityFeedbackHelpPath')).toBe(
vulnerabilityFeedbackHelpPath,
);
});
it.each`
emittedModalEvent | eventPayload | expectedDispatchedAction | expectedActionPayload
${'addDismissalComment'} | ${'foo'} | ${'vulnerabilities/addDismissalComment'} | ${{ comment: 'foo', vulnerability: 'bar' }}
${'editVulnerabilityDismissalComment'} | ${undefined} | ${'vulnerabilities/openDismissalCommentBox'} | ${undefined}
${'showDismissalDeleteButtons'} | ${undefined} | ${'vulnerabilities/showDismissalDeleteButtons'} | ${undefined}
${'hideDismissalDeleteButtons'} | ${undefined} | ${'vulnerabilities/hideDismissalDeleteButtons'} | ${undefined}
${'deleteDismissalComment'} | ${undefined} | ${'vulnerabilities/deleteDismissalComment'} | ${{ vulnerability: 'bar' }}
${'closeDismissalCommentBox'} | ${undefined} | ${'vulnerabilities/closeDismissalCommentBox'} | ${undefined}
${'createMergeRequest'} | ${undefined} | ${'vulnerabilities/createMergeRequest'} | ${{ vulnerability: 'bar' }}
${'createNewIssue'} | ${undefined} | ${'vulnerabilities/createIssue'} | ${{ vulnerability: 'bar' }}
${'dismissVulnerability'} | ${'bar'} | ${'vulnerabilities/dismissVulnerability'} | ${{ comment: 'bar', vulnerability: 'bar' }}
${'openDismissalCommentBox'} | ${undefined} | ${'vulnerabilities/openDismissalCommentBox'} | ${undefined}
${'revertDismissVulnerability'} | ${undefined} | ${'vulnerabilities/undoDismiss'} | ${{ vulnerability: 'bar' }}
${'downloadPatch'} | ${undefined} | ${'vulnerabilities/downloadPatch'} | ${{ vulnerability: 'bar' }}
`(
'dispatches the "$expectedDispatchedAction" action when the modal emits a "$emittedModalEvent" event',
({ emittedModalEvent, eventPayload, expectedDispatchedAction, expectedActionPayload }) => {
wrapper.vm.$store.state.vulnerabilities.modal.vulnerability = 'bar';
jest.spyOn(store, 'dispatch').mockImplementation();
wrapper.find(IssueModal).vm.$emit(emittedModalEvent, eventPayload);
expect(store.dispatch).toHaveBeenCalledWith(
expectedDispatchedAction,
expectedActionPayload,
);
},
);
});
describe('issue modal', () => {
it.each`
givenState | expectedProps
${{ modal: { vulnerability: 'foo' } }} | ${{ modal: { vulnerability: 'foo' }, vulnerabilityFeedbackHelpPath, canCreateIssue: false, canCreateMergeRequest: false, canDismissVulnerability: false, isCreatingIssue: false, isDismissingVulnerability: false, isCreatingMergeRequest: false }}
${{ modal: { vulnerability: { create_vulnerability_feedback_issue_path: 'foo' } } }} | ${expect.objectContaining({ canCreateIssue: true })}
${{ modal: { vulnerability: { create_vulnerability_feedback_merge_request_path: 'foo' } } }} | ${expect.objectContaining({ canCreateMergeRequest: true })}
${{ modal: { vulnerability: { create_vulnerability_feedback_dismissal_path: 'foo' } } }} | ${expect.objectContaining({ canDismissVulnerability: true })}
${{ isCreatingIssue: true }} | ${expect.objectContaining({ isCreatingIssue: true })}
${{ isDismissingVulnerability: true }} | ${expect.objectContaining({ isDismissingVulnerability: true })}
${{ isCreatingMergeRequest: true }} | ${expect.objectContaining({ isCreatingMergeRequest: true })}
`(
'passes right props to issue modal with state $givenState',
({ givenState, expectedProps }) => {
Object.assign(store.state.vulnerabilities, givenState);
createComponent();
expect(wrapper.find(IssueModal).props()).toStrictEqual(expectedProps);
},
);
}); });
describe('with project lock', () => { describe('with project lock', () => {
...@@ -119,7 +183,6 @@ describe('Security Dashboard component', () => { ...@@ -119,7 +183,6 @@ describe('Security Dashboard component', () => {
id: 123, id: 123,
}; };
beforeEach(() => { beforeEach(() => {
setup();
createComponent({ createComponent({
lockToProject: project, lockToProject: project,
}); });
...@@ -148,7 +211,6 @@ describe('Security Dashboard component', () => { ...@@ -148,7 +211,6 @@ describe('Security Dashboard component', () => {
${'vulnerableProjectsEndpoint'} | ${VulnerabilitySeverity} ${'vulnerableProjectsEndpoint'} | ${VulnerabilitySeverity}
`('with an empty $endpointProp', ({ endpointProp, Component }) => { `('with an empty $endpointProp', ({ endpointProp, Component }) => {
beforeEach(() => { beforeEach(() => {
setup();
createComponent({ createComponent({
[endpointProp]: '', [endpointProp]: '',
}); });
...@@ -160,10 +222,6 @@ describe('Security Dashboard component', () => { ...@@ -160,10 +222,6 @@ describe('Security Dashboard component', () => {
}); });
describe('dismissed vulnerabilities', () => { describe('dismissed vulnerabilities', () => {
beforeEach(() => {
setup();
});
it.each` it.each`
description | getParameterValuesReturnValue | expected description | getParameterValuesReturnValue | expected
${'hides dismissed vulnerabilities by default'} | ${[]} | ${true} ${'hides dismissed vulnerabilities by default'} | ${[]} | ${true}
...@@ -178,7 +236,6 @@ describe('Security Dashboard component', () => { ...@@ -178,7 +236,6 @@ describe('Security Dashboard component', () => {
describe('on error', () => { describe('on error', () => {
beforeEach(() => { beforeEach(() => {
setup();
createComponent(); createComponent();
}); });
......
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