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
This commit is contained in:
commit
b2e1d32e7a
3 changed files with 82 additions and 37 deletions
|
@ -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('', []);
|
||||
});
|
||||
|
||||
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');
|
||||
return new Notes('', []);
|
||||
});
|
||||
|
||||
it('edits last comment in discussion when triggered in discussion form', (done) => {
|
||||
const upArrowEvent = $.Event('keydown');
|
||||
upArrowEvent.which = 38;
|
||||
describe('up arrow', () => {
|
||||
it('edits last comment when triggered in main form', () => {
|
||||
const upArrowEvent = $.Event('keydown');
|
||||
upArrowEvent.which = upArrowKeyCode;
|
||||
|
||||
spyOnEvent('.note-discussion .js-note-edit', 'click');
|
||||
spyOnEvent('.note:last .js-note-edit', 'click');
|
||||
|
||||
$('.js-discussion-reply-button').click();
|
||||
$('.js-note-text').trigger(upArrowEvent);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(
|
||||
$('.note-discussion .js-note-text'),
|
||||
).toExist();
|
||||
expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit');
|
||||
});
|
||||
|
||||
$('.note-discussion .js-note-text').trigger(upArrowEvent);
|
||||
it('edits last comment in discussion when triggered in discussion form', (done) => {
|
||||
const upArrowEvent = $.Event('keydown');
|
||||
upArrowEvent.which = upArrowKeyCode;
|
||||
|
||||
expect('click').toHaveBeenTriggeredOn('.note-discussion .js-note-edit');
|
||||
spyOnEvent('.note-discussion .js-note-edit', 'click');
|
||||
|
||||
done();
|
||||
$('.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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue