Merge branch 'up-arrow-focus-discussion-comment' into 'master'

Fixed UP arrow key not editing last comment in discussion

Closes #31348

See merge request !11173
This commit is contained in:
Filipa Lacerda 2017-05-09 09:08:03 +00:00
commit 19c4aec32d
4 changed files with 82 additions and 1 deletions

View file

@ -175,7 +175,7 @@ const normalizeNewlines = function(str) {
if ($textarea.val() !== '') {
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) {
myLastNoteEditBtn = myLastNote.find('.js-note-edit');
return myLastNoteEditBtn.trigger('click', [true, myLastNote]);

View file

@ -0,0 +1,4 @@
---
title: Fix up arrow not editing last discussion comment
merge_request:
author:

View file

@ -16,6 +16,16 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
sha: merge_request.diff_head_sha
)
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
@ -39,6 +49,12 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
render_merge_request(example.description, merged_merge_request)
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
def render_merge_request(fixture_file_name, merge_request)

View 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';
describe('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();
});
});
});
});