Commit f7ad9e5a authored by Eric Eastwood's avatar Eric Eastwood

Fix MR "Changes" diff note up arrow to edit last note

Fix https://gitlab.com/gitlab-org/gitlab-ce/issues/33868

While in a MR "Changes" tab looking at some diff note discussions.
Clicking reply and pressing the up-arrow should edit your last comment in
that discussion.

I suspect this regressed in
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11173/diffs#f4bb984ec495c5cb58516785c62978f5209c39b4_179_178
where we changed the selector
parent 1c64fa08
...@@ -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,16 +7,20 @@ import '~/render_gfm'; ...@@ -7,16 +7,20 @@ 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);
describe('Discussion tab with diff comments', () => {
beforeEach(() => { beforeEach(() => {
loadFixtures(fixture); loadFixtures(discussionTabFixture);
gl.utils.disableButtonIfEmptyField = _.noop; gl.utils.disableButtonIfEmptyField = _.noop;
window.project_uploads_path = 'http://test.host/uploads'; window.project_uploads_path = 'http://test.host/uploads';
$('body').data('page', 'projects:merge_requests:show'); $('body').data('page', 'projects:merge_requests:show');
...@@ -28,7 +32,7 @@ describe('Merge request notes', () => { ...@@ -28,7 +32,7 @@ describe('Merge request notes', () => {
describe('up arrow', () => { describe('up arrow', () => {
it('edits last comment when triggered in main form', () => { it('edits last comment when triggered in main form', () => {
const upArrowEvent = $.Event('keydown'); const upArrowEvent = $.Event('keydown');
upArrowEvent.which = 38; upArrowEvent.which = upArrowKeyCode;
spyOnEvent('.note:last .js-note-edit', 'click'); spyOnEvent('.note:last .js-note-edit', 'click');
...@@ -39,7 +43,7 @@ describe('Merge request notes', () => { ...@@ -39,7 +43,7 @@ describe('Merge request notes', () => {
it('edits last comment in discussion when triggered in discussion form', (done) => { it('edits last comment in discussion when triggered in discussion form', (done) => {
const upArrowEvent = $.Event('keydown'); const upArrowEvent = $.Event('keydown');
upArrowEvent.which = 38; upArrowEvent.which = upArrowKeyCode;
spyOnEvent('.note-discussion .js-note-edit', 'click'); spyOnEvent('.note-discussion .js-note-edit', 'click');
...@@ -58,4 +62,38 @@ describe('Merge request notes', () => { ...@@ -58,4 +62,38 @@ describe('Merge request notes', () => {
}); });
}); });
}); });
});
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('', []);
});
describe('up arrow', () => {
it('edits last comment in discussion when triggered in discussion form', (done) => {
const upArrowEvent = $.Event('keydown');
upArrowEvent.which = upArrowKeyCode;
spyOnEvent('.note:last .js-note-edit', 'click');
$('.js-discussion-reply-button').trigger('click');
setTimeout(() => {
$('.js-note-text').trigger(upArrowEvent);
expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit');
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