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

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

305 lines
8.6 KiB
Ruby
Raw Permalink Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-17 16:20:25 +05:30
RSpec.describe 'Merge request > Batch comments', :js, feature_category: :code_review_workflow do
2020-06-23 00:09:42 +05:30
include MergeRequestDiffHelpers
include RepoHelpers
let(:user) { create(:user) }
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
before do
2022-10-11 01:57:18 +05:30
stub_feature_flags(moved_mr_sidebar: false)
2020-06-23 00:09:42 +05:30
project.add_maintainer(user)
sign_in(user)
2022-07-23 23:45:48 +05:30
visit_diffs
2020-06-23 00:09:42 +05:30
end
2022-07-23 23:45:48 +05:30
it 'adds draft note' do
write_diff_comment
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
expect(find('.draft-note-component')).to have_content('Line is wrong')
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
expect(page).to have_selector('[data-testid="review_bar_component"]')
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
expect(find('[data-testid="review_bar_component"] .gl-badge')).to have_content('1')
end
it 'publishes review' do
write_diff_comment
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
page.within('.review-bar-content') do
click_button 'Finish review'
click_button 'Submit review'
2020-06-23 00:09:42 +05:30
end
2022-07-23 23:45:48 +05:30
wait_for_requests
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
expect(page).not_to have_selector('.draft-note-component', text: 'Line is wrong')
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
expect(page).to have_selector('.note:not(.draft-note)', text: 'Line is wrong')
end
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
it 'deletes draft note' do
write_diff_comment
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
find('.js-note-delete').click
2020-06-23 00:09:42 +05:30
2023-07-09 08:55:56 +05:30
wait_for_requests
2022-07-23 23:45:48 +05:30
page.within('.modal') do
2022-08-13 15:12:31 +05:30
click_button('Delete comment', match: :first)
2020-06-23 00:09:42 +05:30
end
2022-07-23 23:45:48 +05:30
wait_for_requests
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
expect(page).not_to have_selector('.draft-note-component', text: 'Line is wrong')
end
2022-04-04 11:22:00 +05:30
2022-07-23 23:45:48 +05:30
it 'edits draft note' do
write_diff_comment
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
find('.js-note-edit').click
2020-06-23 00:09:42 +05:30
2023-07-09 08:55:56 +05:30
wait_for_requests
2022-07-23 23:45:48 +05:30
# make sure comment form is in view
execute_script("window.scrollBy(0, 200)")
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
write_comment(text: 'Testing update', button_text: 'Save comment')
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
expect(page).to have_selector('.draft-note-component', text: 'Testing update')
end
2020-06-23 00:09:42 +05:30
2022-11-25 23:54:43 +05:30
context 'multiple times on the same diff line' do
it 'shows both drafts at once' do
write_diff_comment
# All of the Diff helpers like click_diff_line (or write_diff_comment)
# fail very badly when run a second time.
# This recreates the relevant logic.
line = find_by_scrolling("[id='#{sample_compare.changes[0][:line_code]}']")
line.hover
line.find('.js-add-diff-note-button').click
write_comment(text: 'A second draft!', button_text: 'Add to review')
expect(page).to have_text('Line is wrong')
expect(page).to have_text('A second draft!')
end
end
2022-07-23 23:45:48 +05:30
context 'with image and file draft note' do
let(:merge_request) { create(:merge_request_with_diffs, :with_image_diffs, source_project: project) }
let!(:draft_on_text) { create(:draft_note_on_text_diff, merge_request: merge_request, author: user, path: 'README.md', note: 'Lorem ipsum on text...') }
let!(:draft_on_image) { create(:draft_note_on_image_diff, merge_request: merge_request, author: user, path: 'files/images/ee_repo_logo.png', note: 'Lorem ipsum on an image...') }
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
it 'does not show in overview' do
visit_overview
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
expect(page).to have_no_text(draft_on_text.note)
expect(page).to have_no_text(draft_on_image.note)
2021-04-29 21:17:54 +05:30
end
2022-07-23 23:45:48 +05:30
end
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
context 'adding single comment to review' do
before do
visit_overview
end
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
it 'at first does not show `Add to review` and `Add comment now` buttons' do
expect(page).to have_no_button('Add to review')
expect(page).to have_no_button('Add comment now')
2021-04-29 21:17:54 +05:30
end
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
context 'when review has started' do
2021-04-29 21:17:54 +05:30
before do
2022-07-23 23:45:48 +05:30
visit_diffs
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
write_diff_comment
2021-04-29 21:17:54 +05:30
2022-10-02 17:18:49 +05:30
visit_overview
2022-07-23 23:45:48 +05:30
end
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
it 'can add comment to review' do
write_comment(selector: '.js-main-target-form', field: 'note-body', text: 'Its a draft comment', button_text: 'Add to review')
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
expect(page).to have_selector('.draft-note-component', text: 'Its a draft comment')
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
click_button('Pending comments')
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
expect(page).to have_text('2 pending comments')
end
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
it 'can add comment right away' do
write_comment(selector: '.js-main-target-form', field: 'note-body', text: 'Its a regular comment', button_text: 'Add comment now')
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
expect(page).to have_selector('.note:not(.draft-note)', text: 'Its a regular comment')
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
click_button('Pending comments')
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
expect(page).to have_text('1 pending comment')
2021-04-29 21:17:54 +05:30
end
2020-06-23 00:09:42 +05:30
end
2022-07-23 23:45:48 +05:30
end
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
context 'in parallel diff' do
before do
find('.js-show-diff-settings').click
click_button 'Side-by-side'
find('.js-show-diff-settings').click
end
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
it 'adds draft comments to both sides' do
write_parallel_comment('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9')
write_parallel_comment('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9', button_text: 'Add to review', text: 'Another wrong line')
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
expect(find('.new .draft-note-component')).to have_content('Line is wrong')
expect(find('.old .draft-note-component')).to have_content('Another wrong line')
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
expect(find('.review-bar-content .gl-badge')).to have_content('2')
2020-06-23 00:09:42 +05:30
end
2022-07-23 23:45:48 +05:30
end
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
context 'thread is unresolved' do
let!(:active_discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
before do
visit_diffs
end
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
it 'publishes comment right away and resolves the thread' do
expect(active_discussion.resolved?).to eq(false)
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
write_reply_to_discussion(button_text: 'Add comment now', resolve: true)
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
2020-06-23 00:09:42 +05:30
end
2022-07-23 23:45:48 +05:30
end
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
it 'publishes review and resolves the thread' do
expect(active_discussion.resolved?).to eq(false)
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
write_reply_to_discussion(resolve: true)
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
page.within('.review-bar-content') do
click_button 'Finish review'
click_button 'Submit review'
end
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
wait_for_requests
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
page.within '.discussions-counter' do
expect(page).to have_content('All threads resolved')
2020-06-23 00:09:42 +05:30
end
end
2022-07-23 23:45:48 +05:30
end
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
context 'thread is resolved' do
let!(:active_discussion) { create(:diff_note_on_merge_request, :resolved, noteable: merge_request, project: project).to_discussion }
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
before do
active_discussion.resolve!(@current_user)
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
visit_diffs
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
page.find('.js-diff-comment-avatar').click
end
2020-06-23 00:09:42 +05:30
2023-04-23 21:23:45 +05:30
it 'publishes comment right away and unresolves the thread',
quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/337931' do
2022-07-23 23:45:48 +05:30
expect(active_discussion.resolved?).to eq(true)
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
write_reply_to_discussion(button_text: 'Add comment now', unresolve: true)
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
2020-06-23 00:09:42 +05:30
end
2022-07-23 23:45:48 +05:30
end
2020-06-23 00:09:42 +05:30
2023-04-23 21:23:45 +05:30
it 'publishes review and unresolves the thread',
quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/337931' do
2022-07-23 23:45:48 +05:30
expect(active_discussion.resolved?).to eq(true)
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
wait_for_requests
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
write_reply_to_discussion(button_text: 'Start a review', unresolve: true)
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
page.within('.review-bar-content') do
click_button 'Finish review'
click_button 'Submit review'
end
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
wait_for_requests
2020-06-23 00:09:42 +05:30
2022-07-23 23:45:48 +05:30
page.within '.discussions-counter' do
expect(page).to have_content('1 unresolved thread')
2020-06-23 00:09:42 +05:30
end
end
end
def visit_diffs
visit diffs_project_merge_request_path(merge_request.project, merge_request)
wait_for_requests
end
2021-04-29 21:17:54 +05:30
def visit_overview
visit project_merge_request_path(merge_request.project, merge_request)
2020-06-23 00:09:42 +05:30
wait_for_requests
end
2023-04-23 21:23:45 +05:30
def write_diff_comment(...)
2022-04-04 11:22:00 +05:30
click_diff_line(find_by_scrolling("[id='#{sample_compare.changes[0][:line_code]}']"))
2021-04-29 21:17:54 +05:30
2023-04-23 21:23:45 +05:30
write_comment(...)
2021-04-29 21:17:54 +05:30
end
def write_parallel_comment(line, **params)
2022-04-04 11:22:00 +05:30
line_element = find_by_scrolling("[id='#{line}']")
scroll_to_elements_bottom(line_element)
line_element.hover
2021-09-30 23:02:18 +05:30
find(".js-add-diff-note-button").click
2020-06-23 00:09:42 +05:30
2021-04-29 21:17:54 +05:30
write_comment(selector: "form[data-line-code='#{line}']", **params)
end
def write_comment(selector: '.js-discussion-note-form', field: 'note_note', button_text: 'Start a review', text: 'Line is wrong')
page.within(selector) do
fill_in(field, with: text)
2020-06-23 00:09:42 +05:30
click_button(button_text)
end
wait_for_requests
end
2021-04-29 21:17:54 +05:30
def write_reply_to_discussion(button_text: 'Start a review', text: 'Line is wrong', resolve: false, unresolve: false)
page.within(first('.diff-files-holder .discussion-reply-holder')) do
find_field('Reply…', match: :first).click
2020-06-23 00:09:42 +05:30
2021-04-29 21:17:54 +05:30
fill_in('note_note', with: text)
2020-06-23 00:09:42 +05:30
2021-04-29 21:17:54 +05:30
if resolve
page.check('Resolve thread')
end
if unresolve
page.check('Unresolve thread')
end
2020-06-23 00:09:42 +05:30
2021-04-29 21:17:54 +05:30
click_button(button_text)
2020-06-23 00:09:42 +05:30
end
2021-04-29 21:17:54 +05:30
wait_for_requests
2020-06-23 00:09:42 +05:30
end
end