Merge branch 'winh-cleanup-comment-submit-test' into 'master'
Cleanup test for disabling comment submit button See merge request gitlab-org/gitlab-ce!17930
This commit is contained in:
commit
d6abee5189
|
@ -1809,9 +1809,11 @@ export default class Notes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$closeBtn.text($closeBtn.data('originalText'));
|
||||||
|
|
||||||
/* eslint-disable promise/catch-or-return */
|
/* eslint-disable promise/catch-or-return */
|
||||||
// Make request to submit comment on server
|
// Make request to submit comment on server
|
||||||
axios
|
return axios
|
||||||
.post(`${formAction}?html=true`, formData)
|
.post(`${formAction}?html=true`, formData)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const note = res.data;
|
const note = res.data;
|
||||||
|
@ -1928,8 +1930,6 @@ export default class Notes {
|
||||||
this.reenableTargetFormSubmitButton(e);
|
this.reenableTargetFormSubmitButton(e);
|
||||||
this.addNoteError($form);
|
this.addNoteError($form);
|
||||||
});
|
});
|
||||||
|
|
||||||
return $closeBtn.text($closeBtn.data('originalText'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,15 +16,15 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
window.gl = window.gl || {};
|
window.gl = window.gl || {};
|
||||||
gl.utils = gl.utils || {};
|
gl.utils = gl.utils || {};
|
||||||
|
|
||||||
const htmlEscape = (comment) => {
|
const htmlEscape = comment => {
|
||||||
const escapedString = comment.replace(/["&'<>]/g, (a) => {
|
const escapedString = comment.replace(/["&'<>]/g, a => {
|
||||||
const escapedToken = {
|
const escapedToken = {
|
||||||
'&': '&',
|
'&': '&',
|
||||||
'<': '<',
|
'<': '<',
|
||||||
'>': '>',
|
'>': '>',
|
||||||
'"': '"',
|
'"': '"',
|
||||||
"'": ''',
|
"'": ''',
|
||||||
'`': '`'
|
'`': '`',
|
||||||
}[a];
|
}[a];
|
||||||
|
|
||||||
return escapedToken;
|
return escapedToken;
|
||||||
|
@ -39,7 +39,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
var commentsTemplate = 'merge_requests/merge_request_with_comment.html.raw';
|
var commentsTemplate = 'merge_requests/merge_request_with_comment.html.raw';
|
||||||
preloadFixtures(commentsTemplate);
|
preloadFixtures(commentsTemplate);
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function() {
|
||||||
loadFixtures(commentsTemplate);
|
loadFixtures(commentsTemplate);
|
||||||
gl.utils.disableButtonIfEmptyField = _.noop;
|
gl.utils.disableButtonIfEmptyField = _.noop;
|
||||||
window.project_uploads_path = 'http://test.host/uploads';
|
window.project_uploads_path = 'http://test.host/uploads';
|
||||||
|
@ -51,6 +51,17 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
$('body').removeAttr('data-page');
|
$('body').removeAttr('data-page');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('addBinding', () => {
|
||||||
|
it('calls postComment when comment button is clicked', () => {
|
||||||
|
spyOn(Notes.prototype, 'postComment');
|
||||||
|
this.notes = new Notes('', []);
|
||||||
|
|
||||||
|
$('.js-comment-button').click();
|
||||||
|
|
||||||
|
expect(Notes.prototype.postComment).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('task lists', function() {
|
describe('task lists', function() {
|
||||||
let mock;
|
let mock;
|
||||||
|
|
||||||
|
@ -58,7 +69,13 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
spyOn(axios, 'patch').and.callThrough();
|
spyOn(axios, 'patch').and.callThrough();
|
||||||
mock = new MockAdapter(axios);
|
mock = new MockAdapter(axios);
|
||||||
|
|
||||||
mock.onPatch(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`).reply(200, {});
|
mock
|
||||||
|
.onPatch(
|
||||||
|
`${
|
||||||
|
gl.TEST_HOST
|
||||||
|
}/frontend-fixtures/merge-requests-project/merge_requests/1.json`,
|
||||||
|
)
|
||||||
|
.reply(200, {});
|
||||||
|
|
||||||
$('.js-comment-button').on('click', function(e) {
|
$('.js-comment-button').on('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -73,18 +90,27 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
it('modifies the Markdown field', function() {
|
it('modifies the Markdown field', function() {
|
||||||
const changeEvent = document.createEvent('HTMLEvents');
|
const changeEvent = document.createEvent('HTMLEvents');
|
||||||
changeEvent.initEvent('change', true, true);
|
changeEvent.initEvent('change', true, true);
|
||||||
$('input[type=checkbox]').attr('checked', true)[1].dispatchEvent(changeEvent);
|
$('input[type=checkbox]')
|
||||||
|
.attr('checked', true)[1]
|
||||||
|
.dispatchEvent(changeEvent);
|
||||||
|
|
||||||
expect($('.js-task-list-field.original-task-list').val()).toBe('- [x] Task List Item');
|
expect($('.js-task-list-field.original-task-list').val()).toBe(
|
||||||
|
'- [x] Task List Item',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('submits an ajax request on tasklist:changed', function(done) {
|
it('submits an ajax request on tasklist:changed', function(done) {
|
||||||
$('.js-task-list-container').trigger('tasklist:changed');
|
$('.js-task-list-container').trigger('tasklist:changed');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(axios.patch).toHaveBeenCalledWith(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`, {
|
expect(axios.patch).toHaveBeenCalledWith(
|
||||||
note: { note: '' },
|
`${
|
||||||
});
|
gl.TEST_HOST
|
||||||
|
}/frontend-fixtures/merge-requests-project/merge_requests/1.json`,
|
||||||
|
{
|
||||||
|
note: { note: '' },
|
||||||
|
},
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -100,10 +126,10 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
spyOn(this.notes, 'renderNote').and.stub();
|
spyOn(this.notes, 'renderNote').and.stub();
|
||||||
|
|
||||||
$(textarea).data('autosave', {
|
$(textarea).data('autosave', {
|
||||||
reset: function() {}
|
reset: function() {},
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.js-comment-button').on('click', (e) => {
|
$('.js-comment-button').on('click', e => {
|
||||||
const $form = $(this);
|
const $form = $(this);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.notes.addNote($form);
|
this.notes.addNote($form);
|
||||||
|
@ -149,7 +175,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
<div class="note-text">${sampleComment}</div>
|
<div class="note-text">${sampleComment}</div>
|
||||||
</li>`,
|
</li>`,
|
||||||
note: sampleComment,
|
note: sampleComment,
|
||||||
valid: true
|
valid: true,
|
||||||
};
|
};
|
||||||
$form = $('form.js-main-target-form');
|
$form = $('form.js-main-target-form');
|
||||||
$notesContainer = $('ul.main-notes-list');
|
$notesContainer = $('ul.main-notes-list');
|
||||||
|
@ -163,7 +189,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
mock.restore();
|
mock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates note and resets edit form', (done) => {
|
it('updates note and resets edit form', done => {
|
||||||
spyOn(this.notes, 'revertNoteEditForm');
|
spyOn(this.notes, 'revertNoteEditForm');
|
||||||
spyOn(this.notes, 'setupNewNote');
|
spyOn(this.notes, 'setupNewNote');
|
||||||
|
|
||||||
|
@ -175,7 +201,9 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
updatedNote.note = 'bar';
|
updatedNote.note = 'bar';
|
||||||
this.notes.updateNote(updatedNote, $targetNote);
|
this.notes.updateNote(updatedNote, $targetNote);
|
||||||
|
|
||||||
expect(this.notes.revertNoteEditForm).toHaveBeenCalledWith($targetNote);
|
expect(this.notes.revertNoteEditForm).toHaveBeenCalledWith(
|
||||||
|
$targetNote,
|
||||||
|
);
|
||||||
expect(this.notes.setupNewNote).toHaveBeenCalled();
|
expect(this.notes.setupNewNote).toHaveBeenCalled();
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
@ -231,17 +259,14 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
note: 'heya',
|
note: 'heya',
|
||||||
html: '<div>heya</div>',
|
html: '<div>heya</div>',
|
||||||
};
|
};
|
||||||
$notesList = jasmine.createSpyObj('$notesList', [
|
$notesList = jasmine.createSpyObj('$notesList', ['find', 'append']);
|
||||||
'find',
|
|
||||||
'append',
|
|
||||||
]);
|
|
||||||
|
|
||||||
notes = jasmine.createSpyObj('notes', [
|
notes = jasmine.createSpyObj('notes', [
|
||||||
'setupNewNote',
|
'setupNewNote',
|
||||||
'refresh',
|
'refresh',
|
||||||
'collapseLongCommitList',
|
'collapseLongCommitList',
|
||||||
'updateNotesCount',
|
'updateNotesCount',
|
||||||
'putConflictEditWarningInPlace'
|
'putConflictEditWarningInPlace',
|
||||||
]);
|
]);
|
||||||
notes.taskList = jasmine.createSpyObj('tasklist', ['init']);
|
notes.taskList = jasmine.createSpyObj('tasklist', ['init']);
|
||||||
notes.note_ids = [];
|
notes.note_ids = [];
|
||||||
|
@ -258,7 +283,10 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
Notes.isNewNote.and.returnValue(true);
|
Notes.isNewNote.and.returnValue(true);
|
||||||
Notes.prototype.renderNote.call(notes, note, null, $notesList);
|
Notes.prototype.renderNote.call(notes, note, null, $notesList);
|
||||||
|
|
||||||
expect(Notes.animateAppendNote).toHaveBeenCalledWith(note.html, $notesList);
|
expect(Notes.animateAppendNote).toHaveBeenCalledWith(
|
||||||
|
note.html,
|
||||||
|
$notesList,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -273,7 +301,10 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
|
|
||||||
Notes.prototype.renderNote.call(notes, note, null, $notesList);
|
Notes.prototype.renderNote.call(notes, note, null, $notesList);
|
||||||
|
|
||||||
expect(Notes.animateUpdateNote).toHaveBeenCalledWith(note.html, $note);
|
expect(Notes.animateUpdateNote).toHaveBeenCalledWith(
|
||||||
|
note.html,
|
||||||
|
$note,
|
||||||
|
);
|
||||||
expect(notes.setupNewNote).toHaveBeenCalledWith($newNote);
|
expect(notes.setupNewNote).toHaveBeenCalledWith($newNote);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -301,7 +332,10 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
$notesList.find.and.returnValue($note);
|
$notesList.find.and.returnValue($note);
|
||||||
Notes.prototype.renderNote.call(notes, note, null, $notesList);
|
Notes.prototype.renderNote.call(notes, note, null, $notesList);
|
||||||
|
|
||||||
expect(notes.putConflictEditWarningInPlace).toHaveBeenCalledWith(note, $note);
|
expect(notes.putConflictEditWarningInPlace).toHaveBeenCalledWith(
|
||||||
|
note,
|
||||||
|
$note,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -311,11 +345,11 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
it('should consider same note text as the same', () => {
|
it('should consider same note text as the same', () => {
|
||||||
const result = Notes.isUpdatedNote(
|
const result = Notes.isUpdatedNote(
|
||||||
{
|
{
|
||||||
note: 'initial'
|
note: 'initial',
|
||||||
},
|
},
|
||||||
$(`<div>
|
$(`<div>
|
||||||
<div class="original-note-content">initial</div>
|
<div class="original-note-content">initial</div>
|
||||||
</div>`)
|
</div>`),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
expect(result).toEqual(false);
|
||||||
|
@ -324,11 +358,11 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
it('should consider same note with trailing newline as the same', () => {
|
it('should consider same note with trailing newline as the same', () => {
|
||||||
const result = Notes.isUpdatedNote(
|
const result = Notes.isUpdatedNote(
|
||||||
{
|
{
|
||||||
note: 'initial\n'
|
note: 'initial\n',
|
||||||
},
|
},
|
||||||
$(`<div>
|
$(`<div>
|
||||||
<div class="original-note-content">initial\n</div>
|
<div class="original-note-content">initial\n</div>
|
||||||
</div>`)
|
</div>`),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
expect(result).toEqual(false);
|
||||||
|
@ -337,11 +371,11 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
it('should consider different notes as different', () => {
|
it('should consider different notes as different', () => {
|
||||||
const result = Notes.isUpdatedNote(
|
const result = Notes.isUpdatedNote(
|
||||||
{
|
{
|
||||||
note: 'foo'
|
note: 'foo',
|
||||||
},
|
},
|
||||||
$(`<div>
|
$(`<div>
|
||||||
<div class="original-note-content">bar</div>
|
<div class="original-note-content">bar</div>
|
||||||
</div>`)
|
</div>`),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(result).toEqual(true);
|
expect(result).toEqual(true);
|
||||||
|
@ -397,7 +431,10 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
it('should call Notes.animateAppendNote', () => {
|
it('should call Notes.animateAppendNote', () => {
|
||||||
Notes.prototype.renderDiscussionNote.call(notes, note, $form);
|
Notes.prototype.renderDiscussionNote.call(notes, note, $form);
|
||||||
|
|
||||||
expect(Notes.animateAppendNote).toHaveBeenCalledWith(note.discussion_html, $('.main-notes-list'));
|
expect(Notes.animateAppendNote).toHaveBeenCalledWith(
|
||||||
|
note.discussion_html,
|
||||||
|
$('.main-notes-list'),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append to row selected with line_code', () => {
|
it('should append to row selected with line_code', () => {
|
||||||
|
@ -428,7 +465,10 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call Notes.animateAppendNote', () => {
|
it('should call Notes.animateAppendNote', () => {
|
||||||
expect(Notes.animateAppendNote).toHaveBeenCalledWith(note.html, discussionContainer);
|
expect(Notes.animateAppendNote).toHaveBeenCalledWith(
|
||||||
|
note.html,
|
||||||
|
discussionContainer,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -461,9 +501,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
noteHTML = '<div></div>';
|
noteHTML = '<div></div>';
|
||||||
$note = jasmine.createSpyObj('$note', [
|
$note = jasmine.createSpyObj('$note', ['replaceWith']);
|
||||||
'replaceWith'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$updatedNote = Notes.animateUpdateNote(noteHTML, $note);
|
$updatedNote = Notes.animateUpdateNote(noteHTML, $note);
|
||||||
});
|
});
|
||||||
|
@ -501,7 +539,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
<div class="note-text">${sampleComment}</div>
|
<div class="note-text">${sampleComment}</div>
|
||||||
</li>`,
|
</li>`,
|
||||||
note: sampleComment,
|
note: sampleComment,
|
||||||
valid: true
|
valid: true,
|
||||||
};
|
};
|
||||||
let $form;
|
let $form;
|
||||||
let $notesContainer;
|
let $notesContainer;
|
||||||
|
@ -534,10 +572,12 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
mockNotesPost();
|
mockNotesPost();
|
||||||
|
|
||||||
$('.js-comment-button').click();
|
$('.js-comment-button').click();
|
||||||
expect($notesContainer.find('.note.being-posted').length > 0).toEqual(true);
|
expect($notesContainer.find('.note.being-posted').length > 0).toEqual(
|
||||||
|
true,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove placeholder note when new comment is done posting', (done) => {
|
it('should remove placeholder note when new comment is done posting', done => {
|
||||||
mockNotesPost();
|
mockNotesPost();
|
||||||
|
|
||||||
$('.js-comment-button').click();
|
$('.js-comment-button').click();
|
||||||
|
@ -549,33 +589,44 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should disable the submit button when comment button is clicked', (done) => {
|
describe('postComment', () => {
|
||||||
expect($form.find('.js-comment-submit-button').is(':disabled')).toEqual(false);
|
it('disables the submit button', done => {
|
||||||
|
const $submitButton = $form.find('.js-comment-submit-button');
|
||||||
|
expect($submitButton).not.toBeDisabled();
|
||||||
|
const dummyEvent = {
|
||||||
|
preventDefault() {},
|
||||||
|
target: $submitButton,
|
||||||
|
};
|
||||||
|
mock.onPost(NOTES_POST_PATH).replyOnce(() => {
|
||||||
|
expect($submitButton).toBeDisabled();
|
||||||
|
return [200, note];
|
||||||
|
});
|
||||||
|
|
||||||
mockNotesPost();
|
this.notes
|
||||||
$('.js-comment-button').click();
|
.postComment(dummyEvent)
|
||||||
expect($form.find('.js-comment-submit-button').is(':disabled')).toEqual(true);
|
.then(() => {
|
||||||
|
expect($submitButton).not.toBeDisabled();
|
||||||
setTimeout(() => {
|
})
|
||||||
expect($form.find('.js-comment-submit-button').is(':disabled')).toEqual(false);
|
.then(done)
|
||||||
|
.catch(done.fail);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show actual note element when new comment is done posting', (done) => {
|
it('should show actual note element when new comment is done posting', done => {
|
||||||
mockNotesPost();
|
mockNotesPost();
|
||||||
|
|
||||||
$('.js-comment-button').click();
|
$('.js-comment-button').click();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect($notesContainer.find(`#note_${note.id}`).length > 0).toEqual(true);
|
expect($notesContainer.find(`#note_${note.id}`).length > 0).toEqual(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reset Form when new comment is done posting', (done) => {
|
it('should reset Form when new comment is done posting', done => {
|
||||||
mockNotesPost();
|
mockNotesPost();
|
||||||
|
|
||||||
$('.js-comment-button').click();
|
$('.js-comment-button').click();
|
||||||
|
@ -587,19 +638,24 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show flash error message when new comment failed to be posted', (done) => {
|
it('should show flash error message when new comment failed to be posted', done => {
|
||||||
mockNotesPostError();
|
mockNotesPostError();
|
||||||
|
|
||||||
$('.js-comment-button').click();
|
$('.js-comment-button').click();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect($notesContainer.parent().find('.flash-container .flash-text').is(':visible')).toEqual(true);
|
expect(
|
||||||
|
$notesContainer
|
||||||
|
.parent()
|
||||||
|
.find('.flash-container .flash-text')
|
||||||
|
.is(':visible'),
|
||||||
|
).toEqual(true);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show flash error message when comment failed to be updated', (done) => {
|
it('should show flash error message when comment failed to be updated', done => {
|
||||||
mockNotesPost();
|
mockNotesPost();
|
||||||
|
|
||||||
$('.js-comment-button').click();
|
$('.js-comment-button').click();
|
||||||
|
@ -620,7 +676,12 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const $updatedNoteEl = $notesContainer.find(`#note_${note.id}`);
|
const $updatedNoteEl = $notesContainer.find(`#note_${note.id}`);
|
||||||
expect($updatedNoteEl.hasClass('.being-posted')).toEqual(false); // Remove being-posted visuals
|
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(
|
||||||
|
$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
|
expect($('.flash-container').is(':visible')).toEqual(true); // Flash error message shown
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
@ -634,12 +695,12 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
const note = {
|
const note = {
|
||||||
commands_changes: {
|
commands_changes: {
|
||||||
assignee_id: 1,
|
assignee_id: 1,
|
||||||
emoji_award: '100'
|
emoji_award: '100',
|
||||||
},
|
},
|
||||||
errors: {
|
errors: {
|
||||||
commands_only: ['Commands applied']
|
commands_only: ['Commands applied'],
|
||||||
},
|
},
|
||||||
valid: false
|
valid: false,
|
||||||
};
|
};
|
||||||
let $form;
|
let $form;
|
||||||
let $notesContainer;
|
let $notesContainer;
|
||||||
|
@ -654,12 +715,12 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
window.gon.current_user_fullname = 'Administrator';
|
window.gon.current_user_fullname = 'Administrator';
|
||||||
gl.awardsHandler = {
|
gl.awardsHandler = {
|
||||||
addAwardToEmojiBar: () => {},
|
addAwardToEmojiBar: () => {},
|
||||||
scrollToAwards: () => {}
|
scrollToAwards: () => {},
|
||||||
};
|
};
|
||||||
gl.GfmAutoComplete = {
|
gl.GfmAutoComplete = {
|
||||||
dataSources: {
|
dataSources: {
|
||||||
commands: '/root/test-project/autocomplete_sources/commands'
|
commands: '/root/test-project/autocomplete_sources/commands',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
$form = $('form.js-main-target-form');
|
$form = $('form.js-main-target-form');
|
||||||
$notesContainer = $('ul.main-notes-list');
|
$notesContainer = $('ul.main-notes-list');
|
||||||
|
@ -670,14 +731,18 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
mock.restore();
|
mock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove slash command placeholder when comment with slash commands is done posting', (done) => {
|
it('should remove slash command placeholder when comment with slash commands is done posting', done => {
|
||||||
spyOn(gl.awardsHandler, 'addAwardToEmojiBar').and.callThrough();
|
spyOn(gl.awardsHandler, 'addAwardToEmojiBar').and.callThrough();
|
||||||
$('.js-comment-button').click();
|
$('.js-comment-button').click();
|
||||||
|
|
||||||
expect($notesContainer.find('.system-note.being-posted').length).toEqual(1); // Placeholder shown
|
expect(
|
||||||
|
$notesContainer.find('.system-note.being-posted').length,
|
||||||
|
).toEqual(1); // Placeholder shown
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect($notesContainer.find('.system-note.being-posted').length).toEqual(0); // Placeholder removed
|
expect(
|
||||||
|
$notesContainer.find('.system-note.being-posted').length,
|
||||||
|
).toEqual(0); // Placeholder removed
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -692,7 +757,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
<div class="note-text">${sampleComment}</div>
|
<div class="note-text">${sampleComment}</div>
|
||||||
</li>`,
|
</li>`,
|
||||||
note: sampleComment,
|
note: sampleComment,
|
||||||
valid: true
|
valid: true,
|
||||||
};
|
};
|
||||||
let $form;
|
let $form;
|
||||||
let $notesContainer;
|
let $notesContainer;
|
||||||
|
@ -714,7 +779,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
mock.restore();
|
mock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not render a script tag', (done) => {
|
it('should not render a script tag', done => {
|
||||||
$('.js-comment-button').click();
|
$('.js-comment-button').click();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -723,8 +788,15 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
$noteEl.find('textarea.js-note-text').html(updatedComment);
|
$noteEl.find('textarea.js-note-text').html(updatedComment);
|
||||||
$noteEl.find('.js-comment-save-button').click();
|
$noteEl.find('.js-comment-save-button').click();
|
||||||
|
|
||||||
const $updatedNoteEl = $notesContainer.find(`#note_${note.id}`).find('.js-task-list-container');
|
const $updatedNoteEl = $notesContainer
|
||||||
expect($updatedNoteEl.find('.note-text').text().trim()).toEqual('');
|
.find(`#note_${note.id}`)
|
||||||
|
.find('.js-task-list-container');
|
||||||
|
expect(
|
||||||
|
$updatedNoteEl
|
||||||
|
.find('.note-text')
|
||||||
|
.text()
|
||||||
|
.trim(),
|
||||||
|
).toEqual('');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -744,7 +816,9 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
|
|
||||||
it('should return form metadata object from form reference', () => {
|
it('should return form metadata object from form reference', () => {
|
||||||
$form.find('textarea.js-note-text').val(sampleComment);
|
$form.find('textarea.js-note-text').val(sampleComment);
|
||||||
const { formData, formContent, formAction } = this.notes.getFormData($form);
|
const { formData, formContent, formAction } = this.notes.getFormData(
|
||||||
|
$form,
|
||||||
|
);
|
||||||
|
|
||||||
expect(formData.indexOf(sampleComment) > -1).toBe(true);
|
expect(formData.indexOf(sampleComment) > -1).toBe(true);
|
||||||
expect(formContent).toEqual(sampleComment);
|
expect(formContent).toEqual(sampleComment);
|
||||||
|
@ -760,7 +834,9 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
const { formContent } = this.notes.getFormData($form);
|
const { formContent } = this.notes.getFormData($form);
|
||||||
|
|
||||||
expect(_.escape).toHaveBeenCalledWith(sampleComment);
|
expect(_.escape).toHaveBeenCalledWith(sampleComment);
|
||||||
expect(formContent).toEqual('<script>alert("Boom!");</script>');
|
expect(formContent).toEqual(
|
||||||
|
'<script>alert("Boom!");</script>',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -770,7 +846,8 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true when comment begins with a quick action', () => {
|
it('should return true when comment begins with a quick action', () => {
|
||||||
const sampleComment = '/wip\n/milestone %1.0\n/merge\n/unassign Merging this';
|
const sampleComment =
|
||||||
|
'/wip\n/milestone %1.0\n/merge\n/unassign Merging this';
|
||||||
const hasQuickActions = this.notes.hasQuickActions(sampleComment);
|
const hasQuickActions = this.notes.hasQuickActions(sampleComment);
|
||||||
|
|
||||||
expect(hasQuickActions).toBeTruthy();
|
expect(hasQuickActions).toBeTruthy();
|
||||||
|
@ -794,7 +871,8 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
describe('stripQuickActions', () => {
|
describe('stripQuickActions', () => {
|
||||||
it('should strip quick actions from the comment which begins with a quick action', () => {
|
it('should strip quick actions from the comment which begins with a quick action', () => {
|
||||||
this.notes = new Notes();
|
this.notes = new Notes();
|
||||||
const sampleComment = '/wip\n/milestone %1.0\n/merge\n/unassign Merging this';
|
const sampleComment =
|
||||||
|
'/wip\n/milestone %1.0\n/merge\n/unassign Merging this';
|
||||||
const stripedComment = this.notes.stripQuickActions(sampleComment);
|
const stripedComment = this.notes.stripQuickActions(sampleComment);
|
||||||
|
|
||||||
expect(stripedComment).toBe('');
|
expect(stripedComment).toBe('');
|
||||||
|
@ -802,7 +880,8 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
|
|
||||||
it('should strip quick actions from the comment but leaves plain comment if it is present', () => {
|
it('should strip quick actions from the comment but leaves plain comment if it is present', () => {
|
||||||
this.notes = new Notes();
|
this.notes = new Notes();
|
||||||
const sampleComment = '/wip\n/milestone %1.0\n/merge\n/unassign\nMerging this';
|
const sampleComment =
|
||||||
|
'/wip\n/milestone %1.0\n/merge\n/unassign\nMerging this';
|
||||||
const stripedComment = this.notes.stripQuickActions(sampleComment);
|
const stripedComment = this.notes.stripQuickActions(sampleComment);
|
||||||
|
|
||||||
expect(stripedComment).toBe('Merging this');
|
expect(stripedComment).toBe('Merging this');
|
||||||
|
@ -810,7 +889,8 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
|
|
||||||
it('should NOT strip string that has slashes within', () => {
|
it('should NOT strip string that has slashes within', () => {
|
||||||
this.notes = new Notes();
|
this.notes = new Notes();
|
||||||
const sampleComment = 'http://127.0.0.1:3000/root/gitlab-shell/issues/1';
|
const sampleComment =
|
||||||
|
'http://127.0.0.1:3000/root/gitlab-shell/issues/1';
|
||||||
const stripedComment = this.notes.stripQuickActions(sampleComment);
|
const stripedComment = this.notes.stripQuickActions(sampleComment);
|
||||||
|
|
||||||
expect(stripedComment).toBe(sampleComment);
|
expect(stripedComment).toBe(sampleComment);
|
||||||
|
@ -821,7 +901,7 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
const availableQuickActions = [
|
const availableQuickActions = [
|
||||||
{ name: 'close', description: 'Close this issue', params: [] },
|
{ name: 'close', description: 'Close this issue', params: [] },
|
||||||
{ name: 'title', description: 'Change title', params: [{}] },
|
{ name: 'title', description: 'Change title', params: [{}] },
|
||||||
{ name: 'estimate', description: 'Set time estimate', params: [{}] }
|
{ name: 'estimate', description: 'Set time estimate', params: [{}] },
|
||||||
];
|
];
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -830,17 +910,29 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
|
|
||||||
it('should return executing quick action description when note has single quick action', () => {
|
it('should return executing quick action description when note has single quick action', () => {
|
||||||
const sampleComment = '/close';
|
const sampleComment = '/close';
|
||||||
expect(this.notes.getQuickActionDescription(sampleComment, availableQuickActions)).toBe('Applying command to close this issue');
|
expect(
|
||||||
|
this.notes.getQuickActionDescription(
|
||||||
|
sampleComment,
|
||||||
|
availableQuickActions,
|
||||||
|
),
|
||||||
|
).toBe('Applying command to close this issue');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return generic multiple quick action description when note has multiple quick actions', () => {
|
it('should return generic multiple quick action description when note has multiple quick actions', () => {
|
||||||
const sampleComment = '/close\n/title [Duplicate] Issue foobar';
|
const sampleComment = '/close\n/title [Duplicate] Issue foobar';
|
||||||
expect(this.notes.getQuickActionDescription(sampleComment, availableQuickActions)).toBe('Applying multiple commands');
|
expect(
|
||||||
|
this.notes.getQuickActionDescription(
|
||||||
|
sampleComment,
|
||||||
|
availableQuickActions,
|
||||||
|
),
|
||||||
|
).toBe('Applying multiple commands');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return generic quick action description when available quick actions list is not populated', () => {
|
it('should return generic quick action description when available quick actions list is not populated', () => {
|
||||||
const sampleComment = '/close\n/title [Duplicate] Issue foobar';
|
const sampleComment = '/close\n/title [Duplicate] Issue foobar';
|
||||||
expect(this.notes.getQuickActionDescription(sampleComment)).toBe('Applying command');
|
expect(this.notes.getQuickActionDescription(sampleComment)).toBe(
|
||||||
|
'Applying command',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -870,14 +962,35 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
expect($tempNote.attr('id')).toEqual(uniqueId);
|
expect($tempNote.attr('id')).toEqual(uniqueId);
|
||||||
expect($tempNote.hasClass('being-posted')).toBeTruthy();
|
expect($tempNote.hasClass('being-posted')).toBeTruthy();
|
||||||
expect($tempNote.hasClass('fade-in-half')).toBeTruthy();
|
expect($tempNote.hasClass('fade-in-half')).toBeTruthy();
|
||||||
$tempNote.find('.timeline-icon > a, .note-header-info > a').each(function() {
|
$tempNote
|
||||||
expect($(this).attr('href')).toEqual(`/${currentUsername}`);
|
.find('.timeline-icon > a, .note-header-info > a')
|
||||||
});
|
.each(function() {
|
||||||
expect($tempNote.find('.timeline-icon .avatar').attr('src')).toEqual(currentUserAvatar);
|
expect($(this).attr('href')).toEqual(`/${currentUsername}`);
|
||||||
expect($tempNote.find('.timeline-content').hasClass('discussion')).toBeFalsy();
|
});
|
||||||
expect($tempNoteHeader.find('.hidden-xs').text().trim()).toEqual(currentUserFullname);
|
expect($tempNote.find('.timeline-icon .avatar').attr('src')).toEqual(
|
||||||
expect($tempNoteHeader.find('.note-headline-light').text().trim()).toEqual(`@${currentUsername}`);
|
currentUserAvatar,
|
||||||
expect($tempNote.find('.note-body .note-text p').text().trim()).toEqual(sampleComment);
|
);
|
||||||
|
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}`);
|
||||||
|
expect(
|
||||||
|
$tempNote
|
||||||
|
.find('.note-body .note-text p')
|
||||||
|
.text()
|
||||||
|
.trim(),
|
||||||
|
).toEqual(sampleComment);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return constructed placeholder element for discussion note based on form contents', () => {
|
it('should return constructed placeholder element for discussion note based on form contents', () => {
|
||||||
|
@ -886,11 +999,13 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
uniqueId,
|
uniqueId,
|
||||||
isDiscussionNote: true,
|
isDiscussionNote: true,
|
||||||
currentUsername,
|
currentUsername,
|
||||||
currentUserFullname
|
currentUserFullname,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect($tempNote.prop('nodeName')).toEqual('LI');
|
expect($tempNote.prop('nodeName')).toEqual('LI');
|
||||||
expect($tempNote.find('.timeline-content').hasClass('discussion')).toBeTruthy();
|
expect(
|
||||||
|
$tempNote.find('.timeline-content').hasClass('discussion'),
|
||||||
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a escaped user name', () => {
|
it('should return a escaped user name', () => {
|
||||||
|
@ -904,7 +1019,12 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
currentUserAvatar,
|
currentUserAvatar,
|
||||||
});
|
});
|
||||||
const $tempNoteHeader = $tempNote.find('.note-header');
|
const $tempNoteHeader = $tempNote.find('.note-header');
|
||||||
expect($tempNoteHeader.find('.hidden-xs').text().trim()).toEqual('Foo <script>alert("XSS")</script>');
|
expect(
|
||||||
|
$tempNoteHeader
|
||||||
|
.find('.hidden-xs')
|
||||||
|
.text()
|
||||||
|
.trim(),
|
||||||
|
).toEqual('Foo <script>alert("XSS")</script>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -927,7 +1047,12 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
expect($tempNote.attr('id')).toEqual(uniqueId);
|
expect($tempNote.attr('id')).toEqual(uniqueId);
|
||||||
expect($tempNote.hasClass('being-posted')).toBeTruthy();
|
expect($tempNote.hasClass('being-posted')).toBeTruthy();
|
||||||
expect($tempNote.hasClass('fade-in-half')).toBeTruthy();
|
expect($tempNote.hasClass('fade-in-half')).toBeTruthy();
|
||||||
expect($tempNote.find('.timeline-content i').text().trim()).toEqual(sampleCommandDescription);
|
expect(
|
||||||
|
$tempNote
|
||||||
|
.find('.timeline-content i')
|
||||||
|
.text()
|
||||||
|
.trim(),
|
||||||
|
).toEqual(sampleCommandDescription);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -937,7 +1062,11 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows a flash message', () => {
|
it('shows a flash message', () => {
|
||||||
this.notes.addFlash('Error message', FLASH_TYPE_ALERT, this.notes.parentTimeline.get(0));
|
this.notes.addFlash(
|
||||||
|
'Error message',
|
||||||
|
FLASH_TYPE_ALERT,
|
||||||
|
this.notes.parentTimeline.get(0),
|
||||||
|
);
|
||||||
|
|
||||||
expect($('.flash-alert').is(':visible')).toBeTruthy();
|
expect($('.flash-alert').is(':visible')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
@ -950,7 +1079,11 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hides visible flash message', () => {
|
it('hides visible flash message', () => {
|
||||||
this.notes.addFlash('Error message 1', FLASH_TYPE_ALERT, this.notes.parentTimeline.get(0));
|
this.notes.addFlash(
|
||||||
|
'Error message 1',
|
||||||
|
FLASH_TYPE_ALERT,
|
||||||
|
this.notes.parentTimeline.get(0),
|
||||||
|
);
|
||||||
|
|
||||||
this.notes.clearFlash();
|
this.notes.clearFlash();
|
||||||
|
|
||||||
|
@ -958,4 +1091,4 @@ import timeoutPromise from './helpers/set_timeout_promise_helper';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).call(window);
|
}.call(window));
|
||||||
|
|
Loading…
Reference in New Issue