Commit 0c4d284a authored by Mark Lapierre's avatar Mark Lapierre

Add basic E2E test of merge trains

New test added to the pipelines for merged results spec file because
it uses the the same setup, including a runner (which is not cheap
to set up)
parent 613716b3
...@@ -161,6 +161,12 @@ module QA ...@@ -161,6 +161,12 @@ module QA
approvals_content.match(/Requires (\d+) more approvals/)[1].to_i approvals_content.match(/Requires (\d+) more approvals/)[1].to_i
end end
def merge_via_merge_train
raise ElementNotFound, "Not ready to merge" unless ready_to_merge?
click_element(:merge_button, text: "Start merge train")
end
private private
def approvals_content def approvals_content
......
...@@ -129,17 +129,7 @@ module QA ...@@ -129,17 +129,7 @@ module QA
end end
def try_to_merge! def try_to_merge!
# The merge button is disabled on load merge_immediately if ready_to_merge?
wait do
has_element?(:merge_button)
end
# The merge button is enabled via JS
wait(reload: false) do
!find_element(:merge_button).disabled?
end
merge_immediately
end end
def merge! def merge!
...@@ -187,6 +177,18 @@ module QA ...@@ -187,6 +177,18 @@ module QA
click_element :edit_button click_element :edit_button
end end
def ready_to_merge?
# The merge button is disabled on load
wait do
has_element?(:merge_button)
end
# The merge button is enabled via JS
wait(reload: false) do
!find_element(:merge_button).disabled?
end
end
def view_email_patches def view_email_patches
click_element :dropdown_toggle click_element :dropdown_toggle
visit_link_in_element(:download_email_patches) visit_link_in_element(:download_email_patches)
......
...@@ -2,23 +2,21 @@ ...@@ -2,23 +2,21 @@
module QA module QA
context 'Release', :docker do context 'Release', :docker do
describe 'Pipelines for merged results' do describe 'Pipelines for merged results and merge trains' do
let(:project) do before(:context) do
Resource::Project.fabricate_via_api! do |project| @project = Resource::Project.fabricate_via_api! do |project|
project.name = 'pipelines-for-merged-results' project.name = 'pipelines-for-merged-results-and-merge-trains'
end end
end @executor = "qa-runner-#{Time.now.to_i}"
let(:executor) { "qa-runner-#{Time.now.to_i}" }
before do
Resource::Runner.fabricate_via_api! do |runner| Resource::Runner.fabricate_via_api! do |runner|
runner.project = project runner.project = @project
runner.name = executor runner.name = @executor
runner.tags = %w[qa test] runner.tags = %w[qa test]
end end
Resource::Repository::ProjectPush.fabricate! do |project_push| Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = project project_push.project = @project
project_push.file_name = '.gitlab-ci.yml' project_push.file_name = '.gitlab-ci.yml'
project_push.commit_message = 'Add .gitlab-ci.yml' project_push.commit_message = 'Add .gitlab-ci.yml'
project_push.file_content = <<~EOF project_push.file_content = <<~EOF
...@@ -28,42 +26,88 @@ module QA ...@@ -28,42 +26,88 @@ module QA
- merge_requests - merge_requests
EOF EOF
end end
end
before do
Runtime::Browser.visit(:gitlab, Page::Main::Login) Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials) Page::Main::Login.perform(&:sign_in_using_credentials)
end
after do
Service::Runner.new(executor).remove!
end
it 'creates a pipeline with merged results' do @project.visit!
project.visit!
Page::Project::Menu.perform(&:go_to_general_settings) Page::Project::Menu.perform(&:go_to_general_settings)
Page::Project::Settings::Main.perform do |main| Page::Project::Settings::Main.perform do |main|
main.expand_merge_requests_settings do |settings| main.expand_merge_requests_settings do |settings|
settings.click_pipelines_for_merged_results_checkbox settings.click_pipelines_for_merged_results_checkbox
settings.click_save_changes settings.click_save_changes
end end
end end
end
after(:context) do
Service::Runner.new(@executor).remove!
end
it 'creates a pipeline with merged results' do
# Create a branch that will be merged into master
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = @project
project_push.new_branch = true
project_push.branch_name = 'merged-results'
end
# Create a merge request to merge the branch we just created
Resource::MergeRequest.fabricate_via_api! do |merge_request| Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.project = project merge_request.project = @project
merge_request.target_new_branch = false merge_request.source_branch = 'merged-results'
merge_request.no_preparation = true
end.visit! end.visit!
Page::MergeRequest::Show.perform do |merge_request| Page::MergeRequest::Show.perform do |show|
expect(merge_request).to have_pipeline_status(/Merged result pipeline #\d+ passed/) expect(show).to have_pipeline_status(/Merged result pipeline #\d+ passed/)
# The default option is to merge via merge train, # The default option is to merge via merge train,
# but that will be covered by another test # but that will be covered by another test
merge_request.merge_immediately show.merge_immediately
end end
expect(page).to have_content('The changes were merged') expect(page).to have_content('The changes were merged')
end end
it 'merges via a merge train' do
# Create a branch that will be merged into master
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = @project
project_push.new_branch = true
project_push.branch_name = 'merge-train'
project_push.file_name = "another_file.txt"
project_push.file_content = "merge me"
end
# Create a merge request to merge the branch we just created
Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.project = @project
merge_request.source_branch = 'merge-train'
merge_request.no_preparation = true
end.visit!
Page::MergeRequest::Show.perform do |show|
expect(show).to have_pipeline_status(/Merged result pipeline #\d+ passed/)
show.merge_via_merge_train
end
expect(page).to have_content('Added to the merge train')
expect(page).to have_content('The changes will be merged into master')
# It's faster to refresh the page than to wait for the UI to
# automatically refresh, so we reload if the merge status
# doesn't update quickly.
merged = Support::Retrier.retry_until(reload_page: page) do
page.has_content?('The changes were merged')
end
expect(merged).to be_truthy, "Expected content 'The changes were merged' but it did not appear."
end
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