Fixed UP arrow key not editing last comment in discussion
Closes #31348
This commit is contained in:
parent
59c9ec5ce6
commit
ee01ebd9e4
4 changed files with 82 additions and 1 deletions
|
@ -175,7 +175,7 @@ const normalizeNewlines = function(str) {
|
||||||
if ($textarea.val() !== '') {
|
if ($textarea.val() !== '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
myLastNote = $("li.note[data-author-id='" + gon.current_user_id + "'][data-editable]:last");
|
myLastNote = $(`li.note[data-author-id='${gon.current_user_id}'][data-editable]:last`, $textarea.closest('.note, #notes'));
|
||||||
if (myLastNote.length) {
|
if (myLastNote.length) {
|
||||||
myLastNoteEditBtn = myLastNote.find('.js-note-edit');
|
myLastNoteEditBtn = myLastNote.find('.js-note-edit');
|
||||||
return myLastNoteEditBtn.trigger('click', [true, myLastNote]);
|
return myLastNoteEditBtn.trigger('click', [true, myLastNote]);
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
title: Fix up arrow not editing last discussion comment
|
||||||
|
merge_request:
|
||||||
|
author:
|
|
@ -16,6 +16,16 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
|
||||||
sha: merge_request.diff_head_sha
|
sha: merge_request.diff_head_sha
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
let(:path) { "files/ruby/popen.rb" }
|
||||||
|
let(:position) do
|
||||||
|
Gitlab::Diff::Position.new(
|
||||||
|
old_path: path,
|
||||||
|
new_path: path,
|
||||||
|
old_line: nil,
|
||||||
|
new_line: 14,
|
||||||
|
diff_refs: merge_request.diff_refs
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
|
@ -39,6 +49,12 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
|
||||||
render_merge_request(example.description, merged_merge_request)
|
render_merge_request(example.description, merged_merge_request)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'merge_requests/diff_comment.html.raw' do |example|
|
||||||
|
create(:diff_note_on_merge_request, project: project, author: admin, position: position, noteable: merge_request)
|
||||||
|
create(:note_on_merge_request, author: admin, project: project, noteable: merge_request)
|
||||||
|
render_merge_request(example.description, merge_request)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def render_merge_request(fixture_file_name, merge_request)
|
def render_merge_request(fixture_file_name, merge_request)
|
||||||
|
|
61
spec/javascripts/merge_request_notes_spec.js
Normal file
61
spec/javascripts/merge_request_notes_spec.js
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/* global Notes */
|
||||||
|
|
||||||
|
import 'vendor/autosize';
|
||||||
|
import '~/gl_form';
|
||||||
|
import '~/lib/utils/text_utility';
|
||||||
|
import '~/render_gfm';
|
||||||
|
import '~/render_math';
|
||||||
|
import '~/notes';
|
||||||
|
|
||||||
|
fdescribe('Merge request notes', () => {
|
||||||
|
window.gon = window.gon || {};
|
||||||
|
window.gl = window.gl || {};
|
||||||
|
gl.utils = gl.utils || {};
|
||||||
|
|
||||||
|
const fixture = 'merge_requests/diff_comment.html.raw';
|
||||||
|
preloadFixtures(fixture);
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
loadFixtures(fixture);
|
||||||
|
gl.utils.disableButtonIfEmptyField = _.noop;
|
||||||
|
window.project_uploads_path = 'http://test.host/uploads';
|
||||||
|
$('body').data('page', 'projects:merge_requests:show');
|
||||||
|
window.gon.current_user_id = $('.note:last').data('author-id');
|
||||||
|
|
||||||
|
return new Notes('', []);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('up arrow', () => {
|
||||||
|
it('edits last comment when triggered in main form', () => {
|
||||||
|
const upArrowEvent = $.Event('keydown');
|
||||||
|
upArrowEvent.which = 38;
|
||||||
|
|
||||||
|
spyOnEvent('.note:last .js-note-edit', 'click');
|
||||||
|
|
||||||
|
$('.js-note-text').trigger(upArrowEvent);
|
||||||
|
|
||||||
|
expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('edits last comment in discussion when triggered in discussion form', (done) => {
|
||||||
|
const upArrowEvent = $.Event('keydown');
|
||||||
|
upArrowEvent.which = 38;
|
||||||
|
|
||||||
|
spyOnEvent('.note-discussion .js-note-edit', 'click');
|
||||||
|
|
||||||
|
$('.js-discussion-reply-button').click();
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(
|
||||||
|
$('.note-discussion .js-note-text'),
|
||||||
|
).toExist();
|
||||||
|
|
||||||
|
$('.note-discussion .js-note-text').trigger(upArrowEvent);
|
||||||
|
|
||||||
|
expect('click').toHaveBeenTriggeredOn('.note-discussion .js-note-edit');
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue