diff options
Diffstat (limited to 'spec/features/merge_request')
17 files changed, 502 insertions, 126 deletions
diff --git a/spec/features/merge_request/close_reopen_report_toggle_spec.rb b/spec/features/merge_request/close_reopen_report_toggle_spec.rb new file mode 100644 index 00000000000..8a4277d87c9 --- /dev/null +++ b/spec/features/merge_request/close_reopen_report_toggle_spec.rb @@ -0,0 +1,118 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Issuables Close/Reopen/Report toggle' do + include IssuablesHelper + + let(:user) { create(:user) } + + context 'on a merge request' do + let(:container) { find('.detail-page-header-actions') } + let(:project) { create(:project, :repository) } + let(:issuable) { create(:merge_request, source_project: project) } + + before do + project.add_maintainer(user) + login_as user + end + + context 'when user has permission to update', :js do + before do + visit project_merge_request_path(project, issuable) + end + + context 'close/reopen/report toggle' do + it 'opens a dropdown when toggle is clicked' do + click_button 'Toggle dropdown' + + expect(container).to have_link("Close merge request") + expect(container).to have_link('Report abuse') + expect(container).to have_text("Report merge requests that are abusive, inappropriate or spam.") + end + + it 'links to Report Abuse' do + click_button 'Toggle dropdown' + click_link 'Report abuse' + + expect(page).to have_content('Report abuse to admin') + end + end + + context 'when the merge request is open' do + let(:issuable) { create(:merge_request, :opened, source_project: project) } + + it 'shows the `Edit` and `Mark as draft` buttons' do + expect(container).to have_link('Edit') + expect(container).to have_link('Mark as draft') + expect(container).not_to have_button('Report abuse') + expect(container).not_to have_button('Close merge request') + expect(container).not_to have_link('Reopen merge request') + end + end + + context 'when the merge request is closed' do + let(:issuable) { create(:merge_request, :closed, source_project: project) } + + it 'shows both the `Edit` and `Reopen` button' do + expect(container).to have_link('Edit') + expect(container).not_to have_button('Report abuse') + expect(container).not_to have_button('Close merge request') + expect(container).to have_link('Reopen merge request') + end + + context 'when the merge request author is the current user' do + let(:issuable) { create(:merge_request, :closed, source_project: project, author: user) } + + it 'shows both the `Edit` and `Reopen` button' do + expect(container).to have_link('Edit') + expect(container).not_to have_link('Report abuse') + expect(container).not_to have_selector('button.dropdown-toggle') + expect(container).not_to have_button('Close merge request') + expect(container).to have_link('Reopen merge request') + end + end + end + + context 'when the merge request is merged' do + let(:issuable) { create(:merge_request, :merged, source_project: project) } + + it 'shows only the `Edit` button' do + expect(container).to have_link(exact_text: 'Edit') + expect(container).not_to have_link('Report abuse') + expect(container).not_to have_button('Close merge request') + expect(container).not_to have_button('Reopen merge request') + end + + context 'when the merge request author is the current user' do + let(:issuable) { create(:merge_request, :merged, source_project: project, author: user) } + + it 'shows only the `Edit` button' do + expect(container).to have_link(exact_text: 'Edit') + expect(container).not_to have_link('Report abuse') + expect(container).not_to have_button('Close merge request') + expect(container).not_to have_button('Reopen merge request') + end + end + end + end + + context 'when user doesnt have permission to update' do + let(:cant_project) { create(:project, :repository) } + let(:cant_issuable) { create(:merge_request, source_project: cant_project) } + + before do + cant_project.add_reporter(user) + + visit project_merge_request_path(cant_project, cant_issuable) + end + + it 'only shows a `Report abuse` button' do + expect(container).to have_link('Report abuse') + expect(container).not_to have_button('Close merge request') + expect(container).not_to have_button('Reopen merge request') + expect(container).not_to have_link(exact_text: 'Edit') + end + end + end +end diff --git a/spec/features/merge_request/merge_request_discussion_lock_spec.rb b/spec/features/merge_request/merge_request_discussion_lock_spec.rb new file mode 100644 index 00000000000..4e0265839f6 --- /dev/null +++ b/spec/features/merge_request/merge_request_discussion_lock_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true +# TODO use shared examples to merge this spec with discussion_lock_spec.rb +# https://gitlab.com/gitlab-org/gitlab/-/issues/255910 + +require 'spec_helper' + +RSpec.describe 'Merge Request Discussion Lock', :js do + let(:user) { create(:user) } + let(:project) { create(:project, :public, :repository) } + let(:merge_request) { create(:merge_request, source_project: project, author: user) } + + before do + sign_in(user) + end + + context 'when a user is a team member' do + before do + project.add_developer(user) + end + + context 'when the discussion is unlocked' do + it 'the user can lock the merge_request' do + visit project_merge_request_path(merge_request.project, merge_request) + + expect(find('.issuable-sidebar')).to have_content('Unlocked') + + page.within('.issuable-sidebar') do + find('.lock-edit').click + click_button('Lock') + end + + expect(find('[data-testid="lock-status"]')).to have_content('Locked') + end + end + + context 'when the discussion is locked' do + before do + merge_request.update_attribute(:discussion_locked, true) + visit project_merge_request_path(merge_request.project, merge_request) + end + + it 'the user can unlock the merge_request' do + expect(find('.issuable-sidebar')).to have_content('Locked') + + page.within('.issuable-sidebar') do + find('.lock-edit').click + click_button('Unlock') + end + + expect(find('[data-testid="lock-status"]')).to have_content('Unlocked') + end + end + end + + context 'when a user is not a team member' do + context 'when the discussion is unlocked' do + before do + visit project_merge_request_path(merge_request.project, merge_request) + end + + it 'the user can not lock the merge_request' do + expect(find('.issuable-sidebar')).to have_content('Unlocked') + expect(find('.issuable-sidebar')).not_to have_selector('.lock-edit') + end + end + + context 'when the discussion is locked' do + before do + merge_request.update_attribute(:discussion_locked, true) + visit project_merge_request_path(merge_request.project, merge_request) + end + + it 'the user can not unlock the merge_request' do + expect(find('.issuable-sidebar')).to have_content('Locked') + expect(find('.issuable-sidebar')).not_to have_selector('.lock-edit') + end + end + end +end diff --git a/spec/features/merge_request/user_closes_merge_request_spec.rb b/spec/features/merge_request/user_closes_merge_request_spec.rb deleted file mode 100644 index e6b6778c76e..00000000000 --- a/spec/features/merge_request/user_closes_merge_request_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'User closes a merge requests', :js do - let(:project) { create(:project, :repository) } - let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } - let(:user) { create(:user) } - - before do - project.add_maintainer(user) - sign_in(user) - - visit(merge_request_path(merge_request)) - end - - it 'closes a merge request' do - click_button('Close merge request', match: :first) - - expect(page).to have_content(merge_request.title) - expect(page).to have_content('Closed by') - end -end diff --git a/spec/features/merge_request/user_closes_reopens_merge_request_state_spec.rb b/spec/features/merge_request/user_closes_reopens_merge_request_state_spec.rb new file mode 100644 index 00000000000..6376f9ab5fd --- /dev/null +++ b/spec/features/merge_request/user_closes_reopens_merge_request_state_spec.rb @@ -0,0 +1,101 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User closes/reopens a merge request', :js do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + + before do + project.add_developer(user) + sign_in(user) + end + + describe 'when open' do + context 'when clicking the top `Close merge request` link', :aggregate_failures do + let(:open_merge_request) { create(:merge_request, source_project: project, target_project: project) } + + before do + visit merge_request_path(open_merge_request) + end + + it 'can close a merge request' do + expect(find('.status-box')).to have_content 'Open' + + within '.detail-page-header' do + click_button 'Toggle dropdown' + click_link 'Close merge request' + end + + wait_for_requests + + expect(find('.status-box')).to have_content 'Closed' + end + end + + context 'when clicking the bottom `Close merge request` button', :aggregate_failures do + let(:open_merge_request) { create(:merge_request, source_project: project, target_project: project) } + + before do + visit merge_request_path(open_merge_request) + end + + it 'can close a merge request' do + expect(find('.status-box')).to have_content 'Open' + + within '.timeline-content-form' do + click_button 'Close merge request' + + # Clicking the bottom `Close merge request` button does not yet update + # the header status so for now we'll check that the button text changes + expect(page).not_to have_button 'Close merge request' + expect(page).to have_button 'Reopen merge request' + end + end + end + end + + describe 'when closed' do + context 'when clicking the top `Reopen merge request` link', :aggregate_failures do + let(:closed_merge_request) { create(:merge_request, source_project: project, target_project: project, state: 'closed') } + + before do + visit merge_request_path(closed_merge_request) + end + + it 'can reopen a merge request' do + expect(find('.status-box')).to have_content 'Closed' + + within '.detail-page-header' do + click_button 'Toggle dropdown' + click_link 'Reopen merge request' + end + + wait_for_requests + + expect(find('.status-box')).to have_content 'Open' + end + end + + context 'when clicking the bottom `Reopen merge request` button', :aggregate_failures do + let(:closed_merge_request) { create(:merge_request, source_project: project, target_project: project, state: 'closed') } + + before do + visit merge_request_path(closed_merge_request) + end + + it 'can reopen a merge request' do + expect(find('.status-box')).to have_content 'Closed' + + within '.timeline-content-form' do + click_button 'Reopen merge request' + + # Clicking the bottom `Reopen merge request` button does not yet update + # the header status so for now we'll check that the button text changes + expect(page).not_to have_button 'Reopen merge request' + expect(page).to have_button 'Close merge request' + end + end + end + end +end diff --git a/spec/features/merge_request/user_comments_on_diff_spec.rb b/spec/features/merge_request/user_comments_on_diff_spec.rb index c452408cff2..0fd140a00bd 100644 --- a/spec/features/merge_request/user_comments_on_diff_spec.rb +++ b/spec/features/merge_request/user_comments_on_diff_spec.rb @@ -31,7 +31,7 @@ RSpec.describe 'User comments on a diff', :js do click_button('Add comment now') end - page.within('.diff-files-holder > div:nth-child(3)') do + page.within('.diff-files-holder > div:nth-child(6)') do expect(page).to have_content('Line is wrong') find('.js-diff-more-actions').click @@ -53,7 +53,7 @@ RSpec.describe 'User comments on a diff', :js do wait_for_requests - page.within('.diff-files-holder > div:nth-child(2) .note-body > .note-text') do + page.within('.diff-files-holder > div:nth-child(5) .note-body > .note-text') do expect(page).to have_content('Line is correct') end @@ -67,7 +67,7 @@ RSpec.describe 'User comments on a diff', :js do wait_for_requests # Hide the comment. - page.within('.diff-files-holder > div:nth-child(3)') do + page.within('.diff-files-holder > div:nth-child(6)') do find('.js-diff-more-actions').click click_button 'Hide comments on this file' @@ -76,22 +76,22 @@ RSpec.describe 'User comments on a diff', :js do # At this moment a user should see only one comment. # The other one should be hidden. - page.within('.diff-files-holder > div:nth-child(2) .note-body > .note-text') do + page.within('.diff-files-holder > div:nth-child(5) .note-body > .note-text') do expect(page).to have_content('Line is correct') end # Show the comment. - page.within('.diff-files-holder > div:nth-child(3)') do + page.within('.diff-files-holder > div:nth-child(6)') do find('.js-diff-more-actions').click click_button 'Show comments on this file' end # Now both the comments should be shown. - page.within('.diff-files-holder > div:nth-child(3) .note-body > .note-text') do + page.within('.diff-files-holder > div:nth-child(6) .note-body > .note-text') do expect(page).to have_content('Line is wrong') end - page.within('.diff-files-holder > div:nth-child(2) .note-body > .note-text') do + page.within('.diff-files-holder > div:nth-child(5) .note-body > .note-text') do expect(page).to have_content('Line is correct') end @@ -102,11 +102,11 @@ RSpec.describe 'User comments on a diff', :js do wait_for_requests - page.within('.diff-files-holder > div:nth-child(3) .parallel .note-body > .note-text') do + page.within('.diff-files-holder > div:nth-child(6) .parallel .note-body > .note-text') do expect(page).to have_content('Line is wrong') end - page.within('.diff-files-holder > div:nth-child(2) .parallel .note-body > .note-text') do + page.within('.diff-files-holder > div:nth-child(5) .parallel .note-body > .note-text') do expect(page).to have_content('Line is correct') end end @@ -136,7 +136,7 @@ RSpec.describe 'User comments on a diff', :js do add_comment('-13', '+15') end - it 'allows comments on previously hidden lines at the top of a file' do + it 'allows comments on previously hidden lines at the top of a file', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/285294' do # Click -9, expand up, select 1 add and verify comment page.within('[data-path="files/ruby/popen.rb"]') do all('.js-unfold-all')[0].click @@ -204,7 +204,7 @@ RSpec.describe 'User comments on a diff', :js do click_button('Add comment now') end - page.within('.diff-file:nth-of-type(5) .discussion .note') do + page.within('.diff-file:nth-of-type(1) .discussion .note') do find('.js-note-edit').click page.within('.current-note-edit-form') do @@ -215,7 +215,7 @@ RSpec.describe 'User comments on a diff', :js do expect(page).not_to have_button('Save comment', disabled: true) end - page.within('.diff-file:nth-of-type(5) .discussion .note') do + page.within('.diff-file:nth-of-type(1) .discussion .note') do expect(page).to have_content('Typo, please fix').and have_no_content('Line is wrong') end end @@ -234,7 +234,7 @@ RSpec.describe 'User comments on a diff', :js do expect(page).to have_content('1') end - page.within('.diff-file:nth-of-type(5) .discussion .note') do + page.within('.diff-file:nth-of-type(1) .discussion .note') do find('.more-actions').click find('.more-actions .dropdown-menu li', match: :first) diff --git a/spec/features/merge_request/user_posts_diff_notes_spec.rb b/spec/features/merge_request/user_posts_diff_notes_spec.rb index 9556142ecb8..794dfd7c8da 100644 --- a/spec/features/merge_request/user_posts_diff_notes_spec.rb +++ b/spec/features/merge_request/user_posts_diff_notes_spec.rb @@ -74,7 +74,10 @@ RSpec.describe 'Merge request > User posts diff notes', :js do context 'with an unfolded line' do before do - find('.js-unfold', match: :first).click + page.within('.file-holder[id="a5cc2925ca8258af241be7e5b0381edf30266302"]') do + find('.js-unfold', match: :first).click + end + wait_for_requests end @@ -137,7 +140,10 @@ RSpec.describe 'Merge request > User posts diff notes', :js do context 'with an unfolded line' do before do - find('.js-unfold', match: :first).click + page.within('.file-holder[id="a5cc2925ca8258af241be7e5b0381edf30266302"]') do + find('.js-unfold', match: :first).click + end + wait_for_requests end diff --git a/spec/features/merge_request/user_reopens_merge_request_spec.rb b/spec/features/merge_request/user_reopens_merge_request_spec.rb deleted file mode 100644 index 4a05a3be59a..00000000000 --- a/spec/features/merge_request/user_reopens_merge_request_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'User reopens a merge requests', :js do - let(:project) { create(:project, :public, :repository) } - let!(:merge_request) { create(:closed_merge_request, source_project: project, target_project: project) } - let(:user) { create(:user) } - - before do - project.add_maintainer(user) - sign_in(user) - - visit(merge_request_path(merge_request)) - end - - it 'reopens a merge request' do - find('.js-issuable-close-dropdown .dropdown-toggle').click - - click_link('Reopen merge request', match: :first) - - wait_for_requests - - page.within('.status-box') do - expect(page).to have_content('Open') - end - end -end diff --git a/spec/features/merge_request/user_resolves_conflicts_spec.rb b/spec/features/merge_request/user_resolves_conflicts_spec.rb index 06405232462..1b1152897fc 100644 --- a/spec/features/merge_request/user_resolves_conflicts_spec.rb +++ b/spec/features/merge_request/user_resolves_conflicts_spec.rb @@ -8,11 +8,6 @@ RSpec.describe 'Merge request > User resolves conflicts', :js do let(:project) { create(:project, :repository) } let(:user) { project.creator } - 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 - def create_merge_request(source_branch) create(:merge_request, source_branch: source_branch, target_branch: 'conflict-start', source_project: project, merge_status: :unchecked) do |mr| mr.mark_as_unmergeable diff --git a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb index 00f0c88497b..cb7c952dfe4 100644 --- a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb +++ b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb @@ -111,7 +111,6 @@ RSpec.describe 'Merge request > User resolves diff notes and threads', :js do it 'shows resolved thread when toggled' do find(".timeline-content .discussion[data-discussion-id='#{note.discussion_id}'] .discussion-toggle-button").click - expect(page.find(".line-holder-placeholder")).to be_visible expect(page.find(".timeline-content #note_#{note.id}")).to be_visible end diff --git a/spec/features/merge_request/user_sees_check_out_branch_modal_spec.rb b/spec/features/merge_request/user_sees_check_out_branch_modal_spec.rb index e47f9ff2660..38546fd629d 100644 --- a/spec/features/merge_request/user_sees_check_out_branch_modal_spec.rb +++ b/spec/features/merge_request/user_sees_check_out_branch_modal_spec.rb @@ -18,8 +18,8 @@ RSpec.describe 'Merge request > User sees check out branch modal', :js do expect(page).to have_content('Check out, review, and merge locally') end - it 'closes the check out branch modal with escape keypress' do - find('#modal_merge_info').send_keys(:escape) + it 'closes the check out branch modal with the close action' do + find('.modal button[aria-label="Close"]').click expect(page).not_to have_content('Check out, review, and merge locally') end diff --git a/spec/features/merge_request/user_sees_empty_state_spec.rb b/spec/features/merge_request/user_sees_empty_state_spec.rb deleted file mode 100644 index ac07b31731d..00000000000 --- a/spec/features/merge_request/user_sees_empty_state_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'Merge request > User sees empty state' do - let(:project) { create(:project, :public, :repository) } - let(:user) { project.creator } - - before do - project.add_maintainer(user) - sign_in(user) - end - - it 'shows an empty state and a "New merge request" button' do - visit project_merge_requests_path(project) - - expect(page).to have_selector('.empty-state') - expect(page).to have_link 'New merge request', href: project_new_merge_request_path(project) - end - - context 'if there are merge requests' do - before do - create(:merge_request, source_project: project) - end - - it 'does not show an empty state' do - visit project_merge_requests_path(project) - - expect(page).not_to have_selector('.empty-state') - end - - it 'shows empty state when filter results empty' do - visit project_merge_requests_path(project, milestone_title: "1.0") - - expect(page).to have_selector('.empty-state') - expect(page).to have_content('Sorry, your filter produced no results') - expect(page).to have_content('To widen your search, change or remove filters above') - end - end -end diff --git a/spec/features/merge_request/user_sees_merge_request_pipelines_spec.rb b/spec/features/merge_request/user_sees_merge_request_pipelines_spec.rb index 7b319f6aff8..6647a4e9291 100644 --- a/spec/features/merge_request/user_sees_merge_request_pipelines_spec.rb +++ b/spec/features/merge_request/user_sees_merge_request_pipelines_spec.rb @@ -27,7 +27,6 @@ RSpec.describe 'Merge request > User sees pipelines triggered by merge request', before do stub_application_setting(auto_devops_enabled: false) - stub_feature_flags(ci_merge_request_pipeline: true) stub_ci_pipeline_yaml_file(YAML.dump(config)) project.add_maintainer(user) sign_in(user) diff --git a/spec/features/merge_request/user_sees_versions_spec.rb b/spec/features/merge_request/user_sees_versions_spec.rb index fb616ceae9d..8930c55a28c 100644 --- a/spec/features/merge_request/user_sees_versions_spec.rb +++ b/spec/features/merge_request/user_sees_versions_spec.rb @@ -17,6 +17,8 @@ RSpec.describe 'Merge request > User sees versions', :js do let!(:params) { {} } before do + stub_feature_flags(diffs_gradual_load: false) + project.add_maintainer(user) sign_in(user) visit diffs_project_merge_request_path(project, merge_request, params) @@ -73,12 +75,12 @@ RSpec.describe 'Merge request > User sees versions', :js do it 'shows the commit SHAs for every version in the dropdown' do page.within '.mr-version-dropdown' do - find('.btn-default').click + find('.gl-dropdown-toggle').click + end - page.within('.dropdown-content') do - shas = merge_request.merge_request_diffs.map { |diff| Commit.truncate_sha(diff.head_commit_sha) } - shas.each { |sha| expect(page).to have_content(sha) } - end + page.within '.mr-version-dropdown' do + shas = merge_request.merge_request_diffs.map { |diff| Commit.truncate_sha(diff.head_commit_sha) } + shas.each { |sha| expect(page).to have_content(sha) } end end @@ -182,7 +184,7 @@ RSpec.describe 'Merge request > User sees versions', :js do it 'has 0 chages between versions' do page.within '.mr-version-compare-dropdown' do - expect(find('.dropdown-menu-toggle')).to have_content 'version 1' + expect(find('.gl-dropdown-toggle')).to have_content 'version 1' end page.within '.mr-version-dropdown' do @@ -203,7 +205,7 @@ RSpec.describe 'Merge request > User sees versions', :js do it 'sets the compared versions to be the same' do page.within '.mr-version-compare-dropdown' do - expect(find('.dropdown-menu-toggle')).to have_content 'version 2' + expect(find('.gl-dropdown-toggle')).to have_content 'version 2' end page.within '.mr-version-dropdown' do diff --git a/spec/features/merge_request/user_squashes_merge_request_spec.rb b/spec/features/merge_request/user_squashes_merge_request_spec.rb new file mode 100644 index 00000000000..84964bd0637 --- /dev/null +++ b/spec/features/merge_request/user_squashes_merge_request_spec.rb @@ -0,0 +1,149 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User squashes a merge request', :js do + let(:user) { create(:user) } + let(:project) { create(:project, :repository) } + let(:source_branch) { 'csv' } + let(:protected_source_branch) { false } + + let!(:original_head) { project.repository.commit('master') } + + shared_examples 'squash' do + it 'squashes the commits into a single commit, and adds a merge commit', :sidekiq_might_not_need_inline do + expect(page).to have_content('Merged') + + latest_master_commits = project.repository.commits_between(original_head.sha, 'master').map(&:raw) + + squash_commit = an_object_having_attributes(sha: a_string_matching(/\h{40}/), + message: a_string_starting_with(project.merge_requests.first.default_squash_commit_message), + author_name: user.name, + committer_name: user.name) + + merge_commit = an_object_having_attributes(sha: a_string_matching(/\h{40}/), + message: a_string_starting_with("Merge branch 'csv' into 'master'"), + author_name: user.name, + committer_name: user.name) + + expect(project.repository).not_to be_merged_to_root_ref(source_branch) + expect(latest_master_commits).to match([squash_commit, merge_commit]) + end + end + + shared_examples 'no squash' do + it 'accepts the merge request without squashing', :sidekiq_might_not_need_inline do + expect(page).to have_content('Merged') + expect(project.repository).to be_merged_to_root_ref(source_branch) + end + end + + def accept_mr + expect(page).to have_button('Merge') + + uncheck 'Delete source branch' unless protected_source_branch + click_on 'Merge' + end + + before do + # Prevent source branch from being removed so we can use be_merged_to_root_ref + # method to check if squash was performed or not + allow_next_instance_of(MergeRequest) do |instance| + allow(instance).to receive(:force_remove_source_branch?).and_return(false) + end + project.add_maintainer(user) + + sign_in user + end + + context 'when the MR has only one commit' do + let(:source_branch) { 'master' } + let(:target_branch) { 'branch-merged' } + let(:protected_source_branch) { true } + let(:source_sha) { project.commit(source_branch).sha } + let(:target_sha) { project.commit(target_branch).sha } + + before do + merge_request = create(:merge_request, source_project: project, target_project: project, source_branch: source_branch, target_branch: target_branch, squash: true) + + visit project_merge_request_path(project, merge_request) + end + + it 'accepts the merge request without issuing a squash request', :sidekiq_inline do + expect_next_instance_of(Gitlab::GitalyClient::OperationService) do |instance| + expect(instance).not_to receive(:user_squash) + end + + expect(project.repository.ancestor?(source_branch, target_branch)).to be_falsey + expect(page).not_to have_field('squash') + + accept_mr + + expect(page).to have_content('Merged') + + latest_target_commits = project.repository.commits_between(source_sha, target_sha).map(&:raw) + + expect(latest_target_commits.count).to eq(1) + expect(project.repository.ancestor?(source_branch, target_branch)).to be_truthy + end + end + + context 'when squash is enabled on merge request creation', :sidekiq_might_not_need_inline do + before do + visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: source_branch }) + check 'merge_request[squash]' + click_on 'Submit merge request' + wait_for_requests + end + + it 'shows the squash checkbox as checked' do + expect(page).to have_checked_field('squash') + end + + context 'when accepting with squash checked' do + before do + accept_mr + end + + include_examples 'squash' + end + + context 'when accepting and unchecking squash' do + before do + uncheck 'squash' + accept_mr + end + + include_examples 'no squash' + end + end + + context 'when squash is not enabled on merge request creation', :sidekiq_might_not_need_inline do + before do + visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: source_branch }) + click_on 'Submit merge request' + wait_for_requests + end + + it 'shows the squash checkbox as unchecked' do + expect(page).to have_unchecked_field('squash') + end + + context 'when accepting and checking squash' do + before do + check 'squash' + accept_mr + end + + include_examples 'squash' + end + + context 'when accepting with squash unchecked' do + before do + accept_mr + end + + include_examples 'no squash' + end + end +end diff --git a/spec/features/merge_request/user_views_diffs_commit_spec.rb b/spec/features/merge_request/user_views_diffs_commit_spec.rb new file mode 100644 index 00000000000..cf92603972e --- /dev/null +++ b/spec/features/merge_request/user_views_diffs_commit_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User views diff by commit', :js do + let(:merge_request) do + create(:merge_request_with_diffs, source_project: project, target_project: project, source_branch: 'merge-test') + end + + let(:project) { create(:project, :public, :repository) } + + before do + visit(diffs_project_merge_request_path(project, merge_request, commit_id: merge_request.diff_head_sha)) + end + + it 'shows full commit description by default' do + expect(page).to have_selector('.commit-row-description', visible: true) + end +end diff --git a/spec/features/merge_request/user_views_diffs_file_by_file_spec.rb b/spec/features/merge_request/user_views_diffs_file_by_file_spec.rb index bb4bf0864c9..ad9c342df3e 100644 --- a/spec/features/merge_request/user_views_diffs_file_by_file_spec.rb +++ b/spec/features/merge_request/user_views_diffs_file_by_file_spec.rb @@ -23,12 +23,12 @@ RSpec.describe 'User views diffs file-by-file', :js do it 'shows diffs file-by-file' do page.within('#diffs') do expect(page).to have_selector('.file-holder', count: 1) - expect(page).to have_selector('.diff-file .file-title', text: '.DS_Store') + expect(page).to have_selector('.diff-file .file-title', text: 'files/ruby/popen.rb') find('.page-link.next-page-item').click expect(page).to have_selector('.file-holder', count: 1) - expect(page).to have_selector('.diff-file .file-title', text: '.gitignore') + expect(page).to have_selector('.diff-file .file-title', text: 'files/ruby/regex.rb') end end end diff --git a/spec/features/merge_request/user_views_diffs_spec.rb b/spec/features/merge_request/user_views_diffs_spec.rb index e1865fe2e14..a0b3067994c 100644 --- a/spec/features/merge_request/user_views_diffs_spec.rb +++ b/spec/features/merge_request/user_views_diffs_spec.rb @@ -22,8 +22,8 @@ RSpec.describe 'User views diffs', :js do it 'unfolds diffs upwards' do first('.js-unfold').click - page.within('.file-holder[id="a5cc2925ca8258af241be7e5b0381edf30266302"]') do - expect(find('.text-file')).to have_content('.bundle') + page.within('.file-holder[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd"]') do + expect(find('.text-file')).to have_content('fileutils') expect(page).to have_selector('.new_line [data-linenumber="1"]', count: 1) end end |