2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2017-04-12 15:02:53 +00:00
|
|
|
|
2017-08-01 18:03:07 +00:00
|
|
|
describe 'Merge request > User posts diff notes', :js do
|
2017-10-04 22:31:34 +00:00
|
|
|
include MergeRequestDiffHelpers
|
2017-09-22 18:15:43 +00:00
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
let(:project) { merge_request.source_project }
|
2017-08-01 18:03:07 +00:00
|
|
|
let(:user) { project.creator }
|
|
|
|
let(:comment_button_class) { '.add-diff-note' }
|
2018-09-05 17:10:30 +00:00
|
|
|
let(:notes_holder_input_class) { 'js-temp-notes-holder' }
|
2017-08-01 18:03:07 +00:00
|
|
|
let(:notes_holder_input_xpath) { './following-sibling::*[contains(concat(" ", @class, " "), " notes_holder ")]' }
|
|
|
|
let(:test_note_comment) { 'this is a test note!' }
|
2017-04-12 15:02:53 +00:00
|
|
|
|
|
|
|
before do
|
2017-09-22 18:15:43 +00:00
|
|
|
set_cookie('sidebar_collapsed', 'true')
|
2017-08-30 13:40:07 +00:00
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
project.add_developer(user)
|
2017-06-21 23:44:10 +00:00
|
|
|
sign_in(user)
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when hovering over a parallel view diff file' do
|
|
|
|
before do
|
2017-07-06 16:20:50 +00:00
|
|
|
visit diffs_project_merge_request_path(project, merge_request, view: 'parallel')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an old line on the left and no line on the right' do
|
|
|
|
it 'allows commenting on the left side' do
|
|
|
|
should_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..'), 'left')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow commenting on the right side' do
|
|
|
|
should_not_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..'), 'right')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no line on the left and a new line on the right' do
|
|
|
|
it 'does not allow commenting on the left side' do
|
|
|
|
should_not_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'left')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows commenting on the right side' do
|
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'right')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an old line on the left and a new line on the right' do
|
2020-02-06 18:08:54 +00:00
|
|
|
it 'allows commenting on the left side', quarantine: 'https://gitlab.com/gitlab-org/gitlab/issues/199050' do
|
2017-04-12 15:02:53 +00:00
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'left')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows commenting on the right side' do
|
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'right')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unchanged line on the left and an unchanged line on the right' do
|
2020-01-20 18:08:44 +00:00
|
|
|
it 'allows commenting on the left side', quarantine: 'https://gitlab.com/gitlab-org/gitlab/issues/196826' do
|
2017-04-12 15:02:53 +00:00
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'left')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows commenting on the right side' do
|
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'right')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a match line' do
|
|
|
|
it 'does not allow commenting on the left side' do
|
2018-06-21 12:22:40 +00:00
|
|
|
line_holder = find('.match', match: :first).find(:xpath, '..')
|
2019-08-10 02:36:32 +00:00
|
|
|
match_should_not_allow_commenting(line_holder)
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow commenting on the right side' do
|
2018-06-21 12:22:40 +00:00
|
|
|
line_holder = find('.match', match: :first).find(:xpath, '..')
|
2019-08-10 02:36:32 +00:00
|
|
|
match_should_not_allow_commenting(line_holder)
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unfolded line' do
|
2017-08-10 22:31:42 +00:00
|
|
|
before do
|
2017-10-12 22:22:14 +00:00
|
|
|
find('.js-unfold', match: :first).click
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# The first `.js-unfold` unfolds upwards, therefore the first
|
|
|
|
# `.line_holder` will be an unfolded line.
|
2018-06-21 12:22:40 +00:00
|
|
|
let(:line_holder) { first('#a5cc2925ca8258af241be7e5b0381edf30266302 .line_holder') }
|
2017-04-12 15:02:53 +00:00
|
|
|
|
2018-10-16 16:21:16 +00:00
|
|
|
it 'allows commenting on the left side' do
|
|
|
|
should_allow_commenting(line_holder, 'left')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
2018-10-16 16:21:16 +00:00
|
|
|
it 'allows commenting on the right side' do
|
|
|
|
# Automatically shifts comment box to left side.
|
|
|
|
should_allow_commenting(line_holder, 'right')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when hovering over an inline view diff file' do
|
|
|
|
before do
|
2017-07-06 16:20:50 +00:00
|
|
|
visit diffs_project_merge_request_path(project, merge_request, view: 'inline')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
2017-09-05 10:20:40 +00:00
|
|
|
context 'after deleteing a note' do
|
|
|
|
it 'allows commenting' do
|
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
|
|
|
|
2017-10-12 22:33:39 +00:00
|
|
|
accept_confirm do
|
|
|
|
first('button.more-actions-toggle').click
|
|
|
|
first('.js-note-delete').click
|
|
|
|
end
|
2017-09-05 10:20:40 +00:00
|
|
|
|
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
context 'with a new line' do
|
|
|
|
it 'allows commenting' do
|
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an old line' do
|
|
|
|
it 'allows commenting' do
|
|
|
|
should_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unchanged line' do
|
|
|
|
it 'allows commenting' do
|
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a match line' do
|
|
|
|
it 'does not allow commenting' do
|
2019-08-10 02:36:32 +00:00
|
|
|
match_should_not_allow_commenting(find('.match', match: :first))
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unfolded line' do
|
2017-08-10 22:31:42 +00:00
|
|
|
before do
|
2017-10-12 22:22:14 +00:00
|
|
|
find('.js-unfold', match: :first).click
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# The first `.js-unfold` unfolds upwards, therefore the first
|
|
|
|
# `.line_holder` will be an unfolded line.
|
2018-06-21 12:22:40 +00:00
|
|
|
let(:line_holder) { first('.line_holder[id="a5cc2925ca8258af241be7e5b0381edf30266302_1_1"]') }
|
2017-04-12 15:02:53 +00:00
|
|
|
|
2018-10-16 16:21:16 +00:00
|
|
|
it 'allows commenting' do
|
|
|
|
should_allow_commenting line_holder
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when hovering over a diff discussion' do
|
|
|
|
before do
|
2017-07-06 16:20:50 +00:00
|
|
|
visit diffs_project_merge_request_path(project, merge_request, view: 'inline')
|
2017-04-12 15:02:53 +00:00
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]'))
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_merge_request_path(project, merge_request)
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow commenting' do
|
|
|
|
should_not_allow_commenting(find('.line_holder', match: :first))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when cancelling the comment addition' do
|
|
|
|
before do
|
2017-07-06 16:20:50 +00:00
|
|
|
visit diffs_project_merge_request_path(project, merge_request, view: 'inline')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a new line' do
|
|
|
|
it 'allows dismissing a comment' do
|
|
|
|
should_allow_dismissing_a_comment(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-25 08:19:36 +00:00
|
|
|
describe 'with multiple note forms' do
|
2017-04-12 15:02:53 +00:00
|
|
|
before do
|
2017-07-06 16:20:50 +00:00
|
|
|
visit diffs_project_merge_request_path(project, merge_request, view: 'inline')
|
2017-04-12 15:02:53 +00:00
|
|
|
click_diff_line(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
|
|
|
click_diff_line(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'))
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'posting a note' do
|
2018-07-20 13:50:26 +00:00
|
|
|
it 'adds as discussion' do
|
2017-04-12 15:02:53 +00:00
|
|
|
should_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'), asset_form_reset: false)
|
2018-07-20 13:50:26 +00:00
|
|
|
expect(page).to have_css('.notes_holder .note.note-discussion', count: 1)
|
2017-04-12 15:02:53 +00:00
|
|
|
expect(page).to have_button('Reply...')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the MR only supports legacy diff notes' do
|
|
|
|
before do
|
2018-07-02 10:43:06 +00:00
|
|
|
merge_request.merge_request_diff.update(start_commit_sha: nil)
|
2017-07-06 16:20:50 +00:00
|
|
|
visit diffs_project_merge_request_path(project, merge_request, view: 'inline')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a new line' do
|
2018-09-10 18:41:57 +00:00
|
|
|
it 'allows commenting' do
|
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an old line' do
|
2018-09-10 18:41:57 +00:00
|
|
|
it 'allows commenting' do
|
|
|
|
should_allow_commenting(find('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'))
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unchanged line' do
|
2018-09-10 18:41:57 +00:00
|
|
|
it 'allows commenting' do
|
|
|
|
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]'))
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a match line' do
|
|
|
|
it 'does not allow commenting' do
|
2019-08-10 02:36:32 +00:00
|
|
|
match_should_not_allow_commenting(find('.match', match: :first))
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_allow_commenting(line_holder, diff_side = nil, asset_form_reset: true)
|
|
|
|
write_comment_on_line(line_holder, diff_side)
|
|
|
|
|
|
|
|
click_button 'Comment'
|
2017-10-07 04:25:17 +00:00
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-04-12 15:02:53 +00:00
|
|
|
|
|
|
|
assert_comment_persistence(line_holder, asset_form_reset: asset_form_reset)
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_allow_dismissing_a_comment(line_holder, diff_side = nil)
|
|
|
|
write_comment_on_line(line_holder, diff_side)
|
|
|
|
|
2017-06-17 06:08:27 +00:00
|
|
|
find('.js-close-discussion-note-form').click
|
2017-04-12 15:02:53 +00:00
|
|
|
|
|
|
|
assert_comment_dismissal(line_holder)
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_not_allow_commenting(line_holder, diff_side = nil)
|
|
|
|
line = get_line_components(line_holder, diff_side)
|
|
|
|
line[:content].hover
|
|
|
|
expect(line[:num]).not_to have_css comment_button_class
|
|
|
|
end
|
|
|
|
|
2019-08-10 02:36:32 +00:00
|
|
|
def match_should_not_allow_commenting(line_holder)
|
|
|
|
expect(line_holder).not_to have_css comment_button_class
|
|
|
|
end
|
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
def write_comment_on_line(line_holder, diff_side)
|
|
|
|
click_diff_line(line_holder, diff_side)
|
|
|
|
|
|
|
|
notes_holder_input = line_holder.find(:xpath, notes_holder_input_xpath)
|
|
|
|
|
|
|
|
expect(notes_holder_input[:class]).to include(notes_holder_input_class)
|
|
|
|
|
|
|
|
notes_holder_input.fill_in 'note[note]', with: test_note_comment
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_comment_persistence(line_holder, asset_form_reset:)
|
|
|
|
notes_holder_saved = line_holder.find(:xpath, notes_holder_input_xpath)
|
|
|
|
|
2018-09-05 12:05:03 +00:00
|
|
|
expect(notes_holder_saved[:class]).not_to include('note-edit-form')
|
2017-04-12 15:02:53 +00:00
|
|
|
expect(notes_holder_saved).to have_content test_note_comment
|
|
|
|
|
|
|
|
assert_form_is_reset if asset_form_reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_comment_dismissal(line_holder)
|
|
|
|
expect(line_holder).not_to have_xpath notes_holder_input_xpath
|
|
|
|
expect(page).not_to have_content test_note_comment
|
|
|
|
|
|
|
|
assert_form_is_reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_form_is_reset
|
2018-09-05 11:23:42 +00:00
|
|
|
expect(page).to have_no_css('.note-edit-form')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|