Commit b2e1d32e authored by Jacob Schatz's avatar Jacob Schatz

Merge branch '33868-fix-mr-changes-diff-note-up-arrow-editing' into 'master'

Fix pressing up-arrow on a MR "Changes" diff discussion edits your last note

Closes #33868

See merge request !12297
parents 780adff5 f7ad9e5a
...@@ -187,7 +187,7 @@ const normalizeNewlines = function(str) { ...@@ -187,7 +187,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`, $textarea.closest('.note, #notes')); myLastNote = $(`li.note[data-author-id='${gon.current_user_id}'][data-editable]:last`, $textarea.closest('.note, .notes_holder, #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]);
......
...@@ -55,13 +55,20 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont ...@@ -55,13 +55,20 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
render_merge_request(example.description, merge_request) render_merge_request(example.description, merge_request)
end end
it 'merge_requests/changes_tab_with_comments.json' 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, action: :diffs, format: :json)
end
private private
def render_merge_request(fixture_file_name, merge_request) def render_merge_request(fixture_file_name, merge_request, action: :show, format: :html)
get :show, get action,
namespace_id: project.namespace.to_param, namespace_id: project.namespace.to_param,
project_id: project, project_id: project,
id: merge_request.to_param id: merge_request.to_param,
format: format
expect(response).to be_success expect(response).to be_success
store_frontend_fixture(response, fixture_file_name) store_frontend_fixture(response, fixture_file_name)
......
...@@ -7,54 +7,92 @@ import '~/render_gfm'; ...@@ -7,54 +7,92 @@ import '~/render_gfm';
import '~/render_math'; import '~/render_math';
import '~/notes'; import '~/notes';
const upArrowKeyCode = 38;
describe('Merge request notes', () => { describe('Merge request notes', () => {
window.gon = window.gon || {}; window.gon = window.gon || {};
window.gl = window.gl || {}; window.gl = window.gl || {};
gl.utils = gl.utils || {}; gl.utils = gl.utils || {};
const fixture = 'merge_requests/diff_comment.html.raw'; const discussionTabFixture = 'merge_requests/diff_comment.html.raw';
preloadFixtures(fixture); const changesTabJsonFixture = 'merge_requests/changes_tab_with_comments.json';
preloadFixtures(discussionTabFixture, changesTabJsonFixture);
beforeEach(() => { describe('Discussion tab with diff comments', () => {
loadFixtures(fixture); beforeEach(() => {
gl.utils.disableButtonIfEmptyField = _.noop; loadFixtures(discussionTabFixture);
window.project_uploads_path = 'http://test.host/uploads'; gl.utils.disableButtonIfEmptyField = _.noop;
$('body').data('page', 'projects:merge_requests:show'); window.project_uploads_path = 'http://test.host/uploads';
window.gon.current_user_id = $('.note:last').data('author-id'); $('body').data('page', 'projects:merge_requests:show');
window.gon.current_user_id = $('.note:last').data('author-id');
return new Notes('', []); return new Notes('', []);
}); });
describe('up arrow', () => {
it('edits last comment when triggered in main form', () => {
const upArrowEvent = $.Event('keydown');
upArrowEvent.which = upArrowKeyCode;
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 = upArrowKeyCode;
spyOnEvent('.note-discussion .js-note-edit', 'click');
$('.js-discussion-reply-button').click();
describe('up arrow', () => { setTimeout(() => {
it('edits last comment when triggered in main form', () => { expect(
const upArrowEvent = $.Event('keydown'); $('.note-discussion .js-note-text'),
upArrowEvent.which = 38; ).toExist();
spyOnEvent('.note:last .js-note-edit', 'click'); $('.note-discussion .js-note-text').trigger(upArrowEvent);
$('.js-note-text').trigger(upArrowEvent); expect('click').toHaveBeenTriggeredOn('.note-discussion .js-note-edit');
expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit'); done();
});
});
}); });
});
it('edits last comment in discussion when triggered in discussion form', (done) => { describe('Changes tab with diff comments', () => {
const upArrowEvent = $.Event('keydown'); beforeEach(() => {
upArrowEvent.which = 38; const diffsResponse = getJSONFixture(changesTabJsonFixture);
const noteFormHtml = `<form class="js-new-note-form">
<textarea class="js-note-text"></textarea>
</form>`;
setFixtures(diffsResponse.html + noteFormHtml);
$('body').data('page', 'projects:merge_requests:show');
window.gon.current_user_id = $('.note:last').data('author-id');
return new Notes('', []);
});
spyOnEvent('.note-discussion .js-note-edit', 'click'); describe('up arrow', () => {
it('edits last comment in discussion when triggered in discussion form', (done) => {
const upArrowEvent = $.Event('keydown');
upArrowEvent.which = upArrowKeyCode;
$('.js-discussion-reply-button').click(); spyOnEvent('.note:last .js-note-edit', 'click');
setTimeout(() => { $('.js-discussion-reply-button').trigger('click');
expect(
$('.note-discussion .js-note-text'),
).toExist();
$('.note-discussion .js-note-text').trigger(upArrowEvent); setTimeout(() => {
$('.js-note-text').trigger(upArrowEvent);
expect('click').toHaveBeenTriggeredOn('.note-discussion .js-note-edit'); expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit');
done(); done();
});
}); });
}); });
}); });
......
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