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) {
if ($textarea.val() !== '') {
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) {
myLastNoteEditBtn = myLastNote.find('.js-note-edit');
return myLastNoteEditBtn.trigger('click', [true, myLastNote]);
......
......@@ -55,13 +55,20 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
render_merge_request(example.description, merge_request)
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
def render_merge_request(fixture_file_name, merge_request)
get :show,
def render_merge_request(fixture_file_name, merge_request, action: :show, format: :html)
get action,
namespace_id: project.namespace.to_param,
project_id: project,
id: merge_request.to_param
id: merge_request.to_param,
format: format
expect(response).to be_success
store_frontend_fixture(response, fixture_file_name)
......
......@@ -7,54 +7,92 @@ import '~/render_gfm';
import '~/render_math';
import '~/notes';
const upArrowKeyCode = 38;
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);
const discussionTabFixture = 'merge_requests/diff_comment.html.raw';
const changesTabJsonFixture = 'merge_requests/changes_tab_with_comments.json';
preloadFixtures(discussionTabFixture, changesTabJsonFixture);
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');
describe('Discussion tab with diff comments', () => {
beforeEach(() => {
loadFixtures(discussionTabFixture);
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('', []);
});
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', () => {
it('edits last comment when triggered in main form', () => {
const upArrowEvent = $.Event('keydown');
upArrowEvent.which = 38;
setTimeout(() => {
expect(
$('.note-discussion .js-note-text'),
).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) => {
const upArrowEvent = $.Event('keydown');
upArrowEvent.which = 38;
describe('Changes tab with diff comments', () => {
beforeEach(() => {
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(() => {
expect(
$('.note-discussion .js-note-text'),
).toExist();
$('.js-discussion-reply-button').trigger('click');
$('.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