2017-01-10 18:02:20 -05:00
|
|
|
/* eslint-disable space-before-function-paren, no-unused-expressions, no-var, object-shorthand, comma-dangle, max-len */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Notes */
|
|
|
|
|
2017-05-03 13:41:16 -04:00
|
|
|
import 'vendor/autosize';
|
|
|
|
import '~/gl_form';
|
|
|
|
import '~/lib/utils/text_utility';
|
|
|
|
import '~/render_gfm';
|
|
|
|
import '~/render_math';
|
|
|
|
import '~/notes';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
window.gon || (window.gon = {});
|
2016-11-22 17:46:58 -05:00
|
|
|
window.gl = window.gl || {};
|
|
|
|
gl.utils = gl.utils || {};
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
describe('Notes', function() {
|
2017-04-20 10:07:06 -04:00
|
|
|
const FLASH_TYPE_ALERT = 'alert';
|
2016-12-30 16:27:40 -05:00
|
|
|
var commentsTemplate = 'issues/issue_with_comment.html.raw';
|
2016-12-30 19:14:33 -05:00
|
|
|
preloadFixtures(commentsTemplate);
|
2016-08-31 10:32:48 -04:00
|
|
|
|
2016-11-22 17:46:58 -05:00
|
|
|
beforeEach(function () {
|
2016-12-30 19:14:33 -05:00
|
|
|
loadFixtures(commentsTemplate);
|
2016-11-22 17:46:58 -05:00
|
|
|
gl.utils.disableButtonIfEmptyField = _.noop;
|
|
|
|
window.project_uploads_path = 'http://test.host/uploads';
|
2016-12-08 16:49:32 -05:00
|
|
|
$('body').data('page', 'projects:issues:show');
|
2016-11-22 17:46:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('task lists', function() {
|
2016-07-24 16:45:11 -04:00
|
|
|
beforeEach(function() {
|
2017-05-05 06:57:29 -04:00
|
|
|
$('.js-comment-button').on('click', function(e) {
|
2016-08-31 10:32:48 -04:00
|
|
|
e.preventDefault();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-05-05 17:41:55 -04:00
|
|
|
this.notes = new Notes('', []);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-08-31 10:32:48 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
it('modifies the Markdown field', function() {
|
|
|
|
$('input[type=checkbox]').attr('checked', true).trigger('change');
|
2016-08-31 10:32:48 -04:00
|
|
|
expect($('.js-task-list-field').val()).toBe('- [x] Task List Item');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-08-31 10:32:48 -04:00
|
|
|
|
2017-02-08 09:12:12 -05:00
|
|
|
it('submits an ajax request on tasklist:changed', function() {
|
|
|
|
spyOn(jQuery, 'ajax').and.callFake(function(req) {
|
|
|
|
expect(req.type).toBe('PATCH');
|
|
|
|
expect(req.url).toBe('http://test.host/frontend-fixtures/issues-project/notes/1');
|
|
|
|
return expect(req.data.note).not.toBe(null);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-02-13 21:52:20 -05:00
|
|
|
$('.js-task-list-field').trigger('tasklist:changed');
|
2016-08-31 10:32:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('comments', function() {
|
|
|
|
var textarea = '.js-note-text';
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2017-05-05 17:41:55 -04:00
|
|
|
this.notes = new Notes('', []);
|
2016-08-31 10:32:48 -04:00
|
|
|
|
|
|
|
this.autoSizeSpy = spyOnEvent($(textarea), 'autosize:update');
|
|
|
|
spyOn(this.notes, 'renderNote').and.stub();
|
|
|
|
|
|
|
|
$(textarea).data('autosave', {
|
|
|
|
reset: function() {}
|
|
|
|
});
|
|
|
|
|
2017-05-05 06:57:29 -04:00
|
|
|
$('.js-comment-button').on('click', (e) => {
|
|
|
|
const $form = $(this);
|
2016-08-31 10:32:48 -04:00
|
|
|
e.preventDefault();
|
2017-05-05 06:57:29 -04:00
|
|
|
this.notes.addNote($form);
|
|
|
|
this.notes.reenableTargetFormSubmitButton(e);
|
|
|
|
this.notes.resetMainTargetForm(e);
|
2016-08-31 10:32:48 -04:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-08-31 10:32:48 -04:00
|
|
|
|
|
|
|
it('autosizes after comment submission', function() {
|
|
|
|
$(textarea).text('This is an example comment note');
|
|
|
|
expect(this.autoSizeSpy).not.toHaveBeenTriggered();
|
|
|
|
|
|
|
|
$('.js-comment-button').click();
|
|
|
|
expect(this.autoSizeSpy).toHaveBeenTriggered();
|
2017-01-10 17:54:56 -05:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-04-19 15:48:48 -04:00
|
|
|
|
2017-05-18 14:05:01 -04:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-19 15:48:48 -04:00
|
|
|
describe('renderNote', () => {
|
|
|
|
let notes;
|
|
|
|
let note;
|
|
|
|
let $notesList;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
note = {
|
2017-05-03 13:41:16 -04:00
|
|
|
id: 1,
|
2017-04-19 15:48:48 -04:00
|
|
|
valid: true,
|
2017-05-03 13:41:16 -04:00
|
|
|
note: 'heya',
|
|
|
|
html: '<div>heya</div>',
|
2017-04-19 15:48:48 -04:00
|
|
|
};
|
2017-05-03 13:41:16 -04:00
|
|
|
$notesList = jasmine.createSpyObj('$notesList', [
|
|
|
|
'find',
|
|
|
|
'append',
|
|
|
|
]);
|
2017-04-19 15:48:48 -04:00
|
|
|
|
|
|
|
notes = jasmine.createSpyObj('notes', [
|
2017-05-19 02:37:53 -04:00
|
|
|
'setupNewNote',
|
2017-04-19 15:48:48 -04:00
|
|
|
'refresh',
|
|
|
|
'collapseLongCommitList',
|
|
|
|
'updateNotesCount',
|
2017-05-03 13:41:16 -04:00
|
|
|
'putConflictEditWarningInPlace'
|
2017-04-19 15:48:48 -04:00
|
|
|
]);
|
|
|
|
notes.taskList = jasmine.createSpyObj('tasklist', ['init']);
|
|
|
|
notes.note_ids = [];
|
2017-05-03 13:41:16 -04:00
|
|
|
notes.updatedNotesTrackingMap = {};
|
2017-04-19 15:48:48 -04:00
|
|
|
|
|
|
|
spyOn(gl.utils, 'localTimeAgo');
|
2017-05-18 03:46:44 -04:00
|
|
|
spyOn(Notes, 'isNewNote').and.callThrough();
|
|
|
|
spyOn(Notes, 'isUpdatedNote').and.callThrough();
|
2017-05-03 13:41:16 -04:00
|
|
|
spyOn(Notes, 'animateAppendNote').and.callThrough();
|
|
|
|
spyOn(Notes, 'animateUpdateNote').and.callThrough();
|
2017-04-19 15:48:48 -04:00
|
|
|
});
|
|
|
|
|
2017-05-03 13:41:16 -04:00
|
|
|
describe('when adding note', () => {
|
|
|
|
it('should call .animateAppendNote', () => {
|
2017-05-18 03:46:44 -04:00
|
|
|
Notes.isNewNote.and.returnValue(true);
|
2017-05-03 13:41:16 -04:00
|
|
|
Notes.prototype.renderNote.call(notes, note, null, $notesList);
|
|
|
|
|
|
|
|
expect(Notes.animateAppendNote).toHaveBeenCalledWith(note.html, $notesList);
|
|
|
|
});
|
2017-04-19 15:48:48 -04:00
|
|
|
});
|
|
|
|
|
2017-05-03 13:41:16 -04:00
|
|
|
describe('when note was edited', () => {
|
|
|
|
it('should call .animateUpdateNote', () => {
|
2017-05-18 03:46:44 -04:00
|
|
|
Notes.isNewNote.and.returnValue(false);
|
|
|
|
Notes.isUpdatedNote.and.returnValue(true);
|
2017-05-03 13:41:16 -04:00
|
|
|
const $note = $('<div>');
|
|
|
|
$notesList.find.and.returnValue($note);
|
|
|
|
Notes.prototype.renderNote.call(notes, note, null, $notesList);
|
|
|
|
|
|
|
|
expect(Notes.animateUpdateNote).toHaveBeenCalledWith(note.html, $note);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('while editing', () => {
|
|
|
|
it('should update textarea if nothing has been touched', () => {
|
2017-05-18 03:46:44 -04:00
|
|
|
Notes.isNewNote.and.returnValue(false);
|
|
|
|
Notes.isUpdatedNote.and.returnValue(true);
|
2017-05-03 13:41:16 -04:00
|
|
|
const $note = $(`<div class="is-editing">
|
|
|
|
<div class="original-note-content">initial</div>
|
|
|
|
<textarea class="js-note-text">initial</textarea>
|
|
|
|
</div>`);
|
|
|
|
$notesList.find.and.returnValue($note);
|
|
|
|
Notes.prototype.renderNote.call(notes, note, null, $notesList);
|
|
|
|
|
|
|
|
expect($note.find('.js-note-text').val()).toEqual(note.note);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call .putConflictEditWarningInPlace', () => {
|
2017-05-18 03:46:44 -04:00
|
|
|
Notes.isNewNote.and.returnValue(false);
|
|
|
|
Notes.isUpdatedNote.and.returnValue(true);
|
2017-05-03 13:41:16 -04:00
|
|
|
const $note = $(`<div class="is-editing">
|
|
|
|
<div class="original-note-content">initial</div>
|
|
|
|
<textarea class="js-note-text">different</textarea>
|
|
|
|
</div>`);
|
|
|
|
$notesList.find.and.returnValue($note);
|
|
|
|
Notes.prototype.renderNote.call(notes, note, null, $notesList);
|
|
|
|
|
|
|
|
expect(notes.putConflictEditWarningInPlace).toHaveBeenCalledWith(note, $note);
|
|
|
|
});
|
|
|
|
});
|
2017-04-19 15:48:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-18 03:46:44 -04:00
|
|
|
describe('isUpdatedNote', () => {
|
|
|
|
it('should consider same note text as the same', () => {
|
|
|
|
const result = Notes.isUpdatedNote(
|
|
|
|
{
|
|
|
|
note: 'initial'
|
|
|
|
},
|
|
|
|
$(`<div>
|
|
|
|
<div class="original-note-content">initial</div>
|
|
|
|
</div>`)
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(result).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should consider same note with trailing newline as the same', () => {
|
|
|
|
const result = Notes.isUpdatedNote(
|
|
|
|
{
|
|
|
|
note: 'initial\n'
|
|
|
|
},
|
|
|
|
$(`<div>
|
|
|
|
<div class="original-note-content">initial\n</div>
|
|
|
|
</div>`)
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(result).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should consider different notes as different', () => {
|
|
|
|
const result = Notes.isUpdatedNote(
|
|
|
|
{
|
|
|
|
note: 'foo'
|
|
|
|
},
|
|
|
|
$(`<div>
|
|
|
|
<div class="original-note-content">bar</div>
|
|
|
|
</div>`)
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(result).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-19 15:48:48 -04:00
|
|
|
describe('renderDiscussionNote', () => {
|
|
|
|
let discussionContainer;
|
|
|
|
let note;
|
|
|
|
let notes;
|
|
|
|
let $form;
|
|
|
|
let row;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
note = {
|
|
|
|
html: '<li></li>',
|
|
|
|
discussion_html: '<div></div>',
|
|
|
|
discussion_id: 1,
|
|
|
|
discussion_resolvable: false,
|
|
|
|
diff_discussion_html: false,
|
|
|
|
};
|
|
|
|
$form = jasmine.createSpyObj('$form', ['closest', 'find']);
|
|
|
|
row = jasmine.createSpyObj('row', ['prevAll', 'first', 'find']);
|
|
|
|
|
|
|
|
notes = jasmine.createSpyObj('notes', [
|
|
|
|
'isParallelView',
|
|
|
|
'updateNotesCount',
|
|
|
|
]);
|
|
|
|
notes.note_ids = [];
|
|
|
|
|
|
|
|
spyOn(gl.utils, 'localTimeAgo');
|
2017-05-18 03:46:44 -04:00
|
|
|
spyOn(Notes, 'isNewNote');
|
2017-04-19 15:48:48 -04:00
|
|
|
spyOn(Notes, 'animateAppendNote');
|
2017-05-18 03:46:44 -04:00
|
|
|
Notes.isNewNote.and.returnValue(true);
|
2017-04-19 15:48:48 -04:00
|
|
|
notes.isParallelView.and.returnValue(false);
|
|
|
|
row.prevAll.and.returnValue(row);
|
|
|
|
row.first.and.returnValue(row);
|
|
|
|
row.find.and.returnValue(row);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Discussion root note', () => {
|
|
|
|
let body;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
body = jasmine.createSpyObj('body', ['attr']);
|
|
|
|
discussionContainer = { length: 0 };
|
|
|
|
|
|
|
|
$form.closest.and.returnValues(row, $form);
|
|
|
|
$form.find.and.returnValues(discussionContainer);
|
|
|
|
body.attr.and.returnValue('');
|
|
|
|
|
|
|
|
Notes.prototype.renderDiscussionNote.call(notes, note, $form);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call Notes.animateAppendNote', () => {
|
2017-05-03 13:41:16 -04:00
|
|
|
expect(Notes.animateAppendNote).toHaveBeenCalledWith(note.discussion_html, $('.main-notes-list'));
|
2017-04-19 15:48:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Discussion sub note', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
discussionContainer = { length: 1 };
|
|
|
|
|
2017-05-03 13:41:16 -04:00
|
|
|
$form.closest.and.returnValues(row, $form);
|
|
|
|
$form.find.and.returnValues(discussionContainer);
|
2017-04-19 15:48:48 -04:00
|
|
|
|
|
|
|
Notes.prototype.renderDiscussionNote.call(notes, note, $form);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call Notes.animateAppendNote', () => {
|
|
|
|
expect(Notes.animateAppendNote).toHaveBeenCalledWith(note.html, discussionContainer);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('animateAppendNote', () => {
|
|
|
|
let noteHTML;
|
|
|
|
let $notesList;
|
2017-05-03 13:41:16 -04:00
|
|
|
let $resultantNote;
|
2017-04-19 15:48:48 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
noteHTML = '<div></div>';
|
|
|
|
$notesList = jasmine.createSpyObj('$notesList', ['append']);
|
|
|
|
|
2017-05-03 13:41:16 -04:00
|
|
|
$resultantNote = Notes.animateAppendNote(noteHTML, $notesList);
|
|
|
|
});
|
2017-04-19 15:48:48 -04:00
|
|
|
|
2017-05-05 06:57:29 -04:00
|
|
|
it('should have `fade-in-full` class', () => {
|
|
|
|
expect($resultantNote.hasClass('fade-in-full')).toEqual(true);
|
2017-04-19 15:48:48 -04:00
|
|
|
});
|
|
|
|
|
2017-05-03 13:41:16 -04:00
|
|
|
it('should append note to the notes list', () => {
|
|
|
|
expect($notesList.append).toHaveBeenCalledWith($resultantNote);
|
2017-04-19 15:48:48 -04:00
|
|
|
});
|
2017-05-03 13:41:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('animateUpdateNote', () => {
|
|
|
|
let noteHTML;
|
|
|
|
let $note;
|
|
|
|
let $updatedNote;
|
2017-04-19 15:48:48 -04:00
|
|
|
|
2017-05-03 13:41:16 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
noteHTML = '<div></div>';
|
|
|
|
$note = jasmine.createSpyObj('$note', [
|
|
|
|
'replaceWith'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$updatedNote = Notes.animateUpdateNote(noteHTML, $note);
|
2017-04-19 15:48:48 -04:00
|
|
|
});
|
2017-05-03 13:41:16 -04:00
|
|
|
|
|
|
|
it('should have `fade-in` class', () => {
|
|
|
|
expect($updatedNote.hasClass('fade-in')).toEqual(true);
|
2017-04-19 15:48:48 -04:00
|
|
|
});
|
|
|
|
|
2017-05-03 13:41:16 -04:00
|
|
|
it('should call replaceWith on $note', () => {
|
|
|
|
expect($note.replaceWith).toHaveBeenCalledWith($updatedNote);
|
2017-04-19 15:48:48 -04:00
|
|
|
});
|
|
|
|
});
|
2017-05-05 06:57:29 -04:00
|
|
|
|
2017-05-05 17:41:55 -04:00
|
|
|
describe('postComment & updateComment', () => {
|
|
|
|
const sampleComment = 'foo';
|
|
|
|
const updatedComment = 'bar';
|
|
|
|
const note = {
|
|
|
|
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
|
|
|
|
};
|
|
|
|
let $form;
|
|
|
|
let $notesContainer;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
this.notes = new Notes('', []);
|
|
|
|
window.gon.current_username = 'root';
|
|
|
|
window.gon.current_user_fullname = 'Administrator';
|
|
|
|
$form = $('form.js-main-target-form');
|
|
|
|
$notesContainer = $('ul.main-notes-list');
|
|
|
|
$form.find('textarea.js-note-text').val(sampleComment);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show placeholder note while new comment is being posted', () => {
|
|
|
|
$('.js-comment-button').click();
|
|
|
|
expect($notesContainer.find('.note.being-posted').length > 0).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove placeholder note when new comment is done posting', () => {
|
|
|
|
const deferred = $.Deferred();
|
|
|
|
spyOn($, 'ajax').and.returnValue(deferred.promise());
|
|
|
|
$('.js-comment-button').click();
|
|
|
|
|
|
|
|
deferred.resolve(note);
|
|
|
|
expect($notesContainer.find('.note.being-posted').length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show actual note element when new comment is done posting', () => {
|
|
|
|
const deferred = $.Deferred();
|
|
|
|
spyOn($, 'ajax').and.returnValue(deferred.promise());
|
|
|
|
$('.js-comment-button').click();
|
|
|
|
|
|
|
|
deferred.resolve(note);
|
|
|
|
expect($notesContainer.find(`#note_${note.id}`).length > 0).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should reset Form when new comment is done posting', () => {
|
|
|
|
const deferred = $.Deferred();
|
|
|
|
spyOn($, 'ajax').and.returnValue(deferred.promise());
|
|
|
|
$('.js-comment-button').click();
|
|
|
|
|
|
|
|
deferred.resolve(note);
|
|
|
|
expect($form.find('textarea.js-note-text').val()).toEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show flash error message when new comment failed to be posted', () => {
|
|
|
|
const deferred = $.Deferred();
|
|
|
|
spyOn($, 'ajax').and.returnValue(deferred.promise());
|
|
|
|
$('.js-comment-button').click();
|
|
|
|
|
|
|
|
deferred.reject();
|
|
|
|
expect($notesContainer.parent().find('.flash-container .flash-text').is(':visible')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show flash error message when comment failed to be updated', () => {
|
|
|
|
const deferred = $.Deferred();
|
|
|
|
spyOn($, 'ajax').and.returnValue(deferred.promise());
|
|
|
|
$('.js-comment-button').click();
|
|
|
|
|
|
|
|
deferred.resolve(note);
|
|
|
|
const $noteEl = $notesContainer.find(`#note_${note.id}`);
|
|
|
|
$noteEl.find('.js-note-edit').click();
|
|
|
|
$noteEl.find('textarea.js-note-text').val(updatedComment);
|
|
|
|
$noteEl.find('.js-comment-save-button').click();
|
|
|
|
|
|
|
|
deferred.reject();
|
|
|
|
const $updatedNoteEl = $notesContainer.find(`#note_${note.id}`);
|
|
|
|
expect($updatedNoteEl.hasClass('.being-posted')).toEqual(false); // Remove being-posted visuals
|
|
|
|
expect($updatedNoteEl.find('.note-text').text().trim()).toEqual(sampleComment); // See if comment reverted back to original
|
|
|
|
expect($('.flash-container').is(':visible')).toEqual(true); // Flash error message shown
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-05 06:57:29 -04:00
|
|
|
describe('getFormData', () => {
|
|
|
|
it('should return form metadata object from form reference', () => {
|
2017-05-05 17:41:55 -04:00
|
|
|
this.notes = new Notes('', []);
|
2017-05-05 06:57:29 -04:00
|
|
|
|
|
|
|
const $form = $('form');
|
|
|
|
const sampleComment = 'foobar';
|
|
|
|
$form.find('textarea.js-note-text').val(sampleComment);
|
|
|
|
const { formData, formContent, formAction } = this.notes.getFormData($form);
|
|
|
|
|
|
|
|
expect(formData.indexOf(sampleComment) > -1).toBe(true);
|
|
|
|
expect(formContent).toEqual(sampleComment);
|
|
|
|
expect(formAction).toEqual($form.attr('action'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hasSlashCommands', () => {
|
|
|
|
beforeEach(() => {
|
2017-05-05 17:41:55 -04:00
|
|
|
this.notes = new Notes('', []);
|
2017-05-05 06:57:29 -04:00
|
|
|
});
|
|
|
|
|
2017-05-11 05:05:07 -04:00
|
|
|
it('should return true when comment begins with a slash command', () => {
|
2017-05-15 11:07:43 -04:00
|
|
|
const sampleComment = '/wip\n/milestone %1.0\n/merge\n/unassign Merging this';
|
2017-05-05 06:57:29 -04:00
|
|
|
const hasSlashCommands = this.notes.hasSlashCommands(sampleComment);
|
|
|
|
|
|
|
|
expect(hasSlashCommands).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2017-05-11 05:05:07 -04:00
|
|
|
it('should return false when comment does NOT begin with a slash command', () => {
|
|
|
|
const sampleComment = 'Hey, /unassign Merging this';
|
|
|
|
const hasSlashCommands = this.notes.hasSlashCommands(sampleComment);
|
|
|
|
|
|
|
|
expect(hasSlashCommands).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2017-05-05 06:57:29 -04:00
|
|
|
it('should return false when comment does NOT have any slash commands', () => {
|
|
|
|
const sampleComment = 'Looking good, Awesome!';
|
|
|
|
const hasSlashCommands = this.notes.hasSlashCommands(sampleComment);
|
|
|
|
|
|
|
|
expect(hasSlashCommands).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('stripSlashCommands', () => {
|
2017-05-11 05:05:07 -04:00
|
|
|
it('should strip slash commands from the comment which begins with a slash command', () => {
|
|
|
|
this.notes = new Notes();
|
2017-05-15 11:07:43 -04:00
|
|
|
const sampleComment = '/wip\n/milestone %1.0\n/merge\n/unassign Merging this';
|
2017-05-11 05:05:07 -04:00
|
|
|
const stripedComment = this.notes.stripSlashCommands(sampleComment);
|
|
|
|
|
2017-05-15 11:07:43 -04:00
|
|
|
expect(stripedComment).toBe('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should strip slash commands from the comment but leaves plain comment if it is present', () => {
|
|
|
|
this.notes = new Notes();
|
|
|
|
const sampleComment = '/wip\n/milestone %1.0\n/merge\n/unassign\nMerging this';
|
|
|
|
const stripedComment = this.notes.stripSlashCommands(sampleComment);
|
|
|
|
|
|
|
|
expect(stripedComment).toBe('Merging this');
|
2017-05-11 05:05:07 -04:00
|
|
|
});
|
2017-05-05 06:57:29 -04:00
|
|
|
|
2017-05-11 05:05:07 -04:00
|
|
|
it('should NOT strip string that has slashes within', () => {
|
2017-05-05 06:57:29 -04:00
|
|
|
this.notes = new Notes();
|
2017-05-11 05:05:07 -04:00
|
|
|
const sampleComment = 'http://127.0.0.1:3000/root/gitlab-shell/issues/1';
|
2017-05-05 06:57:29 -04:00
|
|
|
const stripedComment = this.notes.stripSlashCommands(sampleComment);
|
|
|
|
|
2017-05-11 05:05:07 -04:00
|
|
|
expect(stripedComment).toBe(sampleComment);
|
2017-05-05 06:57:29 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createPlaceholderNote', () => {
|
|
|
|
const sampleComment = 'foobar';
|
|
|
|
const uniqueId = 'b1234-a4567';
|
|
|
|
const currentUsername = 'root';
|
|
|
|
const currentUserFullname = 'Administrator';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-05-05 17:41:55 -04:00
|
|
|
this.notes = new Notes('', []);
|
2017-05-15 11:07:43 -04:00
|
|
|
spyOn(_, 'escape').and.callFake((comment) => {
|
|
|
|
const escapedString = comment.replace(/["&'<>]/g, (a) => {
|
|
|
|
const escapedToken = {
|
|
|
|
'&': '&',
|
|
|
|
'<': '<',
|
|
|
|
'>': '>',
|
|
|
|
'"': '"',
|
|
|
|
"'": ''',
|
|
|
|
'`': '`'
|
|
|
|
}[a];
|
|
|
|
|
|
|
|
return escapedToken;
|
|
|
|
});
|
|
|
|
|
|
|
|
return escapedString;
|
|
|
|
});
|
2017-05-05 06:57:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return constructed placeholder element for regular note based on form contents', () => {
|
|
|
|
const $tempNote = this.notes.createPlaceholderNote({
|
|
|
|
formContent: sampleComment,
|
|
|
|
uniqueId,
|
|
|
|
isDiscussionNote: false,
|
|
|
|
currentUsername,
|
|
|
|
currentUserFullname
|
|
|
|
});
|
|
|
|
const $tempNoteHeader = $tempNote.find('.note-header');
|
|
|
|
|
|
|
|
expect($tempNote.prop('nodeName')).toEqual('LI');
|
|
|
|
expect($tempNote.attr('id')).toEqual(uniqueId);
|
|
|
|
$tempNote.find('.timeline-icon > a, .note-header-info > a').each(function() {
|
|
|
|
expect($(this).attr('href')).toEqual(`/${currentUsername}`);
|
|
|
|
});
|
|
|
|
expect($tempNote.find('.timeline-content').hasClass('discussion')).toBeFalsy();
|
|
|
|
expect($tempNoteHeader.find('.hidden-xs').text().trim()).toEqual(currentUserFullname);
|
|
|
|
expect($tempNoteHeader.find('.note-headline-light').text().trim()).toEqual(`@${currentUsername}`);
|
2017-05-15 11:07:43 -04:00
|
|
|
expect($tempNote.find('.note-body .note-text p').text().trim()).toEqual(sampleComment);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should escape HTML characters from note based on form contents', () => {
|
|
|
|
const commentWithHtml = '<script>alert("Boom!");</script>';
|
|
|
|
const $tempNote = this.notes.createPlaceholderNote({
|
|
|
|
formContent: commentWithHtml,
|
|
|
|
uniqueId,
|
|
|
|
isDiscussionNote: false,
|
|
|
|
currentUsername,
|
|
|
|
currentUserFullname
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(_.escape).toHaveBeenCalledWith(commentWithHtml);
|
|
|
|
expect($tempNote.find('.note-body .note-text p').html()).toEqual('<script>alert("Boom!");</script>');
|
2017-05-05 06:57:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return constructed placeholder element for discussion note based on form contents', () => {
|
|
|
|
const $tempNote = this.notes.createPlaceholderNote({
|
|
|
|
formContent: sampleComment,
|
|
|
|
uniqueId,
|
|
|
|
isDiscussionNote: true,
|
|
|
|
currentUsername,
|
|
|
|
currentUserFullname
|
|
|
|
});
|
|
|
|
|
|
|
|
expect($tempNote.prop('nodeName')).toEqual('LI');
|
|
|
|
expect($tempNote.find('.timeline-content').hasClass('discussion')).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2017-04-20 10:07:06 -04:00
|
|
|
|
|
|
|
describe('appendFlash', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
this.notes = new Notes();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows a flash message', () => {
|
|
|
|
this.notes.addFlash('Error message', FLASH_TYPE_ALERT, this.notes.parentTimeline);
|
|
|
|
|
|
|
|
expect(document.querySelectorAll('.flash-alert').length).toBe(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('clearFlash', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
$(document).off('ajax:success');
|
|
|
|
this.notes = new Notes();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes all the associated flash messages', () => {
|
|
|
|
this.notes.addFlash('Error message 1', FLASH_TYPE_ALERT, this.notes.parentTimeline);
|
|
|
|
this.notes.addFlash('Error message 2', FLASH_TYPE_ALERT, this.notes.parentTimeline);
|
|
|
|
|
|
|
|
this.notes.clearFlash();
|
|
|
|
|
|
|
|
expect(document.querySelectorAll('.flash-alert').length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-02-10 02:29:41 -05:00
|
|
|
}).call(window);
|