Commit 4c41fe4b authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'ml-qa-fix-merge-request-approvals-test' into 'master'

Update E2E test of assigning code owners

Closes #33680

See merge request gitlab-org/gitlab!18358
parents 1987c8a7 aca4050b
...@@ -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
project.visit!
Page::Project::Menu.perform(&:go_to_members_settings)
Page::Project::Settings::Members.perform do |members_page|
members_page.add_member(approver.username)
members_page.add_member(non_approver.username)
end end
let(:branch_name) { 'protected-branch' }
Page::Project::Menu.perform(&:go_to_general_settings) before do
project.add_member(approver, Resource::Members::AccessLevel::DEVELOPER)
project.add_member(non_approver, Resource::Members::AccessLevel::DEVELOPER)
Page::Project::Settings::Main.perform do |settings| Runtime::Browser.visit(:gitlab, Page::Main::Login)
settings.expand_request_approval_settings do |page| Page::Main::Login.perform(&:sign_in_using_credentials)
page.click_require_code_owners_approval_checkbox
page.click_save_merge_request_approval_button project.visit!
end
end end
# Push CODEOWNERS to master it 'merge request assigns code owners as approvers' do
project_push = Resource::Repository::ProjectPush.fabricate! do |push| # Commit CODEOWNERS to master
push.project = project Resource::Repository::Commit.fabricate_via_api! do |commit|
push.file_name = 'CODEOWNERS' commit.project = project
push.file_content = <<~CONTENT commit.commit_message = 'Add CODEOWNERS and test files'
commit.add_files(
[
{
file_path: 'CODEOWNERS',
content: <<~CONTENT
CODEOWNERS @#{approver.username} CODEOWNERS @#{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 projected branch that requires approval from code owners
merge_request = Resource::MergeRequest.fabricate! do |merge_request| Resource::ProtectedBranch.fabricate! do |protected_branch|
merge_request.title = 'This is a merge request' protected_branch.branch_name = branch_name
merge_request.description = 'Change code owners' protected_branch.project = project
merge_request.project = project_push.project end
merge_request.file_name = 'CODEOWNERS'
merge_request.target_new_branch = false # Push a new CODEOWNERS file
merge_request.file_content = <<~CONTENT Resource::Repository::Push.fabricate! do |push|
push.repository_http_uri = project.repository_http_location.uri
push.branch_name = branch_name + '-patch'
push.file_name = 'CODEOWNERS'
push.file_content = <<~CONTENT
CODEOWNERS @#{non_approver.username} CODEOWNERS @#{non_approver.username}
CONTENT CONTENT
end end
merge_request.visit! # Create a merge request
Resource::MergeRequest.fabricate! do |merge_request|
merge_request.project = project
merge_request.target_new_branch = false
merge_request.source_branch = branch_name + '-patch'
merge_request.target_branch = branch_name
merge_request.no_preparation = true
end.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