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