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 { ...@@ -151,9 +151,9 @@ export default {
return this.mr.hasCI || this.hasPipelineMustSucceedConflict; return this.mr.hasCI || this.hasPipelineMustSucceedConflict;
}, },
shouldSuggestPipelines() { shouldSuggestPipelines() {
return ( const { hasCI, mergeRequestAddCiConfigPath, isDismissedSuggestPipeline } = this.mr;
!this.mr.hasCI && this.mr.mergeRequestAddCiConfigPath && !this.mr.isDismissedSuggestPipeline
); return !hasCI && mergeRequestAddCiConfigPath && !isDismissedSuggestPipeline;
}, },
shouldRenderCodeQuality() { shouldRenderCodeQuality() {
return this.mr?.codequalityReportsPath; return this.mr?.codequalityReportsPath;
......
...@@ -83,7 +83,10 @@ class MergeRequestWidgetEntity < Grape::Entity ...@@ -83,7 +83,10 @@ class MergeRequestWidgetEntity < Grape::Entity
end end
expose :is_dismissed_suggest_pipeline do |_merge_request| 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 end
expose :human_access do |merge_request| expose :human_access do |merge_request|
......
...@@ -6,9 +6,10 @@ RSpec.describe 'Merge request > User sees suggest pipeline', :js do ...@@ -6,9 +6,10 @@ RSpec.describe 'Merge request > User sees suggest pipeline', :js do
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.source_project } let(:project) { merge_request.source_project }
let(:user) { project.creator } let(:user) { project.creator }
let(:suggest_pipeline_enabled) { true }
before do 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) project.add_maintainer(user)
sign_in(user) sign_in(user)
visit project_merge_request_path(project, merge_request) visit project_merge_request_path(project, merge_request)
...@@ -66,4 +67,12 @@ RSpec.describe 'Merge request > User sees suggest pipeline', :js do ...@@ -66,4 +67,12 @@ RSpec.describe 'Merge request > User sees suggest pipeline', :js do
# nudge 4 # nudge 4
expect(page).to have_content("That's it, well done!") expect(page).to have_content("That's it, well done!")
end 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 end
...@@ -283,28 +283,6 @@ RSpec.describe MergeRequestWidgetEntity do ...@@ -283,28 +283,6 @@ RSpec.describe MergeRequestWidgetEntity do
it 'provides a valid value for suggest pipeline feature id' do it 'provides a valid value for suggest pipeline feature id' do
expect(subject[:suggest_pipeline_feature_id]).to eq described_class::SUGGEST_PIPELINE expect(subject[:suggest_pipeline_feature_id]).to eq described_class::SUGGEST_PIPELINE
end 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 end
it 'has human access' do it 'has human access' do
...@@ -395,4 +373,46 @@ RSpec.describe MergeRequestWidgetEntity do ...@@ -395,4 +373,46 @@ RSpec.describe MergeRequestWidgetEntity do
end end
end 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 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