Commit ef14e6b3 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'replace_project_merge_requests.feature' into 'master'

Replace the 'project/merge_requests.feature' spinach test with an rspec analog

See merge request gitlab-org/gitlab-ce!14621
parents b3a066a3 2fc45e4d
---
title: Replace the 'project/merge_requests.feature' spinach test with an rspec analog
merge_request: 14621
author: Vitaliy @blackst0ne Klachkov
type: other
This diff is collapsed.
This diff is collapsed.
require 'spec_helper' require 'spec_helper'
feature 'Merge requests > User posts diff notes', :js do feature 'Merge requests > User posts diff notes', :js do
include MergeRequestDiffHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.source_project } let(:project) { merge_request.source_project }
...@@ -244,36 +246,6 @@ feature 'Merge requests > User posts diff notes', :js do ...@@ -244,36 +246,6 @@ feature 'Merge requests > User posts diff notes', :js do
expect(line[:num]).not_to have_css comment_button_class expect(line[:num]).not_to have_css comment_button_class
end end
def get_line_components(line_holder, diff_side = nil)
if diff_side.nil?
get_inline_line_components(line_holder)
else
get_parallel_line_components(line_holder, diff_side)
end
end
def get_inline_line_components(line_holder)
{ content: line_holder.find('.line_content', match: :first), num: line_holder.find('.diff-line-num', match: :first) }
end
def get_parallel_line_components(line_holder, diff_side = nil)
side_index = diff_side == 'left' ? 0 : 1
# Wait for `.line_content`
line_holder.find('.line_content', match: :first)
# Wait for `.diff-line-num`
line_holder.find('.diff-line-num', match: :first)
{ content: line_holder.all('.line_content')[side_index], num: line_holder.all('.diff-line-num')[side_index] }
end
def click_diff_line(line_holder, diff_side = nil)
line = get_line_components(line_holder, diff_side)
line[:content].hover
expect(line[:num]).to have_css comment_button_class
line[:num].find(comment_button_class).trigger 'click'
end
def write_comment_on_line(line_holder, diff_side) def write_comment_on_line(line_holder, diff_side)
click_diff_line(line_holder, diff_side) click_diff_line(line_holder, diff_side)
......
...@@ -62,4 +62,23 @@ describe 'User accepts a merge request', :js do ...@@ -62,4 +62,23 @@ describe 'User accepts a merge request', :js do
wait_for_requests wait_for_requests
end end
end end
context 'when modifying the merge commit message' do
before do
merge_request.mark_as_mergeable
visit(merge_request_path(merge_request))
end
it 'accepts a merge request' do
click_button('Modify commit message')
fill_in('Commit message', with: 'wow such merge')
click_button('Merge')
page.within('.status-box') do
expect(page).to have_content('Merged')
end
end
end
end end
require 'spec_helper'
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_master(user)
sign_in(user)
visit(merge_request_path(merge_request))
end
it 'closes a merge request' do
click_link('Close merge request', match: :first)
expect(page).to have_content(merge_request.title)
expect(page).to have_content('Closed by')
end
end
require 'spec_helper'
describe 'User comments on a commit', :js do
include MergeRequestDiffHelpers
include RepoHelpers
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_master(user)
sign_in(user)
visit(project_commit_path(project, sample_commit.id))
end
include_examples 'comment on merge request file'
end
require 'spec_helper'
describe 'User comments on a diff', :js do
include MergeRequestDiffHelpers
include RepoHelpers
let(:project) { create(:project, :repository) }
let(:merge_request) do
create(:merge_request_with_diffs, source_project: project, target_project: project, source_branch: 'merge-test')
end
let(:user) { create(:user) }
before do
project.add_master(user)
sign_in(user)
visit(diffs_project_merge_request_path(project, merge_request))
end
context 'when viewing comments' do
context 'when toggling inline comments' do
context 'in a single file' do
it 'hides a comment' do
click_diff_line(find("[id='#{sample_compare.changes[1][:line_code]}']"))
page.within('.js-discussion-note-form') do
fill_in('note_note', with: 'Line is wrong')
click_button('Comment')
end
page.within('.files > div:nth-child(3)') do
expect(page).to have_content('Line is wrong')
find('.js-toggle-diff-comments').trigger('click')
expect(page).not_to have_content('Line is wrong')
end
end
end
context 'in multiple files' do
it 'toggles comments' do
click_diff_line(find("[id='#{sample_compare.changes[0][:line_code]}']"))
page.within('.js-discussion-note-form') do
fill_in('note_note', with: 'Line is correct')
click_button('Comment')
end
wait_for_requests
page.within('.files > div:nth-child(2) .note-body > .note-text') do
expect(page).to have_content('Line is correct')
end
click_diff_line(find("[id='#{sample_compare.changes[1][:line_code]}']"))
page.within('.js-discussion-note-form') do
fill_in('note_note', with: 'Line is wrong')
click_button('Comment')
end
wait_for_requests
# Hide the comment.
page.within('.files > div:nth-child(3)') do
find('.js-toggle-diff-comments').trigger('click')
expect(page).not_to have_content('Line is wrong')
end
# At this moment a user should see only one comment.
# The other one should be hidden.
page.within('.files > div:nth-child(2) .note-body > .note-text') do
expect(page).to have_content('Line is correct')
end
# Show the comment.
page.within('.files > div:nth-child(3)') do
find('.js-toggle-diff-comments').trigger('click')
end
# Now both the comments should be shown.
page.within('.files > div:nth-child(3) .note-body > .note-text') do
expect(page).to have_content('Line is wrong')
end
page.within('.files > div:nth-child(2) .note-body > .note-text') do
expect(page).to have_content('Line is correct')
end
# Check the same comments in the side-by-side view.
click_link('Side-by-side')
wait_for_requests
page.within('.files > div:nth-child(3) .parallel .note-body > .note-text') do
expect(page).to have_content('Line is wrong')
end
page.within('.files > div:nth-child(2) .parallel .note-body > .note-text') do
expect(page).to have_content('Line is correct')
end
end
end
end
end
context 'when adding comments' do
include_examples 'comment on merge request file'
end
context 'when editing comments' do
it 'edits a comment' do
click_diff_line(find("[id='#{sample_commit.line_code}']"))
page.within('.js-discussion-note-form') do
fill_in(:note_note, with: 'Line is wrong')
click_button('Comment')
end
page.within('.diff-file:nth-of-type(5) .note') do
find('.js-note-edit').click
page.within('.current-note-edit-form') do
fill_in('note_note', with: 'Typo, please fix')
click_button('Save comment')
end
expect(page).not_to have_button('Save comment', disabled: true)
end
page.within('.diff-file:nth-of-type(5) .note') do
expect(page).to have_content('Typo, please fix').and have_no_content('Line is wrong')
end
end
end
context 'when deleting comments' do
it 'deletes a comment' do
click_diff_line(find("[id='#{sample_commit.line_code}']"))
page.within('.js-discussion-note-form') do
fill_in(:note_note, with: 'Line is wrong')
click_button('Comment')
end
page.within('.notes-tab .badge') do
expect(page).to have_content('1')
end
page.within('.diff-file:nth-of-type(5) .note') do
find('.more-actions').click
find('.more-actions .dropdown-menu li', match: :first)
find('.js-note-delete').click
end
page.within('.merge-request-tabs') do
find('.notes-tab').trigger('click')
end
wait_for_requests
expect(page).not_to have_css('.notes .discussion')
page.within('.notes-tab .badge') do
expect(page).to have_content('0')
end
end
end
end
require 'spec_helper'
describe 'User comments on a merge request', :js do
include RepoHelpers
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_master(user)
sign_in(user)
visit(merge_request_path(merge_request))
end
it 'adds a comment' do
page.within('.js-main-target-form') do
fill_in(:note_note, with: '# Comment with a header')
click_button('Comment')
end
wait_for_requests
page.within('.note') do
expect(page).to have_content('Comment with a header')
expect(page).not_to have_css('#comment-with-a-header')
end
end
it 'loads new comment' do
# Add new comment in background in order to check
# if it's going to be loaded automatically for current user.
create(:diff_note_on_merge_request, project: project, noteable: merge_request, author: user, note: 'Line is wrong')
# Trigger a refresh of notes.
execute_script("$(document).trigger('visibilitychange');")
wait_for_requests
page.within('.notes .discussion') do
expect(page).to have_content("#{user.name} #{user.to_reference} started a discussion")
expect(page).to have_content(sample_commit.line_code_path)
expect(page).to have_content('Line is wrong')
end
page.within('.notes-tab .badge') do
expect(page).to have_content('1')
end
end
end
require 'spec_helper'
describe 'User creates a merge request', :js do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
before do
project.add_master(user)
sign_in(user)
visit(project_new_merge_request_path(project))
end
it 'creates a merge request' do
find('.js-source-branch').click
click_link('fix')
find('.js-target-branch').click
click_link('feature')
click_button('Compare branches')
fill_in('merge_request_title', with: 'Wiki Feature')
click_button('Submit merge request')
page.within('.merge-request') do
expect(page).to have_content('Wiki Feature')
end
wait_for_requests
end
end
require 'spec_helper'
describe 'User edits a merge request', :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_master(user)
sign_in(user)
visit(edit_project_merge_request_path(project, merge_request))
end
it 'changes the target branch' do
expect(page).to have_content('Target branch')
first('.target_branch').click
select('merge-test', from: 'merge_request_target_branch', visible: false)
click_button('Save changes')
expect(page).to have_content("Request to merge #{merge_request.source_branch} into merge-test")
expect(page).to have_content("changed target branch from #{merge_request.target_branch} to merge-test")
end
end
require 'spec_helper'
describe 'User manages subscription', :js do
let(:project) { create(:project, :public, :repository) }
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:user) { create(:user) }
before do
project.add_master(user)
sign_in(user)
visit(merge_request_path(merge_request))
end
it 'toggles subscription' do
subscribe_button = find('.issuable-subscribe-button span')
expect(subscribe_button).to have_content('Subscribe')
click_on('Subscribe')
wait_for_requests
expect(subscribe_button).to have_content('Unsubscribe')
click_on('Unsubscribe')
wait_for_requests
expect(subscribe_button).to have_content('Subscribe')
end
end
require 'spec_helper'
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_master(user)
sign_in(user)
visit(merge_request_path(merge_request))
end
it 'reopens a merge request' do
click_link('Reopen merge request', match: :first)
page.within('.status-box') do
expect(page).to have_content('Open')
end
end
end
require 'spec_helper'
describe 'User sorts merge requests' do
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let!(:merge_request2) do
create(:merge_request_with_diffs, source_project: project, target_project: project, source_branch: 'merge-test')
end
let(:project) { create(:project, :public, :repository) }
let(:user) { create(:user) }
before do
project.add_master(user)
sign_in(user)
visit(project_merge_requests_path(project))
end
it 'keeps the sort option' do
find('button.dropdown-toggle').click
page.within('.content ul.dropdown-menu.dropdown-menu-align-right li') do
click_link('Last updated')
end
visit(merge_requests_dashboard_path(assignee_id: user.id))
expect(find('.issues-filters')).to have_content('Last updated')
visit(project_merge_requests_path(project))
expect(find('.issues-filters')).to have_content('Last updated')
end
context 'when merge requests have awards' do
before do
create_list(:award_emoji, 2, awardable: merge_request)
create(:award_emoji, :downvote, awardable: merge_request)
create(:award_emoji, awardable: merge_request2)
create_list(:award_emoji, 2, :downvote, awardable: merge_request2)
end
it 'sorts by popularity' do
find('button.dropdown-toggle').click
page.within('.content ul.dropdown-menu.dropdown-menu-align-right li') do
click_link('Popularity')
end
page.within('.mr-list') do
page.within('li.merge-request:nth-child(1)') do
expect(page).to have_content(merge_request.title)
expect(page).to have_content('2 1')
end
page.within('li.merge-request:nth-child(2)') do
expect(page).to have_content(merge_request2.title)
expect(page).to have_content('1 2')
end
end
end
end
end
require 'spec_helper'
describe 'User views all merge requests' do
let!(:closed_merge_request) { create(:closed_merge_request, source_project: project, target_project: project) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:project) { create(:project, :public) }
before do
visit(project_merge_requests_path(project, state: :all))
end
it 'shows all merge requests' do
expect(page).to have_content(merge_request.title).and have_content(closed_merge_request.title)
end
end
require 'spec_helper'
describe 'User views closed merge requests' do
let!(:closed_merge_request) { create(:closed_merge_request, source_project: project, target_project: project) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:project) { create(:project, :public) }
before do
visit(project_merge_requests_path(project, state: :closed))
end
it 'shows closed merge requests' do
expect(page).to have_content(closed_merge_request.title).and have_no_content(merge_request.title)
end
end
require 'spec_helper'
describe 'User views diffs', :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))
wait_for_requests
end
shared_examples 'unfold diffs' do
it 'unfolds diffs' do
first('.js-unfold').click
expect(first('.text-file')).to have_content('.bundle')
end
end
it 'shows diffs' do
expect(page).to have_css('.tab-content #diffs.active')
expect(page).to have_css('#parallel-diff-btn', count: 1)
expect(page).to have_css('#inline-diff-btn', count: 1)
end
context 'when in the inline view' do
include_examples 'unfold diffs'
end
context 'when in the side-by-side view' do
before do
click_link('Side-by-side')
wait_for_requests
end
it 'shows diffs in parallel' do
expect(page).to have_css('.parallel')
end
include_examples 'unfold diffs'
end
end
require 'spec_helper'
describe 'User views merged merge requests' do
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let!(:merged_merge_request) { create(:merged_merge_request, source_project: project, target_project: project) }
let(:project) { create(:project, :public) }
before do
visit(project_merge_requests_path(project, state: :merged))
end
it 'shows merged merge requests' do
expect(page).to have_content(merged_merge_request.title).and have_no_content(merge_request.title)
end
end
require 'spec_helper'
describe 'User views an open merge request' do
let(:merge_request) do
create(:merge_request, source_project: project, target_project: project, description: '# Description header')
end
context 'when a merge request does not have repository' do
let(:project) { create(:project, :public) }
before do
visit(merge_request_path(merge_request))
end
it 'renders both the title and the description' do
node = find('.wiki h1 a#user-content-description-header')
expect(node[:href]).to end_with('#description-header')
# Work around a weird Capybara behavior where calling `parent` on a node
# returns the whole document, not the node's actual parent element
expect(find(:xpath, "#{node.path}/..").text).to eq(merge_request.description[2..-1])
expect(page).to have_content(merge_request.title).and have_content(merge_request.description)
end
end
context 'when a merge request has repository', :js do
let(:project) { create(:project, :public, :repository) }
context 'when rendering description preview' do
let(:user) { create(:user) }
before do
project.add_master(user)
sign_in(user)
visit(edit_project_merge_request_path(project, merge_request))
end
it 'renders empty description preview' do
find('.gfm-form').fill_in(:merge_request_description, with: '')
page.within('.gfm-form') do
click_link('Preview')
expect(find('.js-md-preview')).to have_content('Nothing to preview.')
end
end
it 'renders description preview' do
find('.gfm-form').fill_in(:merge_request_description, with: ':+1: Nice')
page.within('.gfm-form') do
click_link('Preview')
expect(find('.js-md-preview')).to have_css('gl-emoji')
end
expect(find('.gfm-form')).to have_css('.js-md-preview').and have_link('Write')
expect(find('#merge_request_description', visible: false)).not_to be_visible
end
end
context 'when the branch is rebased on the target' do
let(:merge_request) { create(:merge_request, :rebased, source_project: project, target_project: project) }
before do
visit(merge_request_path(merge_request))
end
it 'does not show diverged commits count' do
page.within('.mr-source-target') do
expect(page).not_to have_content(/([0-9]+ commit[s]? behind)/)
end
end
end
context 'when the branch is diverged on the target' do
let(:merge_request) { create(:merge_request, :diverged, source_project: project, target_project: project) }
before do
visit(merge_request_path(merge_request))
end
it 'shows diverged commits count' do
page.within('.mr-source-target') do
expect(page).to have_content(/([0-9]+ commits behind)/)
end
end
end
end
end
require 'spec_helper'
describe 'User views open merge requests' do
let(:project) { create(:project, :public, :repository) }
context "when the target branch is the project's default branch" do
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let!(:closed_merge_request) { create(:closed_merge_request, source_project: project, target_project: project) }
before do
visit(project_merge_requests_path(project))
end
it 'shows open merge requests' do
expect(page).to have_content(merge_request.title).and have_no_content(closed_merge_request.title)
end
it 'does not show target branch name' do
expect(page).to have_content(merge_request.title)
expect(find('.issuable-info')).not_to have_content(project.default_branch)
end
end
context "when the target branch is different from the project's default branch" do
let!(:merge_request) do
create(:merge_request,
source_project: project,
target_project: project,
source_branch: 'fix',
target_branch: 'feature_conflict')
end
before do
visit(project_merge_requests_path(project))
end
it 'shows target branch name' do
expect(page).to have_content(merge_request.target_branch)
end
end
context 'when a merge request has pipelines' do
let!(:build) { create :ci_build, pipeline: pipeline }
let(:merge_request) do
create(:merge_request_with_diffs,
source_project: project,
target_project: project,
source_branch: 'merge-test')
end
let(:pipeline) do
create(:ci_pipeline,
project: project,
sha: merge_request.diff_head_sha,
ref: merge_request.source_branch,
head_pipeline_of: merge_request)
end
before do
project.enable_ci
visit(project_merge_requests_path(project))
end
it 'shows pipeline status' do
page.within('.mr-list') do
expect(page).to have_link('Pipeline: pending')
end
end
end
end
module MergeRequestDiffHelpers
def click_diff_line(line_holder, diff_side = nil)
line = get_line_components(line_holder, diff_side)
line[:content].hover
line[:num].find('.add-diff-note').trigger('click')
end
def get_line_components(line_holder, diff_side = nil)
if diff_side.nil?
get_inline_line_components(line_holder)
else
get_parallel_line_components(line_holder, diff_side)
end
end
def get_inline_line_components(line_holder)
{ content: line_holder.find('.line_content', match: :first), num: line_holder.find('.diff-line-num', match: :first) }
end
def get_parallel_line_components(line_holder, diff_side = nil)
side_index = diff_side == 'left' ? 0 : 1
# Wait for `.line_content`
line_holder.find('.line_content', match: :first)
# Wait for `.diff-line-num`
line_holder.find('.diff-line-num', match: :first)
{ content: line_holder.all('.line_content')[side_index], num: line_holder.all('.diff-line-num')[side_index] }
end
end
shared_examples 'comment on merge request file' do
it 'adds a comment' do
click_diff_line(find("[id='#{sample_commit.line_code}']"))
page.within('.js-discussion-note-form') do
fill_in(:note_note, with: 'Line is wrong')
click_button('Comment')
end
wait_for_requests
page.within('.notes_holder') do
expect(page).to have_content('Line is wrong')
end
visit(merge_request_path(merge_request))
page.within('.notes .discussion') do
expect(page).to have_content("#{user.name} #{user.to_reference} started a discussion")
expect(page).to have_content(sample_commit.line_code_path)
expect(page).to have_content('Line is wrong')
end
page.within('.notes-tab .badge') do
expect(page).to have_content('1')
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