Improve MR feature specs and reduce duplication

Signed-off-by: Rémy Coutable's avatarRémy Coutable <remy@rymai.me>
parent 50a64953
Pipeline #16320742 passed with stages
in 69 minutes and 22 seconds
require 'rails_helper'
describe 'Merge request > User assigns themselves' do
let(:project) { create(:project, :public, :repository) }
let(:user) { project.creator }
let(:issue1) { create(:issue, project: project) }
let(:issue2) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, :simple, source_project: project, author: user, description: "fixes #{issue1.to_reference} and #{issue2.to_reference}") }
context 'logged in as a member of the project' do
before do
sign_in(user)
visit project_merge_request_path(project, merge_request)
end
it 'updates related issues', :js do
click_link 'Assign yourself to these issues'
expect(page).to have_content '2 issues have been assigned to you'
end
it 'returns user to the merge request', :js do
click_link 'Assign yourself to these issues'
expect(page).to have_content merge_request.description
end
context 'when related issues are already assigned' do
before do
[issue1, issue2].each { |issue| issue.update!(assignees: [user]) }
end
it 'does not display if related issues are already assigned' do
expect(page).not_to have_content 'Assign yourself'
end
end
end
context 'logged in as a non-member of the project' do
before do
sign_in(create(:user))
visit project_merge_request_path(project, merge_request)
end
it 'does not not show assignment link' do
expect(page).not_to have_content 'Assign yourself'
end
end
end
require 'rails_helper'
feature 'Merge request awards', :js do
let(:user) { create(:user) }
describe 'Merge request > User awards emoji', :js do
let(:project) { create(:project, :public, :repository) }
let(:user) { project.creator }
let(:merge_request) { create(:merge_request, source_project: project) }
describe 'logged in' do
......
require 'spec_helper'
require 'rails_helper'
describe 'Cherry-pick Merge Requests', :js do
let(:user) { create(:user) }
describe 'Merge request > User cherry-picks', :js do
let(:group) { create(:group) }
let(:project) { create(:project, :repository, namespace: group) }
let(:user) { project.creator }
let(:merge_request) { create(:merge_request_with_diffs, source_project: project, author: user) }
before do
sign_in user
project.add_master(user)
sign_in(user)
end
context "Viewing a merged merge request" do
context 'Viewing a merged merge request' do
before do
service = MergeRequests::MergeService.new(project, user)
......@@ -21,24 +21,24 @@ describe 'Cherry-pick Merge Requests', :js do
end
# Fast-forward merge, or merged before GitLab 8.5.
context "Without a merge commit" do
context 'Without a merge commit' do
before do
merge_request.merge_commit_sha = nil
merge_request.save
end
it "doesn't show a Cherry-pick button" do
it 'does not show a Cherry-pick button' do
visit project_merge_request_path(project, merge_request)
expect(page).not_to have_link "Cherry-pick"
expect(page).not_to have_link 'Cherry-pick'
end
end
context "With a merge commit" do
it "shows a Cherry-pick button" do
context 'With a merge commit' do
it 'shows a Cherry-pick button' do
visit project_merge_request_path(project, merge_request)
expect(page).to have_link "Cherry-pick"
expect(page).to have_link 'Cherry-pick'
end
end
end
......
require 'spec_helper'
feature 'image diff notes', :js do
feature 'Merge request > User creates image diff notes', :js do
include NoteInteractionHelpers
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:user) { project.creator }
before do
project.add_master(user)
sign_in user
sign_in(user)
# Stub helper to return any blob file as image from public app folder.
# This is necessary to run this specs since we don't display repo images in capybara.
......@@ -25,20 +24,14 @@ feature 'image diff notes', :js do
create_image_diff_note
end
it 'shows indicator badge on image diff' do
it 'shows indicator and avatar badges, and allows collapsing/expanding the discussion notes' do
indicator = find('.js-image-badge')
expect(indicator).to have_content('1')
end
it 'shows the avatar badge on the new note' do
badge = find('.image-diff-avatar-link .badge')
expect(indicator).to have_content('1')
expect(badge).to have_content('1')
end
it 'allows collapsing/expanding the discussion notes' do
find('.js-diff-notes-toggle', :first).click
find('.js-diff-notes-toggle').click
expect(page).not_to have_content('image diff test comment')
......@@ -86,15 +79,9 @@ feature 'image diff notes', :js do
wait_for_requests
end
it 'render diff indicators within the image diff frame' do
it 'render diff indicators within the image diff frame, diff notes, and avatar badge numbers' do
expect(page).to have_css('.js-image-badge', count: 2)
end
it 'shows the diff notes' do
expect(page).to have_css('.diff-content .note', count: 2)
end
it 'shows the diff notes with correct avatar badge numbers' do
expect(page).to have_css('.image-diff-avatar-link', text: 1)
expect(page).to have_css('.image-diff-avatar-link', text: 2)
end
......@@ -127,19 +114,13 @@ feature 'image diff notes', :js do
create_image_diff_note
end
it 'shows indicator badge on image diff' do
it 'shows indicator and avatar badges, and allows collapsing/expanding the discussion notes' do
indicator = find('.js-image-badge', match: :first)
expect(indicator).to have_content('1')
end
it 'shows the avatar badge on the new note' do
badge = find('.image-diff-avatar-link .badge', match: :first)
expect(indicator).to have_content('1')
expect(badge).to have_content('1')
end
it 'allows expanding/collapsing the discussion notes' do
page.all('.js-diff-notes-toggle')[0].click
page.all('.js-diff-notes-toggle')[1].click
......@@ -154,7 +135,7 @@ feature 'image diff notes', :js do
end
end
describe 'discussion tab polling', :js do
describe 'discussion tab polling' do
let(:merge_request) { create(:merge_request_with_diffs, :with_image_diffs, source_project: project, author: user) }
let(:path) { "files/images/ee_repo_logo.png" }
......
require 'rails_helper'
describe 'Merge request > User creates MR' do
it_behaves_like 'a creatable merge request'
context 'from a forked project' do
include ProjectForksHelper
let(:canonical_project) { create(:project, :public, :repository) }
let(:source_project) do
fork_project(canonical_project, user,
repository: true,
namespace: user.namespace)
end
context 'to canonical project' do
it_behaves_like 'a creatable merge request'
end
context 'to another forked project' do
let(:target_project) do
fork_project(canonical_project, user,
repository: true,
namespace: user.namespace)
end
it_behaves_like 'a creatable merge request'
end
end
end
require 'spec_helper'
require 'rails_helper'
feature 'Clicking toggle commit message link', :js do
let(:user) { create(:user) }
describe 'Merge request < User customizes merge commit message', :js do
let(:project) { create(:project, :public, :repository) }
let(:user) { project.creator }
let(:issue_1) { create(:issue, project: project)}
let(:issue_2) { create(:issue, project: project)}
let(:merge_request) do
......@@ -33,17 +33,14 @@ feature 'Clicking toggle commit message link', :js do
before do
project.add_master(user)
sign_in user
sign_in(user)
visit project_merge_request_path(project, merge_request)
end
it 'toggles commit message between message with description and without description' do
expect(page).not_to have_selector('.js-commit-message')
click_button "Modify commit message"
expect(textbox).to be_visible
end
it "toggles commit message between message with description and without description " do
expect(textbox.value).to eq(default_message)
click_link "Include description in commit message"
......
require 'rails_helper'
describe 'Merge request > User edits MR' do
it_behaves_like 'an editable merge request'
context 'for a forked project' do
it_behaves_like 'an editable merge request' do
let(:source_project) { create(:project, :repository, forked_from_project: target_project) }
end
end
end
require 'spec_helper'
require 'rails_helper'
describe 'Discussion Lock', :js do
describe 'Merge request > User locks discussion', :js do
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request, source_project: project, author: user) }
let(:project) { create(:project, :public, :repository) }
let(:merge_request) { create(:merge_request, source_project: project) }
before do
sign_in(user)
......
require 'spec_helper'
require 'rails_helper'
feature 'Merge immediately', :js do
let(:user) { create(:user) }
describe 'Merge requests > User merges immediately', :js do
let(:project) { create(:project, :public, :repository) }
let(:user) { project.creator }
let!(:merge_request) do
create(:merge_request_with_diffs, source_project: project,
author: user,
......@@ -11,25 +10,18 @@ feature 'Merge immediately', :js do
head_pipeline: pipeline,
source_branch: pipeline.ref)
end
let(:pipeline) do
create(:ci_pipeline, project: project,
ref: 'master',
sha: project.repository.commit('master').id)
end
before do
project.add_master(user)
end
context 'when there is active pipeline for merge request' do
background do
create(:ci_build, pipeline: pipeline)
end
before do
sign_in user
visit project_merge_request_path(merge_request.project, merge_request)
create(:ci_build, pipeline: pipeline)
project.add_master(user)
sign_in(user)
visit project_merge_request_path(project, merge_request)
end
it 'enables merge immediately' do
......
require 'spec_helper'
require 'rails_helper'
feature 'Only allow merge requests to be merged if the pipeline succeeds', :js do
describe 'Merge request > User merges only if pipeline succeeds', :js do
let(:merge_request) { create(:merge_request_with_diffs) }
let(:project) { merge_request.target_project }
before do
sign_in merge_request.author
project.add_master(merge_request.author)
sign_in(merge_request.author)
end
context 'project does not have CI enabled', :js do
context 'project does not have CI enabled' do
it 'allows MR to be merged' do
visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
wait_for_requests
......@@ -20,8 +19,8 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', :js d
end
end
context 'when project has CI enabled', :js do
given!(:pipeline) do
context 'when project has CI enabled' do
let!(:pipeline) do
create(:ci_empty_pipeline,
project: project,
sha: merge_request.diff_head_sha,
......@@ -35,10 +34,10 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', :js d
end
context 'when CI is running' do
given(:status) { :running }
let(:status) { :running }
it 'does not allow to merge immediately' do
visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
wait_for_requests
......@@ -48,10 +47,10 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', :js d
end
context 'when CI failed' do
given(:status) { :failed }
let(:status) { :failed }
it 'does not allow MR to be merged' do
visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
wait_for_requests
......@@ -61,10 +60,10 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', :js d
end
context 'when CI canceled' do
given(:status) { :canceled }
let(:status) { :canceled }
it 'does not allow MR to be merged' do
visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
wait_for_requests
......@@ -74,10 +73,10 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', :js d
end
context 'when CI succeeded' do
given(:status) { :success }
let(:status) { :success }
it 'allows MR to be merged' do
visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
wait_for_requests
......@@ -86,10 +85,10 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', :js d
end
context 'when CI skipped' do
given(:status) { :skipped }
let(:status) { :skipped }
it 'allows MR to be merged' do
visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
wait_for_requests
......@@ -104,10 +103,10 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', :js d
end
context 'when CI is running' do
given(:status) { :running }
let(:status) { :running }
it 'allows MR to be merged immediately' do
visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
wait_for_requests
......@@ -119,10 +118,10 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', :js d
end
context 'when CI failed' do
given(:status) { :failed }
let(:status) { :failed }
it 'allows MR to be merged' do
visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
wait_for_requests
......@@ -131,10 +130,10 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', :js d
end
context 'when CI succeeded' do
given(:status) { :success }
let(:status) { :success }
it 'allows MR to be merged' do
visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
wait_for_requests
......@@ -143,8 +142,4 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', :js d
end
end
end
def visit_merge_request(merge_request)
visit project_merge_request_path(merge_request.project, merge_request)
end
end
require 'spec_helper'
require 'rails_helper'
feature 'Merge When Pipeline Succeeds', :js do
let(:user) { create(:user) }
describe 'Merge request > User merges when pipeline succeeds', :js do
let(:project) { create(:project, :public, :repository) }
let(:user) { project.creator }
let(:merge_request) do
create(:merge_request_with_diffs, source_project: project,
author: user,
title: 'Bug NS-04',
merge_params: { force_remove_source_branch: '1' })
end
let(:pipeline) do
create(:ci_pipeline, project: project,
sha: merge_request.diff_head_sha,
......@@ -23,17 +21,10 @@ feature 'Merge When Pipeline Succeeds', :js do
end
context 'when there is active pipeline for merge request' do
background do
create(:ci_build, pipeline: pipeline)
end
before do
sign_in user
visit_merge_request(merge_request)
end
it 'displays the Merge when pipeline succeeds button' do
expect(page).to have_button "Merge when pipeline succeeds"
create(:ci_build, pipeline: pipeline)
sign_in(user)
visit project_merge_request_path(project, merge_request)
end
describe 'enabling Merge when pipeline succeeds' do
......@@ -44,7 +35,7 @@ feature 'Merge When Pipeline Succeeds', :js do
expect(page).to have_content "Set by #{user.name} to be merged automatically when the pipeline succeeds"
expect(page).to have_content "The source branch will not be removed"
expect(page).to have_selector ".js-cancel-auto-merge"
visit_merge_request(merge_request) # Needed to refresh the page
visit project_merge_request_path(project, merge_request) # Needed to refresh the page
expect(page).to have_content /enabled an automatic merge when the pipeline for \h{8} succeeds/i
end
end
......@@ -115,14 +106,13 @@ feature 'Merge When Pipeline Succeeds', :js do
title: 'MepMep',
merge_when_pipeline_succeeds: true)
end
let!(:build) do
create(:ci_build, pipeline: pipeline)
end
before do
sign_in user
visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
end
it 'allows to cancel the automatic merge' do
......@@ -130,31 +120,67 @@ feature 'Merge When Pipeline Succeeds', :js do
expect(page).to have_button "Merge when pipeline succeeds"
visit_merge_request(merge_request) # refresh the page
refresh
expect(page).to have_content "canceled the automatic merge"
end
context 'when pipeline succeeds' do
background { build.success }
before do
build.success
refresh
end
it 'merges merge request' do
visit_merge_request(merge_request) # refresh the page
expect(page).to have_content 'The changes were merged'
expect(merge_request.reload).to be_merged
end
end
context 'view merge request with MWPS enabled but automatically merge fails' do
before do
merge_request.update(
merge_user: merge_request.author,
merge_error: 'Something went wrong'
)
refresh
end
it 'shows information about the merge error' do
# Wait for the `ci_status` and `merge_check` requests
wait_for_requests
page.within('.mr-widget-body') do
expect(page).to have_content('Something went wrong')
end
end
end
context 'view merge request with MWPS enabled but automatically merge fails' do
before do
merge_request.update(
merge_user: merge_request.author,
merge_error: 'Something went wrong'
)
refresh
end
it 'shows information about the merge error' do
# Wait for the `ci_status` and `merge_check` requests
wait_for_requests
page.within('.mr-widget-body') do
expect(page).to have_content('Something went wrong')
end
end
end
end
context 'when pipeline is not active' do
it "does not allow to enable merge when pipeline succeeds" do
visit_merge_request(merge_request)
it 'does not allow to enable merge when pipeline succeeds' do
visit project_merge_request_path(project, merge_request)
expect(page).not_to have_link 'Merge when pipeline succeeds'
end
end
def visit_merge_request(merge_request)
visit project_merge_request_path(merge_request.project, merge_request)
end
end
require 'spec_helper'
require 'rails_helper'
feature 'Merge requests > User posts diff notes', :js do
describe 'Merge request > User posts diff notes', :js do
include MergeRequestDiffHelpers
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.source_project }
let(:user) { project.creator }
let(:comment_button_class) { '.add-diff-note' }
let(:notes_holder_input_class) { 'js-temp-notes-holder' }
let(:notes_holder_input_xpath) { './following-sibling::*[contains(concat(" ", @class, " "), " notes_holder ")]' }
let(:test_note_comment) { 'this is a test note!' }
before do
set_cookie('sidebar_collapsed', 'true')
......@@ -14,11 +18,6 @@ feature 'Merge requests > User posts diff notes', :js do
sign_in(user)
end
let(:comment_button_class) { '.add-diff-note' }
let(:notes_holder_input_class) { 'js-temp-notes-holder' }
let(:notes_holder_input_xpath) { './following-sibling::*[contains(concat(" ", @class, " "), " notes_holder ")]' }
let(:test_note_comment) { 'this is a test note!' }
context 'when hovering over a parallel view diff file' do
before do
visit diffs_project_merge_request_path(project, merge_request, view: 'parallel')
......
require 'spec_helper'
require 'rails_helper'
describe 'Merge requests > User posts notes', :js do
describe 'Merge request > User posts notes', :js do
include NoteInteractionHelpers
let(:project) { create(:project, :repository) }
let(:user) { project.creator }
let(:merge_request) do
create(:merge_request, source_project: project, target_project: project)
end
......@@ -13,7 +14,8 @@ describe 'Merge requests > User posts notes', :js do
end
before do
sign_in(create(:admin))
project.add_master(user)
sign_in(user)