debian-mirror-gitlab/spec/features/merge_request/user_selects_branches_for_new_mr_spec.rb

207 lines
6.8 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2016-06-02 11:05:42 +05:30
2020-06-23 00:09:42 +05:30
RSpec.describe 'Merge request > User selects branches for new MR', :js do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, :public, :repository) }
2018-03-17 18:26:18 +05:30
let(:user) { project.creator }
2016-06-02 11:05:42 +05:30
2018-10-15 14:42:47 +05:30
def select_source_branch(branch_name)
find('.js-source-branch', match: :first).click
find('.js-source-branch-dropdown .dropdown-input-field').native.send_keys branch_name
find('.js-source-branch-dropdown .dropdown-content a', text: branch_name, match: :first).click
end
2016-06-02 11:05:42 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2018-03-17 18:26:18 +05:30
sign_in(user)
2016-06-02 11:05:42 +05:30
end
2017-08-17 22:00:37 +05:30
it 'selects the source branch sha when a tag with the same name exists' do
2017-09-10 17:25:29 +05:30
visit project_merge_requests_path(project)
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
page.within '.content' do
click_link 'New merge request'
end
2016-09-13 17:45:13 +05:30
expect(page).to have_content('Source branch')
expect(page).to have_content('Target branch')
2016-06-02 11:05:42 +05:30
first('.js-source-branch').click
2018-10-15 14:42:47 +05:30
find('.js-source-branch-dropdown .dropdown-content a', match: :first).click
2017-08-17 22:00:37 +05:30
expect(page).to have_content "b83d6e3"
end
it 'selects the target branch sha when a tag with the same name exists' do
2017-09-10 17:25:29 +05:30
visit project_merge_requests_path(project)
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
page.within '.content' do
click_link 'New merge request'
end
2017-08-17 22:00:37 +05:30
expect(page).to have_content('Source branch')
expect(page).to have_content('Target branch')
first('.js-target-branch').click
2018-10-15 14:42:47 +05:30
find('.js-target-branch-dropdown .dropdown-content a', text: 'v1.1.0', match: :first).click
2017-08-17 22:00:37 +05:30
expect(page).to have_content "b83d6e3"
end
it 'generates a diff for an orphaned branch' do
2018-10-15 14:42:47 +05:30
visit project_new_merge_request_path(project)
2017-08-17 22:00:37 +05:30
2018-10-15 14:42:47 +05:30
select_source_branch('orphaned-branch')
2016-06-02 11:05:42 +05:30
click_button "Compare branches"
click_link "Changes"
expect(page).to have_content "README.md"
expect(page).to have_content "wm.png"
fill_in "merge_request_title", with: "Orphaned MR test"
2021-04-29 21:17:54 +05:30
click_button "Create merge request"
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
click_button "Check out branch"
2016-06-02 11:05:42 +05:30
2019-12-04 20:38:33 +05:30
expect(page).to have_content 'git checkout -b "orphaned-branch" "origin/orphaned-branch"'
2016-06-02 11:05:42 +05:30
end
2018-03-17 18:26:18 +05:30
it 'allows filtering multiple dropdowns' do
visit project_new_merge_request_path(project)
first('.js-source-branch').click
2018-10-15 14:42:47 +05:30
page.within '.js-source-branch-dropdown' do
input = find('.dropdown-input-field')
input.click
input.send_keys('orphaned-branch')
2018-03-17 18:26:18 +05:30
2018-10-15 14:42:47 +05:30
expect(page).to have_css('.dropdown-content li', count: 1)
end
2018-03-17 18:26:18 +05:30
first('.js-target-branch').click
2018-10-15 14:42:47 +05:30
find('.js-target-branch-dropdown .dropdown-content li', match: :first)
target_items = all('.js-target-branch-dropdown .dropdown-content li')
2018-03-17 18:26:18 +05:30
expect(target_items.count).to be > 1
end
2016-06-02 11:05:42 +05:30
context 'when target project cannot be viewed by the current user' do
it 'does not leak the private project name & namespace' do
2017-09-10 17:25:29 +05:30
private_project = create(:project, :private, :repository)
2016-06-02 11:05:42 +05:30
2017-09-10 17:25:29 +05:30
visit project_new_merge_request_path(project, merge_request: { target_project_id: private_project.id })
2016-06-02 11:05:42 +05:30
2017-09-10 17:25:29 +05:30
expect(page).not_to have_content private_project.full_path
expect(page).to have_content project.full_path
2016-06-02 11:05:42 +05:30
end
end
2016-09-13 17:45:13 +05:30
2017-08-17 22:00:37 +05:30
context 'when source project cannot be viewed by the current user' do
it 'does not leak the private project name & namespace' do
2017-09-10 17:25:29 +05:30
private_project = create(:project, :private, :repository)
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
visit project_new_merge_request_path(project, merge_request: { source_project_id: private_project.id })
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(page).not_to have_content private_project.full_path
expect(page).to have_content project.full_path
2017-08-17 22:00:37 +05:30
end
end
it 'populates source branch button' do
2017-09-10 17:25:29 +05:30
visit project_new_merge_request_path(project, change_branches: true, merge_request: { target_branch: 'master', source_branch: 'fix' })
2017-08-17 22:00:37 +05:30
expect(find('.js-source-branch')).to have_content('fix')
end
2016-09-13 17:45:13 +05:30
it 'allows to change the diff view' do
2017-09-10 17:25:29 +05:30
visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: 'fix' })
2016-09-13 17:45:13 +05:30
click_link 'Changes'
2021-04-17 20:07:23 +05:30
expect(page).to have_css('a.btn.selected', text: 'Inline')
expect(page).not_to have_css('a.btn.selected', text: 'Side-by-side')
2016-09-13 17:45:13 +05:30
click_link 'Side-by-side'
within '.merge-request' do
2021-04-17 20:07:23 +05:30
expect(page).not_to have_css('a.btn.selected', text: 'Inline')
expect(page).to have_css('a.btn.selected', text: 'Side-by-side')
2016-09-13 17:45:13 +05:30
end
end
2017-08-17 22:00:37 +05:30
it 'does not allow non-existing branches' do
2017-09-10 17:25:29 +05:30
visit project_new_merge_request_path(project, merge_request: { target_branch: 'non-exist-target', source_branch: 'non-exist-source' })
2017-08-17 22:00:37 +05:30
expect(page).to have_content('The form contains the following errors')
expect(page).to have_content('Source branch "non-exist-source" does not exist')
expect(page).to have_content('Target branch "non-exist-target" does not exist')
end
context 'when a branch contains commits that both delete and add the same image' do
it 'renders the diff successfully' do
2017-09-10 17:25:29 +05:30
visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: 'deleted-image-test' })
2017-08-17 22:00:37 +05:30
click_link "Changes"
expect(page).to have_content "6049019_460s.jpg"
end
end
# Isolates a regression (see #24627)
it 'does not show error messages on initial form' do
2017-09-10 17:25:29 +05:30
visit project_new_merge_request_path(project)
2017-08-17 22:00:37 +05:30
expect(page).not_to have_selector('#error_explanation')
expect(page).not_to have_content('The form contains the following error')
end
context 'when a new merge request has a pipeline' do
let!(:pipeline) do
create(:ci_pipeline, sha: project.commit('fix').id,
ref: 'fix',
project: project)
end
it 'shows pipelines for a new merge request' do
2017-09-10 17:25:29 +05:30
visit project_new_merge_request_path(
project,
2017-08-17 22:00:37 +05:30
merge_request: { target_branch: 'master', source_branch: 'fix' })
page.within('.merge-request') do
click_link 'Pipelines'
expect(page).to have_content "##{pipeline.id}"
end
end
end
2018-10-15 14:42:47 +05:30
context 'with special characters in branch names' do
2020-01-01 13:55:28 +05:30
let(:create_branch_service) { ::Branches::CreateService.new(project, user) }
2018-10-15 14:42:47 +05:30
it 'escapes quotes in branch names' do
special_branch_name = '"with-quotes"'
2020-01-01 13:55:28 +05:30
create_branch_service.execute(special_branch_name, 'add-pdf-file')
2018-10-15 14:42:47 +05:30
visit project_new_merge_request_path(project)
select_source_branch(special_branch_name)
source_branch_input = find('[name="merge_request[source_branch]"]', visible: false)
expect(source_branch_input.value).to eq special_branch_name
end
it 'does not escape unicode in branch names' do
special_branch_name = 'ʕ•ᴥ•ʔ'
2020-01-01 13:55:28 +05:30
create_branch_service.execute(special_branch_name, 'add-pdf-file')
2018-10-15 14:42:47 +05:30
visit project_new_merge_request_path(project)
select_source_branch(special_branch_name)
click_button "Compare branches"
2021-04-29 21:17:54 +05:30
expect(page).to have_button("Create merge request")
2018-10-15 14:42:47 +05:30
end
end
2016-06-02 11:05:42 +05:30
end