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
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'Merge request > User posts diff notes', :js do
|
2017-10-04 22:31:34 +00:00
|
|
|
include MergeRequestDiffHelpers
|
2021-11-19 18:12:50 +00:00
|
|
|
include Spec::Support::Helpers::ModalHelpers
|
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' }
|
2021-06-18 18:10:13 +00:00
|
|
|
let(:notes_holder_input_xpath) { '..//following-sibling::*[contains(concat(" ", @class, " "), " notes_holder ")]' }
|
2017-08-01 18:03:07 +00:00
|
|
|
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
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]'), 'left')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow commenting on the right side' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_not_allow_commenting(find_by_scrolling('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..'), 'right')
|
2017-04-12 15:02:53 +00:00
|
|
|
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
|
2022-02-15 15:15:04 +00:00
|
|
|
should_not_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'left')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows commenting on the right side' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'right')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an old line on the left and a new line on the right' do
|
2020-07-08 06:09:13 +00:00
|
|
|
it 'allows commenting on the left side', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/199050' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'left')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows commenting on the right side' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'right')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unchanged line on the left and an unchanged line on the right' do
|
2020-07-08 06:09:13 +00:00
|
|
|
it 'allows commenting on the left side', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/196826' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'left')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows commenting on the right side' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'right')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a match line' do
|
2020-04-06 21:09:19 +00:00
|
|
|
it 'does not allow commenting' do
|
2022-02-15 15:15:04 +00:00
|
|
|
line_holder = find_by_scrolling('.match', match: :first)
|
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
|
2022-02-15 15:15:04 +00:00
|
|
|
page.within find_by_scrolling('.file-holder[id="a5cc2925ca8258af241be7e5b0381edf30266302"]') do
|
2020-12-15 00:10:07 +00:00
|
|
|
find('.js-unfold', match: :first).click
|
|
|
|
end
|
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
2018-10-16 16:21:16 +00:00
|
|
|
it 'allows commenting on the left side' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('#a5cc2925ca8258af241be7e5b0381edf30266302').first('.line_holder [data-testid="left-side"]'))
|
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.
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('#a5cc2925ca8258af241be7e5b0381edf30266302').first('.line_holder [data-testid="right-side"]'))
|
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
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
2017-09-05 10:20:40 +00:00
|
|
|
|
2022-07-06 00:09:36 +00:00
|
|
|
accept_gl_confirm(button_text: 'Delete comment') do
|
2017-10-12 22:33:39 +00:00
|
|
|
first('button.more-actions-toggle').click
|
|
|
|
first('.js-note-delete').click
|
|
|
|
end
|
2017-09-05 10:20:40 +00:00
|
|
|
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
2017-09-05 10:20:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-12 15:02:53 +00:00
|
|
|
context 'with a new line' do
|
|
|
|
it 'allows commenting' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an old line' do
|
|
|
|
it 'allows commenting' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'))
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unchanged line' do
|
|
|
|
it 'allows commenting' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[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
|
2022-02-15 15:15:04 +00:00
|
|
|
match_should_not_allow_commenting(find_by_scrolling('.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
|
2022-02-15 15:15:04 +00:00
|
|
|
page.within find_by_scrolling('.file-holder[id="a5cc2925ca8258af241be7e5b0381edf30266302"]') do
|
2020-12-15 00:10:07 +00:00
|
|
|
find('.js-unfold', match: :first).click
|
|
|
|
end
|
|
|
|
|
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.
|
2022-02-15 15:15:04 +00:00
|
|
|
let(:line_holder) { find_by_scrolling('[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')
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[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
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_dismissing_a_comment(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
2017-04-12 15:02:53 +00:00
|
|
|
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')
|
2022-02-15 15:15:04 +00:00
|
|
|
click_diff_line(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
|
|
|
|
click_diff_line(find_by_scrolling('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'))
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'posting a note' do
|
2018-07-20 13:50:26 +00:00
|
|
|
it 'adds as discussion' do
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[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)
|
2021-02-18 06:09:43 +00:00
|
|
|
expect(page).to have_field('Reply…')
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the MR only supports legacy diff notes' do
|
|
|
|
before do
|
2020-08-10 18:09:54 +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
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[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
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[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
|
2022-02-15 15:15:04 +00:00
|
|
|
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]'))
|
2017-04-12 15:02:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a match line' do
|
2022-09-22 18:11:12 +00:00
|
|
|
it 'does not allow commenting', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/375024' do
|
2022-02-15 15:15:04 +00:00
|
|
|
match_should_not_allow_commenting(find_by_scrolling('.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)
|
|
|
|
|
2020-06-01 06:08:21 +00:00
|
|
|
click_button 'Add comment now'
|
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)
|
|
|
|
|
2022-05-16 12:07:51 +00:00
|
|
|
accept_gl_confirm(s_('Notes|Are you sure you want to cancel creating this comment?'), button_text: _('Discard changes')) do
|
2021-11-19 18:12:50 +00:00
|
|
|
find('.js-close-discussion-note-form').click
|
2020-05-05 21:09:42 +00:00
|
|
|
end
|
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
|