Commit aca4050b authored by Mark Lapierre's avatar Mark Lapierre

Update E2E test of assigning code owners

A recent change removed the option to require approval from codeowners
from project settings and added it to the protected branch creation
screen.

See https://gitlab.com/gitlab-org/gitlab/merge_requests/15862

This updates the E2E test of the affected feature:

* converts the old qa class selectors to data attributes.
* removes the EE project settings module because it only contained the
  merge request approval setting, which only include the code owners
  setting and was removed with the feature change
* fixes a bug in `Resource::Repository::Commit` that caused new files
  to not be committed
* updates the test to conform with our current style
parent 65381105
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
%tr.d-none.d-sm-table-row %tr.d-none.d-sm-table-row
%th.w-25= s_('CodeOwner|Pattern') %th.w-25= s_('CodeOwner|Pattern')
%th= _('Members') %th= _('Members')
%tbody.qa-approver-list %tbody{ data: { qa_selector: "approver_list" } }
- code_owner_rules.each do |code_owner_approval_rule| - code_owner_rules.each do |code_owner_approval_rule|
%tr.qa-approver %tr{ data: { qa_selector: "approver" } }
%td.monospace= code_owner_approval_rule.name %td.monospace= code_owner_approval_rule.name
%td.d-none.d-sm-table-cell %td.d-none.d-sm-table-cell
- code_owner_approval_rule.approvers.each do |approver| - code_owner_approval_rule.approvers.each do |approver|
......
...@@ -113,7 +113,6 @@ module QA ...@@ -113,7 +113,6 @@ module QA
module Settings module Settings
autoload :ProtectedBranches, 'qa/ee/page/project/settings/protected_branches' autoload :ProtectedBranches, 'qa/ee/page/project/settings/protected_branches'
autoload :MirroringRepositories, 'qa/ee/page/project/settings/mirroring_repositories' autoload :MirroringRepositories, 'qa/ee/page/project/settings/mirroring_repositories'
autoload :Main, 'qa/ee/page/project/settings/main'
autoload :MergeRequest, 'qa/ee/page/project/settings/merge_request' autoload :MergeRequest, 'qa/ee/page/project/settings/merge_request'
autoload :Repository, 'qa/ee/page/project/settings/repository' autoload :Repository, 'qa/ee/page/project/settings/repository'
autoload :PushRules, 'qa/ee/page/project/settings/push_rules' autoload :PushRules, 'qa/ee/page/project/settings/push_rules'
......
# frozen_string_literal: true
module QA
module EE
module Page
module Project
module Settings
module Main
def self.prepended(page)
page.module_eval do
view 'ee/app/views/projects/_merge_request_approvals_settings.html.haml' do
element :merge_request_approval_settings
end
end
end
def expand_request_approval_settings(&block)
expand_section(:merge_request_approval_settings) do
MergeRequestApproval.perform(&block)
end
end
end
end
end
end
end
end
...@@ -58,5 +58,3 @@ module QA ...@@ -58,5 +58,3 @@ module QA
end end
end end
end end
QA::Page::Project::Settings::Main.prepend_if_ee('QA::EE::Page::Project::Settings::Main')
...@@ -58,8 +58,10 @@ module QA ...@@ -58,8 +58,10 @@ module QA
end end
def actions def actions
@add_files.map { |file| file.merge({ action: "create" }) } if @add_files pending_actions = []
@update_files.map { |file| file.merge({ action: "update" }) } if @update_files @add_files.map { |file| pending_actions << file.merge({ action: "create" }) } if @add_files
@update_files.map { |file| pending_actions << file.merge({ action: "update" }) } if @update_files
pending_actions
end end
private private
......
...@@ -3,66 +3,79 @@ ...@@ -3,66 +3,79 @@
module QA module QA
context 'Create' do context 'Create' do
describe 'Codeowners' do describe 'Codeowners' do
it 'merge request assigns code owners as approvers' do # Create one user to be the assigned approver and another user who will not be an approver
Runtime::Browser.visit(:gitlab, Page::Main::Login) let(:approver) { Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1) }
Page::Main::Login.perform(&:sign_in_using_credentials) let(:non_approver) { Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_2, Runtime::Env.gitlab_qa_password_2) }
# Create one user to be the assigned approver and another user who will let(:project) do
# not be an approver Resource::Project.fabricate_via_api! do |project|
approver = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1)
non_approver = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_2, Runtime::Env.gitlab_qa_password_2)
# Create a project and assign the users to it
project = Resource::Project.fabricate! do |project|
project.name = "assign-approvers" project.name = "assign-approvers"
project.initialize_with_readme = true
end end
end
let(:branch_name) { 'protected-branch' }
before do
project.add_member(approver, Resource::Members::AccessLevel::DEVELOPER)
project.add_member(non_approver, Resource::Members::AccessLevel::DEVELOPER)
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
project.visit! project.visit!
end
Page::Project::Menu.perform(&:go_to_members_settings) it 'merge request assigns code owners as approvers' do
Page::Project::Settings::Members.perform do |members_page| # Commit CODEOWNERS to master
members_page.add_member(approver.username) Resource::Repository::Commit.fabricate_via_api! do |commit|
members_page.add_member(non_approver.username) commit.project = project
commit.commit_message = 'Add CODEOWNERS and test files'
commit.add_files(
[
{
file_path: 'CODEOWNERS',
content: <<~CONTENT
CODEOWNERS @#{approver.username}
CONTENT
}
]
)
end end
Page::Project::Menu.perform(&:go_to_general_settings) # Create a projected branch that requires approval from code owners
Resource::ProtectedBranch.fabricate! do |protected_branch|
Page::Project::Settings::Main.perform do |settings| protected_branch.branch_name = branch_name
settings.expand_request_approval_settings do |page| protected_branch.project = project
page.click_require_code_owners_approval_checkbox
page.click_save_merge_request_approval_button
end
end end
# Push CODEOWNERS to master # Push a new CODEOWNERS file
project_push = Resource::Repository::ProjectPush.fabricate! do |push| Resource::Repository::Push.fabricate! do |push|
push.project = project push.repository_http_uri = project.repository_http_location.uri
push.branch_name = branch_name + '-patch'
push.file_name = 'CODEOWNERS' push.file_name = 'CODEOWNERS'
push.file_content = <<~CONTENT push.file_content = <<~CONTENT
CODEOWNERS @#{approver.username} CODEOWNERS @#{non_approver.username}
CONTENT CONTENT
push.commit_message = 'Add CODEOWNERS and test files'
end end
# Push a new CODEOWNERS file and create a merge request # Create a merge request
merge_request = Resource::MergeRequest.fabricate! do |merge_request| Resource::MergeRequest.fabricate! do |merge_request|
merge_request.title = 'This is a merge request' merge_request.project = project
merge_request.description = 'Change code owners'
merge_request.project = project_push.project
merge_request.file_name = 'CODEOWNERS'
merge_request.target_new_branch = false merge_request.target_new_branch = false
merge_request.file_content = <<~CONTENT merge_request.source_branch = branch_name + '-patch'
CODEOWNERS @#{non_approver.username} merge_request.target_branch = branch_name
CONTENT merge_request.no_preparation = true
end end.visit!
merge_request.visit!
# Check that the merge request assigns the original code owner as an # Check that the merge request assigns the original code owner as an
# approver (because the current CODEOWNERS file in the master branch # approver (because the current CODEOWNERS file in the master branch
# doesn't have the new owner yet) # doesn't have the new owner yet)
Page::MergeRequest::Show.perform do |mr_page| Page::MergeRequest::Show.perform do |show|
mr_page.edit! show.edit!
expect(mr_page.approvers).to include(approver.name) approvers = show.approvers
expect(mr_page.approvers).not_to include(non_approver.name)
expect(approvers).to include(approver.name)
expect(approvers).not_to include(non_approver.name)
end 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