Commit fac9b2b2 authored by eugielimpin's avatar eugielimpin Committed by Denys Mishunov

Toggle banner using suggest_pipeline_enabled application setting

Update the logic of showing/hiding the suggest pipeline banner in MR
pages without pipeline to also check the value of
suggest_pipeline_enabled application setting.

Changelog: changed
parent 62c86853
......@@ -151,9 +151,9 @@ export default {
return this.mr.hasCI || this.hasPipelineMustSucceedConflict;
},
shouldSuggestPipelines() {
return (
!this.mr.hasCI && this.mr.mergeRequestAddCiConfigPath && !this.mr.isDismissedSuggestPipeline
);
const { hasCI, mergeRequestAddCiConfigPath, isDismissedSuggestPipeline } = this.mr;
return !hasCI && mergeRequestAddCiConfigPath && !isDismissedSuggestPipeline;
},
shouldRenderCodeQuality() {
return this.mr?.codequalityReportsPath;
......
......@@ -83,7 +83,10 @@ class MergeRequestWidgetEntity < Grape::Entity
end
expose :is_dismissed_suggest_pipeline do |_merge_request|
current_user && current_user.dismissed_callout?(feature_name: SUGGEST_PIPELINE)
next true unless current_user
next true unless Gitlab::CurrentSettings.suggest_pipeline_enabled?
current_user.dismissed_callout?(feature_name: SUGGEST_PIPELINE)
end
expose :human_access do |merge_request|
......
......@@ -6,9 +6,10 @@ RSpec.describe 'Merge request > User sees suggest pipeline', :js do
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.source_project }
let(:user) { project.creator }
let(:suggest_pipeline_enabled) { true }
before do
stub_application_setting(auto_devops_enabled: false)
stub_application_setting(suggest_pipeline_enabled: suggest_pipeline_enabled, auto_devops_enabled: false)
project.add_maintainer(user)
sign_in(user)
visit project_merge_request_path(project, merge_request)
......@@ -66,4 +67,12 @@ RSpec.describe 'Merge request > User sees suggest pipeline', :js do
# nudge 4
expect(page).to have_content("That's it, well done!")
end
context 'when feature setting is disabled' do
let(:suggest_pipeline_enabled) { false }
it 'does not show the suggest pipeline widget' do
expect(page).not_to have_content('Are you adding technical debt or code vulnerabilities?')
end
end
end
......@@ -283,28 +283,6 @@ RSpec.describe MergeRequestWidgetEntity do
it 'provides a valid value for suggest pipeline feature id' do
expect(subject[:suggest_pipeline_feature_id]).to eq described_class::SUGGEST_PIPELINE
end
it 'provides a valid value for if it is dismissed' do
expect(subject[:is_dismissed_suggest_pipeline]).to be(false)
end
context 'when the suggest pipeline has been dismissed' do
before do
create(:user_callout, user: user, feature_name: described_class::SUGGEST_PIPELINE)
end
it 'indicates suggest pipeline has been dismissed' do
expect(subject[:is_dismissed_suggest_pipeline]).to be(true)
end
end
context 'when user is not logged in' do
let(:request) { double('request', current_user: nil, project: project) }
it 'returns a blank is dismissed value' do
expect(subject[:is_dismissed_suggest_pipeline]).to be_nil
end
end
end
it 'has human access' do
......@@ -395,4 +373,46 @@ RSpec.describe MergeRequestWidgetEntity do
end
end
end
describe 'is_dismissed_suggest_pipeline' do
context 'when user is logged in' do
context 'when the suggest pipeline feature is enabled' do
before do
allow(Gitlab::CurrentSettings).to receive(:suggest_pipeline_enabled?).and_return(true)
end
it 'is false' do
expect(subject[:is_dismissed_suggest_pipeline]).to be(false)
end
context 'when suggest pipeline has been dismissed' do
before do
create(:user_callout, user: user, feature_name: described_class::SUGGEST_PIPELINE)
end
it 'is true' do
expect(subject[:is_dismissed_suggest_pipeline]).to be(true)
end
end
end
context 'when the suggest pipeline feature is disabled' do
before do
allow(Gitlab::CurrentSettings).to receive(:suggest_pipeline_enabled?).and_return(false)
end
it 'is true' do
expect(subject[:is_dismissed_suggest_pipeline]).to be(true)
end
end
end
context 'when user is not logged in' do
let(:request) { double('request', current_user: nil, project: project) }
it 'is true' do
expect(subject[:is_dismissed_suggest_pipeline]).to be(true)
end
end
end
end
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