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

216 lines
7.4 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-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
describe 'Merge request > User resolves conflicts', :js do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, :repository) }
2018-03-17 18:26:18 +05:30
let(:user) { project.creator }
2017-09-10 17:25:29 +05:30
before do
# In order to have the diffs collapsed, we need to disable the increase feature
stub_feature_flags(gitlab_git_diff_size_limit_increase: false)
end
2016-09-13 17:45:13 +05:30
def create_merge_request(source_branch)
2018-11-08 19:23:39 +05:30
create(:merge_request, source_branch: source_branch, target_branch: 'conflict-start', source_project: project, merge_status: :unchecked) do |mr|
2016-09-13 17:45:13 +05:30
mr.mark_as_unmergeable
end
end
2019-12-26 22:10:19 +05:30
shared_examples 'conflicts are resolved in Interactive mode' do
2016-11-03 12:29:30 +05:30
it 'conflicts are resolved in Interactive mode' do
within find('.files-wrapper .diff-file', text: 'files/ruby/popen.rb') do
click_button 'Use ours'
end
within find('.files-wrapper .diff-file', text: 'files/ruby/regex.rb') do
all('button', text: 'Use ours').each do |button|
2018-03-17 18:26:18 +05:30
button.send_keys(:return)
2016-11-03 12:29:30 +05:30
end
end
2018-11-08 19:23:39 +05:30
find_button('Commit to source branch').send_keys(:return)
2016-11-03 12:29:30 +05:30
expect(page).to have_content('All merge conflicts were resolved')
merge_request.reload_diff
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-11-03 12:29:30 +05:30
click_on 'Changes'
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-11-03 12:29:30 +05:30
2019-03-02 22:35:43 +05:30
find('.js-toggle-tree-list').click
2016-11-03 12:29:30 +05:30
within find('.diff-file', text: 'files/ruby/popen.rb') do
expect(page).to have_selector('.line_content.new', text: "vars = { 'PWD' => path }")
expect(page).to have_selector('.line_content.new', text: "options = { chdir: path }")
end
within find('.diff-file', text: 'files/ruby/regex.rb') do
expect(page).to have_selector('.line_content.new', text: "def username_regexp")
expect(page).to have_selector('.line_content.new', text: "def project_name_regexp")
expect(page).to have_selector('.line_content.new', text: "def path_regexp")
expect(page).to have_selector('.line_content.new', text: "def archive_formats_regexp")
expect(page).to have_selector('.line_content.new', text: "def git_reference_regexp")
expect(page).to have_selector('.line_content.new', text: "def default_regexp")
end
end
end
2016-09-13 17:45:13 +05:30
2016-11-03 12:29:30 +05:30
shared_examples "conflicts are resolved in Edit inline mode" do
it 'conflicts are resolved in Edit inline mode' do
expect(find('#conflicts')).to have_content('popen.rb')
within find('.files-wrapper .diff-file', text: 'files/ruby/popen.rb') do
click_button 'Edit inline'
2017-09-10 17:25:29 +05:30
wait_for_requests
2018-03-17 18:26:18 +05:30
find('.files-wrapper .diff-file pre')
2016-11-03 12:29:30 +05:30
execute_script('ace.edit($(".files-wrapper .diff-file pre")[0]).setValue("One morning");')
end
within find('.files-wrapper .diff-file', text: 'files/ruby/regex.rb') do
click_button 'Edit inline'
2017-09-10 17:25:29 +05:30
wait_for_requests
2018-03-17 18:26:18 +05:30
find('.files-wrapper .diff-file pre')
2016-11-03 12:29:30 +05:30
execute_script('ace.edit($(".files-wrapper .diff-file pre")[1]).setValue("Gregor Samsa woke from troubled dreams");')
end
2018-11-08 19:23:39 +05:30
find_button('Commit to source branch').send_keys(:return)
2017-09-10 17:25:29 +05:30
2016-11-03 12:29:30 +05:30
expect(page).to have_content('All merge conflicts were resolved')
merge_request.reload_diff
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-11-03 12:29:30 +05:30
click_on 'Changes'
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-11-03 12:29:30 +05:30
expect(page).to have_content('One morning')
expect(page).to have_content('Gregor Samsa woke from troubled dreams')
end
end
context 'can be resolved in the UI' do
2016-09-13 17:45:13 +05:30
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2017-09-10 17:25:29 +05:30
sign_in(user)
2016-09-13 17:45:13 +05:30
end
2016-11-03 12:29:30 +05:30
context 'the conflicts are resolvable' do
let(:merge_request) { create_merge_request('conflict-resolvable') }
2017-09-10 17:25:29 +05:30
before do
visit project_merge_request_path(project, merge_request)
end
2016-11-03 12:29:30 +05:30
it 'shows a link to the conflict resolution page' do
2018-03-17 18:26:18 +05:30
expect(page).to have_link('conflicts', href: %r{/conflicts\Z})
2016-11-03 12:29:30 +05:30
end
context 'in Inline view mode' do
2017-09-10 17:25:29 +05:30
before do
2018-03-17 18:26:18 +05:30
click_link('conflicts', href: %r{/conflicts\Z})
2017-09-10 17:25:29 +05:30
end
2016-11-03 12:29:30 +05:30
2018-12-05 23:21:45 +05:30
include_examples "conflicts are resolved in Interactive mode"
include_examples "conflicts are resolved in Edit inline mode"
2016-11-03 12:29:30 +05:30
end
context 'in Parallel view mode' do
before do
2018-03-17 18:26:18 +05:30
click_link('conflicts', href: %r{/conflicts\Z})
2016-11-03 12:29:30 +05:30
click_button 'Side-by-side'
end
2018-12-05 23:21:45 +05:30
include_examples "conflicts are resolved in Interactive mode"
include_examples "conflicts are resolved in Edit inline mode"
2016-11-03 12:29:30 +05:30
end
2016-09-13 17:45:13 +05:30
end
2016-11-03 12:29:30 +05:30
context 'the conflict contain markers' do
let(:merge_request) { create_merge_request('conflict-contains-conflict-markers') }
2016-09-13 17:45:13 +05:30
2016-11-03 12:29:30 +05:30
before do
2017-09-10 17:25:29 +05:30
visit project_merge_request_path(project, merge_request)
2018-03-17 18:26:18 +05:30
click_link('conflicts', href: %r{/conflicts\Z})
2016-11-03 12:29:30 +05:30
end
it 'conflicts can not be resolved in Interactive mode' do
within find('.files-wrapper .diff-file', text: 'files/markdown/ruby-style-guide.md') do
expect(page).not_to have_content 'Interactive mode'
expect(page).not_to have_content 'Edit inline'
end
end
2019-12-04 20:38:33 +05:30
# TODO: https://gitlab.com/gitlab-org/gitlab-foss/issues/48034
2018-11-08 19:23:39 +05:30
xit 'conflicts are resolved in Edit inline mode' do
2016-11-03 12:29:30 +05:30
within find('.files-wrapper .diff-file', text: 'files/markdown/ruby-style-guide.md') do
2017-09-10 17:25:29 +05:30
wait_for_requests
2018-03-17 18:26:18 +05:30
find('.files-wrapper .diff-file pre')
2016-11-03 12:29:30 +05:30
execute_script('ace.edit($(".files-wrapper .diff-file pre")[0]).setValue("Gregor Samsa woke from troubled dreams");')
2016-09-13 17:45:13 +05:30
end
2016-11-03 12:29:30 +05:30
2018-11-08 19:23:39 +05:30
click_button 'Commit to source branch'
2016-11-03 12:29:30 +05:30
expect(page).to have_content('All merge conflicts were resolved')
merge_request.reload_diff
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-11-03 12:29:30 +05:30
click_on 'Changes'
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
click_link 'Expand all'
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-11-03 12:29:30 +05:30
expect(page).to have_content('Gregor Samsa woke from troubled dreams')
2016-09-13 17:45:13 +05:30
end
end
2019-04-03 18:18:56 +05:30
context "with malicious branch name" do
let(:bad_branch_name) { "malicious-branch-{{toString.constructor('alert(/xss/)')()}}" }
2020-03-09 13:42:32 +05:30
let!(:branch) { project.repository.create_branch(bad_branch_name, 'conflict-resolvable') }
let(:merge_request) { create_merge_request(bad_branch_name) }
2019-04-03 18:18:56 +05:30
before do
visit project_merge_request_path(project, merge_request)
click_link('conflicts', href: %r{/conflicts\Z})
end
it "renders bad name without xss issues" do
expect(find('.resolve-conflicts-form .resolve-info')).to have_content(bad_branch_name)
end
end
2016-09-13 17:45:13 +05:30
end
2020-05-24 23:13:21 +05:30
unresolvable_conflicts = {
2016-09-13 17:45:13 +05:30
'conflict-too-large' => 'when the conflicts contain a large file',
'conflict-binary-file' => 'when the conflicts contain a binary file',
'conflict-missing-side' => 'when the conflicts contain a file edited in one branch and deleted in another',
2017-09-10 17:25:29 +05:30
'conflict-non-utf8' => 'when the conflicts contain a non-UTF-8 file'
2017-08-17 22:00:37 +05:30
}.freeze
2016-09-13 17:45:13 +05:30
2020-05-24 23:13:21 +05:30
unresolvable_conflicts.each do |source_branch, description|
2016-09-13 17:45:13 +05:30
context description do
let(:merge_request) { create_merge_request(source_branch) }
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2017-09-10 17:25:29 +05:30
sign_in(user)
visit project_merge_request_path(project, merge_request)
2016-09-13 17:45:13 +05:30
end
it 'does not show a link to the conflict resolution page' do
2018-03-17 18:26:18 +05:30
expect(page).not_to have_link('conflicts', href: %r{/conflicts\Z})
2016-09-13 17:45:13 +05:30
end
it 'shows an error if the conflicts page is visited directly' do
visit current_url + '/conflicts'
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-09-13 17:45:13 +05:30
expect(find('#conflicts')).to have_content('Please try to resolve them locally.')
end
end
end
end