Commit 6403ff05 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'improvement-outdated-security-report' into 'master'

Show security report out-of-date message for Active MRs

See merge request gitlab-org/gitlab!23575
parents 1e035fd9 514dffeb
......@@ -3,6 +3,7 @@ import { __ } from '~/locale';
export const mrStates = {
merged: 'merged',
closed: 'closed',
open: 'open',
};
export const humanMRStates = {
......
---
title: Show security report outdated message for only Active MRs
merge_request: 23575
author:
type: other
......@@ -319,6 +319,7 @@ export default {
:can-create-merge-request="mr.canCreateMergeRequest"
:can-dismiss-vulnerability="mr.canDismissVulnerability"
:diverged-commits-count="mr.divergedCommitsCount"
:mr-state="mr.state"
/>
<mr-widget-licenses
v-if="shouldRenderLicenseReport"
......
......@@ -10,6 +10,7 @@ import IssueModal from './components/modal.vue';
import securityReportsMixin from './mixins/security_report_mixin';
import createStore from './store';
import { s__, sprintf } from '~/locale';
import { mrStates } from '~/mr_popover/constants';
export default {
store: createStore(),
......@@ -118,6 +119,11 @@ export default {
required: false,
default: 0,
},
mrState: {
type: String,
required: false,
default: null,
},
},
componentNames,
computed: {
......@@ -174,6 +180,9 @@ export default {
s__('Security report is out of date. Retry the pipeline for the target branch.'),
);
},
isMRActive() {
return this.mrState !== mrStates.merged && this.mrState !== mrStates.closed;
},
},
created() {
......@@ -285,7 +294,11 @@ export default {
</a>
</div>
<div v-if="isBaseSecurityReportOutOfDate" slot="subHeading" class="text-secondary-700 text-1">
<div
v-if="isMRActive && isBaseSecurityReportOutOfDate"
slot="subHeading"
class="text-secondary-700 text-1"
>
<span>{{ subHeadingText }}</span>
</div>
......
......@@ -9,6 +9,7 @@ import { mount } from '@vue/test-utils';
import { waitForMutation } from 'helpers/vue_test_utils_helper';
import { trimText } from 'helpers/text_helper';
import axios from '~/lib/utils/axios_utils';
import { mrStates } from '~/mr_popover/constants';
import {
sastDiffSuccessMock,
......@@ -334,28 +335,17 @@ describe('Grouped security reports app', () => {
'DAST detected 1 new, and 2 fixed vulnerabilities',
);
});
it('should display out of date message', () => {
expect(wrapper.vm.$el.textContent).toContain(
'Security report is out of date. Retry the pipeline for the target branch',
);
});
});
describe('sast reports', () => {
beforeEach(() => {
gl.mrWidgetData = gl.mrWidgetData || {};
gl.mrWidgetData.sast_comparison_path = SAST_DIFF_ENDPOINT;
gl.mrWidgetData.diverged_commits_count = 100;
mock
.onGet(SAST_DIFF_ENDPOINT)
.reply(200, { ...sastDiffSuccessMock, base_report_out_of_date: true });
mock.onGet(SAST_DIFF_ENDPOINT).reply(200, { ...sastDiffSuccessMock });
createWrapper({
...props,
divergedCommitsCount: 1,
targetBranch: 'master',
enabledReports: {
sast: true,
},
......@@ -373,11 +363,73 @@ describe('Grouped security reports app', () => {
'SAST detected 1 new, and 2 fixed vulnerabilities',
);
});
});
describe('Out of date report', () => {
const createComponent = (extraProp, done) => {
gl.mrWidgetData = gl.mrWidgetData || {};
gl.mrWidgetData.sast_comparison_path = SAST_DIFF_ENDPOINT;
mock
.onGet(SAST_DIFF_ENDPOINT)
.reply(200, { ...sastDiffSuccessMock, base_report_out_of_date: true });
createWrapper({
...props,
...extraProp,
targetBranch: 'master',
enabledReports: {
sast: true,
},
});
it('should display out of date message for Outdated MR ', () => {
waitForMutation(wrapper.vm.$store, `sast/${sastTypes.RECEIVE_DIFF_SUCCESS}`)
.then(done)
.catch(done.fail);
};
describe('with active MR', () => {
beforeEach(done => {
createComponent({ mrState: mrStates.open }, done);
});
it('should display out of date message', () => {
expect(wrapper.vm.$el.textContent).toContain(
'Security report is out of date. Retry the pipeline for the target branch',
);
});
});
describe('with active MR and diverged commit', () => {
beforeEach(done => {
createComponent({ mrState: mrStates.open, divergedCommitsCount: 1 }, done);
});
it('should display out of date message', () => {
expect(wrapper.vm.$el.textContent).toContain(
'Security report is out of date. Please incorporate latest changes from master',
);
});
});
describe('with closed MR', () => {
beforeEach(done => {
createComponent({ mrState: mrStates.closed }, done);
});
it('should not display out of date message', () => {
expect(wrapper.vm.$el.textContent).not.toContain('Security report is out of date.');
});
});
describe('with merged MR', () => {
beforeEach(done => {
createComponent({ mrState: mrStates.merged }, done);
});
it('should not display out of date message', () => {
expect(wrapper.vm.$el.textContent).not.toContain('Security report is out of date.');
});
});
});
});
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