diff --git a/app/views/projects/merge_requests/_nav_btns.html.haml b/app/views/projects/merge_requests/_nav_btns.html.haml index d1e3f759f745a2e1420618b6cc720b903e0b5df9..130d0c848a2523978eb196df50b15932fa251516 100644 --- a/app/views/projects/merge_requests/_nav_btns.html.haml +++ b/app/views/projects/merge_requests/_nav_btns.html.haml @@ -1,3 +1,4 @@ += render_if_exists 'projects/merge_requests/merge_trains_button' - if @can_bulk_update = render Pajamas::ButtonComponent.new(type: :submit, button_options: { class: 'gl-mr-3 js-bulk-update-toggle' }) do = _("Bulk edit") diff --git a/ee/app/views/projects/merge_requests/_merge_trains_button.html.haml b/ee/app/views/projects/merge_requests/_merge_trains_button.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..5be8815a5803b7ceb4a643c7f998f57706a61365 --- /dev/null +++ b/ee/app/views/projects/merge_requests/_merge_trains_button.html.haml @@ -0,0 +1,3 @@ +- if merge_trains_available? && can?(@current_user, :read_merge_train, @project) + = render Pajamas::ButtonComponent.new(href: project_merge_trains_path(@project)) do + = _("Merge trains") diff --git a/ee/spec/features/merge_requests/user_sees_nav_buttons_spec.rb b/ee/spec/features/merge_requests/user_sees_nav_buttons_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..1cbfb30515081c93d91455d3b0ba64e66ca7a7d4 --- /dev/null +++ b/ee/spec/features/merge_requests/user_sees_nav_buttons_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Merge request > User sees nav buttons', :js, feature_category: :code_review_workflow do + let_it_be(:project) { create(:project) } + let_it_be(:maintainer) { create(:user) } + let_it_be(:guest) { create(:user) } + let_it_be(:merge_request) { create(:merge_request, source_project: project, target_project: project) } + + before_all do + project.add_maintainer(maintainer) + project.add_guest(guest) + end + + context 'as a maintainer' do + before do + project.update!(merge_trains_enabled: true) + stub_licensed_features(merge_trains: true) + + sign_in(maintainer) + + visit project_merge_requests_path(project) + end + + it 'shows the "New merge request" link' do + expect(page).to have_link 'New merge request', href: project_new_merge_request_path(project) + end + + it 'shows the "Bulk edit" button' do + expect(page).to have_button 'Bulk edit' + end + + it 'shows the "Merge trains" link' do + expect(page).to have_link 'Merge trains', href: project_merge_trains_path(project) + end + end + + context 'as a guest' do + before do + project.update!(merge_trains_enabled: true) + stub_licensed_features(merge_trains: true) + + sign_in(guest) + + visit project_merge_requests_path(project) + end + + it 'does not show the "New merge request" link' do + expect(page).not_to have_link 'New merge request' + end + + it 'does not show the "Bulk edit" button' do + expect(page).not_to have_button 'Bulk edit' + end + + it 'does not show the "Merge trains" link' do + expect(page).not_to have_link 'Merge trains' + end + end +end diff --git a/spec/features/merge_requests/user_sees_nav_buttons_spec.rb b/spec/features/merge_requests/user_sees_nav_buttons_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..3679a2eed1d691a5e7bcbd58f9c2b5b6af284f50 --- /dev/null +++ b/spec/features/merge_requests/user_sees_nav_buttons_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Merge request > User sees nav buttons', feature_category: :code_review_workflow do + let_it_be(:project) { create(:project) } + let_it_be(:maintainer) { create(:user) } + let_it_be(:guest) { create(:user) } + let_it_be(:merge_request) { create(:merge_request, source_project: project, target_project: project) } + + before_all do + project.add_maintainer(maintainer) + project.add_guest(guest) + end + + context 'as a maintainer' do + before do + sign_in(maintainer) + + visit project_merge_requests_path(project) + end + + it 'shows the "New merge request" button' do + expect(page).to have_link 'New merge request', href: project_new_merge_request_path(project) + end + + it 'shows the "Bulk edit" button' do + expect(page).to have_button 'Bulk edit' + end + + it 'does not show the "Merge trains" button' do + expect(page).not_to have_link 'Merge trains' + end + end + + context 'as a guest' do + before do + sign_in(guest) + + visit project_merge_requests_path(project) + end + + it 'does not show the "New merge request" button' do + expect(page).not_to have_link 'New merge request' + end + + it 'does not show the "Bulk edit" button' do + expect(page).not_to have_button 'Bulk edit' + end + + it 'does not show the "Merge trains" button' do + expect(page).not_to have_link 'Merge trains' + end + end +end