Commit 137b5f4e authored by Stan Hu's avatar Stan Hu

Merge branch '233386-fix-resolve-button-when-replying-to-comment' into 'master'

Fix missing resolve button when replying to notes

Closes #233386

See merge request gitlab-org/gitlab!39614
parents f1d59ff2 fdf5ec1d
......@@ -23,6 +23,7 @@ class Discussion
:resolved_by_id,
:system_note_with_references_visible_for?,
:resource_parent,
:save,
to: :first_note
......
......@@ -17,12 +17,8 @@ class IndividualNoteDiscussion < Discussion
noteable.supports_replying_to_individual_notes?
end
def convert_to_discussion!(save: false)
first_note.becomes!(Discussion.note_class).to_discussion.tap do
# Save needs to be called on first_note instead of the transformed note
# because of https://gitlab.com/gitlab-org/gitlab-foss/issues/57324
first_note.save if save
end
def convert_to_discussion!
first_note.becomes!(Discussion.note_class).to_discussion
end
def reply_attributes
......
......@@ -54,7 +54,8 @@ module Notes
def when_saved(note)
if note.part_of_discussion? && note.discussion.can_convert_to_discussion?
note.discussion.convert_to_discussion!(save: true)
note.discussion.convert_to_discussion!.save
note.clear_memoization(:discussion)
end
todo_service.new_note(note, current_user)
......
---
title: Fix missing resolve button when replying to notes in MRs
merge_request: 39614
author:
type: fixed
......@@ -95,20 +95,32 @@ RSpec.describe 'Merge request > User posts notes', :js do
end
end
describe 'reply on a deleted conversation' do
before do
visit project_merge_request_path(project, merge_request)
end
it 'shows an error message' do
describe 'replying to a comment' do
it 'makes the discussion resolvable' do
find('.js-reply-button').click
note.delete
page.within('.discussion-reply-holder') do
fill_in 'note[note]', with: 'A reply'
click_button 'Add comment now'
wait_for_requests
expect(page).to have_content('Your comment could not be submitted because discussion to reply to cannot be found')
expect(page).to have_button('Resolve thread')
end
end
context 'when comment is deleted' do
before do
note.delete
end
it 'shows an error message' do
find('.js-reply-button').click
page.within('.discussion-reply-holder') do
fill_in 'note[note]', with: 'A reply'
click_button 'Add comment now'
expect(page).to have_content('Your comment could not be submitted because discussion to reply to cannot be found')
end
end
end
end
......
......@@ -434,6 +434,13 @@ RSpec.describe Notes::CreateService do
.and change { existing_note.updated_at }
end
it 'returns a DiscussionNote with its parent discussion refreshed correctly' do
discussion_notes = subject.discussion.notes
expect(discussion_notes.size).to eq(2)
expect(discussion_notes.first).to be_a(DiscussionNote)
end
context 'discussion to reply cannot be found' do
before do
existing_note.delete
......
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