debian-mirror-gitlab/spec/features/merge_request/user_posts_diff_notes_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

288 lines
10 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2018-03-17 18:26:18 +05:30
2020-06-23 00:09:42 +05:30
RSpec.describe 'Merge request > User posts diff notes', :js do
2018-03-17 18:26:18 +05:30
include MergeRequestDiffHelpers
2022-01-26 12:08:38 +05:30
include Spec::Support::Helpers::ModalHelpers
2017-08-17 22:00:37 +05:30
2022-11-25 23:54:43 +05:30
let_it_be(:merge_request) { create(:merge_request) }
2017-08-17 22:00:37 +05:30
let(:project) { merge_request.source_project }
2018-03-17 18:26:18 +05:30
let(:user) { project.creator }
let(:comment_button_class) { '.add-diff-note' }
let(:notes_holder_input_class) { 'js-temp-notes-holder' }
2021-09-30 23:02:18 +05:30
let(:notes_holder_input_xpath) { '..//following-sibling::*[contains(concat(" ", @class, " "), " notes_holder ")]' }
2018-03-17 18:26:18 +05:30
let(:test_note_comment) { 'this is a test note!' }
2017-08-17 22:00:37 +05:30
before do
2018-03-17 18:26:18 +05:30
set_cookie('sidebar_collapsed', 'true')
2017-08-17 22:00:37 +05:30
project.add_developer(user)
2017-09-10 17:25:29 +05:30
sign_in(user)
2017-08-17 22:00:37 +05:30
end
context 'when hovering over a parallel view diff file' do
before do
2017-09-10 17:25:29 +05:30
visit diffs_project_merge_request_path(project, merge_request, view: 'parallel')
2017-08-17 22:00:37 +05:30
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-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]'), 'left')
2017-08-17 22:00:37 +05:30
end
it 'does not allow commenting on the right side' do
2022-04-04 11:22:00 +05:30
should_not_allow_commenting(find_by_scrolling('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_23_22"]').find(:xpath, '..'), 'right')
2017-08-17 22:00:37 +05:30
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-04-04 11:22:00 +05:30
should_not_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'left')
2017-08-17 22:00:37 +05:30
end
it 'allows commenting on the right side' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"]').find(:xpath, '..'), 'right')
2017-08-17 22:00:37 +05:30
end
end
context 'with an old line on the left and a new line on the right' do
2020-07-28 23:09:34 +05:30
it 'allows commenting on the left side', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/199050' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'left')
2017-08-17 22:00:37 +05:30
end
it 'allows commenting on the right side' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9"]').find(:xpath, '..'), 'right')
2017-08-17 22:00:37 +05:30
end
end
context 'with an unchanged line on the left and an unchanged line on the right' do
2020-07-28 23:09:34 +05:30
it 'allows commenting on the left side', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/196826' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'left')
2017-08-17 22:00:37 +05:30
end
it 'allows commenting on the right side' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'right')
2017-08-17 22:00:37 +05:30
end
end
context 'with a match line' do
2020-04-22 19:07:51 +05:30
it 'does not allow commenting' do
2022-04-04 11:22:00 +05:30
line_holder = find_by_scrolling('.match', match: :first)
2019-10-12 21:52:04 +05:30
match_should_not_allow_commenting(line_holder)
2017-08-17 22:00:37 +05:30
end
end
context 'with an unfolded line' do
2018-03-17 18:26:18 +05:30
before do
2022-04-04 11:22:00 +05:30
page.within find_by_scrolling('.file-holder[id="a5cc2925ca8258af241be7e5b0381edf30266302"]') do
2021-02-22 17:27:13 +05:30
find('.js-unfold', match: :first).click
end
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
end
2018-12-13 13:39:08 +05:30
it 'allows commenting on the left side' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('#a5cc2925ca8258af241be7e5b0381edf30266302').first('.line_holder [data-testid="left-side"]'))
2017-08-17 22:00:37 +05:30
end
2018-12-13 13:39:08 +05:30
it 'allows commenting on the right side' do
# Automatically shifts comment box to left side.
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('#a5cc2925ca8258af241be7e5b0381edf30266302').first('.line_holder [data-testid="right-side"]'))
2017-08-17 22:00:37 +05:30
end
end
end
context 'when hovering over an inline view diff file' do
before do
2017-09-10 17:25:29 +05:30
visit diffs_project_merge_request_path(project, merge_request, view: 'inline')
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
context 'after deleteing a note' do
it 'allows commenting' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
2018-03-17 18:26:18 +05:30
2022-08-13 15:12:31 +05:30
accept_gl_confirm(button_text: 'Delete comment') do
2018-03-17 18:26:18 +05:30
first('button.more-actions-toggle').click
first('.js-note-delete').click
end
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
2018-03-17 18:26:18 +05:30
end
end
2017-08-17 22:00:37 +05:30
context 'with a new line' do
it 'allows commenting' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
2017-08-17 22:00:37 +05:30
end
end
context 'with an old line' do
it 'allows commenting' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'))
2017-08-17 22:00:37 +05:30
end
end
context 'with an unchanged line' do
it 'allows commenting' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]'))
2017-08-17 22:00:37 +05:30
end
end
context 'with a match line' do
it 'does not allow commenting' do
2022-04-04 11:22:00 +05:30
match_should_not_allow_commenting(find_by_scrolling('.match', match: :first))
2017-08-17 22:00:37 +05:30
end
end
context 'with an unfolded line' do
2018-03-17 18:26:18 +05:30
before do
2022-04-04 11:22:00 +05:30
page.within find_by_scrolling('.file-holder[id="a5cc2925ca8258af241be7e5b0381edf30266302"]') do
2021-02-22 17:27:13 +05:30
find('.js-unfold', match: :first).click
end
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
end
# The first `.js-unfold` unfolds upwards, therefore the first
# `.line_holder` will be an unfolded line.
2022-04-04 11:22:00 +05:30
let(:line_holder) { find_by_scrolling('[id="a5cc2925ca8258af241be7e5b0381edf30266302_1_1"]') }
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
it 'allows commenting' do
should_allow_commenting line_holder
2017-08-17 22:00:37 +05:30
end
end
context 'when hovering over a diff discussion' do
before do
2017-09-10 17:25:29 +05:30
visit diffs_project_merge_request_path(project, merge_request, view: 'inline')
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]'))
2017-09-10 17:25:29 +05:30
visit project_merge_request_path(project, merge_request)
2017-08-17 22:00:37 +05:30
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-09-10 17:25:29 +05:30
visit diffs_project_merge_request_path(project, merge_request, view: 'inline')
2017-08-17 22:00:37 +05:30
end
context 'with a new line' do
it 'allows dismissing a comment' do
2022-04-04 11:22:00 +05:30
should_allow_dismissing_a_comment(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
2017-08-17 22:00:37 +05:30
end
end
end
2019-07-07 11:18:12 +05:30
describe 'with multiple note forms' do
2017-08-17 22:00:37 +05:30
before do
2017-09-10 17:25:29 +05:30
visit diffs_project_merge_request_path(project, merge_request, view: 'inline')
2022-04-04 11:22:00 +05:30
click_diff_line(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
click_diff_line(find_by_scrolling('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'))
2017-08-17 22:00:37 +05:30
end
describe 'posting a note' do
2018-11-18 11:00:15 +05:30
it 'adds as discussion' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'), asset_form_reset: false)
2018-11-18 11:00:15 +05:30
expect(page).to have_css('.notes_holder .note.note-discussion', count: 1)
2021-04-17 20:07:23 +05:30
expect(page).to have_field('Reply…')
2017-08-17 22:00:37 +05:30
end
end
end
context 'when the MR only supports legacy diff notes' do
before do
2020-10-24 23:57:45 +05:30
merge_request.merge_request_diff.update!(start_commit_sha: nil)
2017-09-10 17:25:29 +05:30
visit diffs_project_merge_request_path(project, merge_request, view: 'inline')
2017-08-17 22:00:37 +05:30
end
context 'with a new line' do
2018-12-05 23:21:45 +05:30
it 'allows commenting' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
2017-08-17 22:00:37 +05:30
end
end
context 'with an old line' do
2018-12-05 23:21:45 +05:30
it 'allows commenting' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="6eb14e00385d2fb284765eb1cd8d420d33d63fc9_22_22"]'))
2017-08-17 22:00:37 +05:30
end
end
context 'with an unchanged line' do
2018-12-05 23:21:45 +05:30
it 'allows commenting' do
2022-04-04 11:22:00 +05:30
should_allow_commenting(find_by_scrolling('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]'))
2017-08-17 22:00:37 +05:30
end
end
context 'with a match line' do
2022-11-25 23:54:43 +05:30
it 'does not allow commenting', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/375024' do
2022-04-04 11:22:00 +05:30
match_should_not_allow_commenting(find_by_scrolling('.match', match: :first))
2017-08-17 22:00:37 +05:30
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-23 00:09:42 +05:30
click_button 'Add comment now'
2018-03-17 18:26:18 +05:30
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
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-07-16 23:28:13 +05:30
accept_gl_confirm(s_('Notes|Are you sure you want to cancel creating this comment?'), button_text: _('Discard changes')) do
2022-01-26 12:08:38 +05:30
find('.js-close-discussion-note-form').click
2020-05-24 23:13:21 +05:30
end
2017-08-17 22:00:37 +05:30
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-10-12 21:52:04 +05:30
def match_should_not_allow_commenting(line_holder)
expect(line_holder).not_to have_css comment_button_class
end
2017-08-17 22:00:37 +05:30
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-11-20 20:47:30 +05:30
expect(notes_holder_saved[:class]).not_to include('note-edit-form')
2017-08-17 22:00:37 +05:30
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-11-20 20:47:30 +05:30
expect(page).to have_no_css('.note-edit-form')
2017-08-17 22:00:37 +05:30
end
end