Commit 4b9c952d authored by Kushal Pandya's avatar Kushal Pandya Committed by Phil Hughes

Fix ability to edit diff notes multiple times

parent 6ca5a989
...@@ -578,12 +578,12 @@ const normalizeNewlines = function(str) { ...@@ -578,12 +578,12 @@ const normalizeNewlines = function(str) {
Updates the current note field. Updates the current note field.
*/ */
Notes.prototype.updateNote = function(_xhr, noteEntity, _status) { Notes.prototype.updateNote = function(noteEntity, $targetNote) {
var $noteEntityEl, $note_li; var $noteEntityEl, $note_li;
// Convert returned HTML to a jQuery object so we can modify it further // Convert returned HTML to a jQuery object so we can modify it further
$noteEntityEl = $(noteEntity.html); $noteEntityEl = $(noteEntity.html);
$noteEntityEl.addClass('fade-in-full'); $noteEntityEl.addClass('fade-in-full');
this.revertNoteEditForm(); this.revertNoteEditForm($targetNote);
gl.utils.localTimeAgo($('.js-timeago', $noteEntityEl)); gl.utils.localTimeAgo($('.js-timeago', $noteEntityEl));
$noteEntityEl.renderGFM(); $noteEntityEl.renderGFM();
$noteEntityEl.find('.js-task-list-container').taskList('enable'); $noteEntityEl.find('.js-task-list-container').taskList('enable');
...@@ -1404,7 +1404,7 @@ const normalizeNewlines = function(str) { ...@@ -1404,7 +1404,7 @@ const normalizeNewlines = function(str) {
gl.utils.ajaxPost(formAction, formData) gl.utils.ajaxPost(formAction, formData)
.then((note) => { .then((note) => {
// Submission successful! render final note element // Submission successful! render final note element
this.updateNote(null, note, null); this.updateNote(note, $editingNote);
}) })
.fail(() => { .fail(() => {
// Submission failed, revert back to original note // Submission failed, revert back to original note
......
...@@ -79,6 +79,47 @@ import '~/notes'; ...@@ -79,6 +79,47 @@ import '~/notes';
}); });
}); });
describe('updateNote', () => {
let sampleComment;
let noteEntity;
let $form;
let $notesContainer;
beforeEach(() => {
this.notes = new Notes('', []);
window.gon.current_username = 'root';
window.gon.current_user_fullname = 'Administrator';
sampleComment = 'foo';
noteEntity = {
id: 1234,
html: `<li class="note note-row-1234 timeline-entry" id="note_1234">
<div class="note-text">${sampleComment}</div>
</li>`,
note: sampleComment,
valid: true
};
$form = $('form.js-main-target-form');
$notesContainer = $('ul.main-notes-list');
$form.find('textarea.js-note-text').val(sampleComment);
});
it('updates note and resets edit form', () => {
const deferred = $.Deferred();
spyOn($, 'ajax').and.returnValue(deferred.promise());
spyOn(this.notes, 'revertNoteEditForm');
$('.js-comment-button').click();
deferred.resolve(noteEntity);
const $targetNote = $notesContainer.find(`#note_${noteEntity.id}`);
const updatedNote = Object.assign({}, noteEntity);
updatedNote.note = 'bar';
this.notes.updateNote(updatedNote, $targetNote);
expect(this.notes.revertNoteEditForm).toHaveBeenCalledWith($targetNote);
});
});
describe('renderNote', () => { describe('renderNote', () => {
let notes; let notes;
let note; let note;
......
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