summaryrefslogtreecommitdiff
path: root/spec/javascripts/notes_spec.js
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-05-07 15:00:58 +0100
committerFilipa Lacerda <filipa@gitlab.com>2017-05-07 15:00:58 +0100
commit842918602dbe622dc20593c0abea5293e304ac62 (patch)
treec748164aab8cfa43fe3332640c60e3308b4e9c29 /spec/javascripts/notes_spec.js
parent214d7880c3d651b367eb73651a6e0e3046868287 (diff)
parent6ad3814e1b31bfacfae7a2aabb4e4607b12ca66f (diff)
downloadgitlab-ce-remove-old-isobject.tar.gz
Merge branch 'master' into remove-old-isobjectremove-old-isobject
* master: (226 commits) Real time pipeline show action Fix `Routable.find_by_full_path` on MySQL add CHANGELOG.md entry for !11138 add tooltips to user contrib graph key Use an absolute path for locale path in FastGettext config Colorize labels in issue search field Fix Karma failures for jQuery deferreds Reduce risk of deadlocks Fix failing spec and eslint Resolve discussions Resolve discussions Dry up routable lookups. Fixes #30317 Add “project moved” flash message on redirect Resolve discussions Fix Rubocop failures Index redirect_routes path for LIKE Add index for source association and for path Fix or workaround spec failure Refactor Delete conflicting redirects ...
Diffstat (limited to 'spec/javascripts/notes_spec.js')
-rw-r--r--spec/javascripts/notes_spec.js217
1 files changed, 88 insertions, 129 deletions
diff --git a/spec/javascripts/notes_spec.js b/spec/javascripts/notes_spec.js
index 7bffa90ab14..cfd599f793e 100644
--- a/spec/javascripts/notes_spec.js
+++ b/spec/javascripts/notes_spec.js
@@ -29,7 +29,7 @@ import '~/notes';
$('.js-comment-button').on('click', function(e) {
e.preventDefault();
});
- this.notes = new Notes();
+ this.notes = new Notes('', []);
});
it('modifies the Markdown field', function() {
@@ -51,7 +51,7 @@ import '~/notes';
var textarea = '.js-note-text';
beforeEach(function() {
- this.notes = new Notes();
+ this.notes = new Notes('', []);
this.autoSizeSpy = spyOnEvent($(textarea), 'autosize:update');
spyOn(this.notes, 'renderNote').and.stub();
@@ -273,9 +273,92 @@ import '~/notes';
});
});
+ 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
+ });
+ });
+
describe('getFormData', () => {
it('should return form metadata object from form reference', () => {
- this.notes = new Notes();
+ this.notes = new Notes('', []);
const $form = $('form');
const sampleComment = 'foobar';
@@ -290,7 +373,7 @@ import '~/notes';
describe('hasSlashCommands', () => {
beforeEach(() => {
- this.notes = new Notes();
+ this.notes = new Notes('', []);
});
it('should return true when comment has slash commands', () => {
@@ -327,7 +410,7 @@ import '~/notes';
const currentUserFullname = 'Administrator';
beforeEach(() => {
- this.notes = new Notes();
+ this.notes = new Notes('', []);
});
it('should return constructed placeholder element for regular note based on form contents', () => {
@@ -364,129 +447,5 @@ import '~/notes';
expect($tempNote.find('.timeline-content').hasClass('discussion')).toBeTruthy();
});
});
-
- 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');
- $notesContainer = $('ul.main-notes-list');
- $form.find('textarea.js-note-text').val(sampleComment);
- $('.js-comment-button').click();
- });
-
- it('should show placeholder note while new comment is being posted', () => {
- expect($notesContainer.find('.note.being-posted').length > 0).toEqual(true);
- });
-
- it('should remove placeholder note when new comment is done posting', () => {
- spyOn($, 'ajax').and.callFake((options) => {
- options.success(note);
- expect($notesContainer.find('.note.being-posted').length).toEqual(0);
- });
- });
-
- it('should show actual note element when new comment is done posting', () => {
- spyOn($, 'ajax').and.callFake((options) => {
- options.success(note);
- expect($notesContainer.find(`#${note.id}`).length > 0).toEqual(true);
- });
- });
-
- it('should reset Form when new comment is done posting', () => {
- spyOn($, 'ajax').and.callFake((options) => {
- options.success(note);
- expect($form.find('textarea.js-note-text')).toEqual('');
- });
- });
-
- it('should trigger ajax:success event on Form when new comment is done posting', () => {
- spyOn($, 'ajax').and.callFake((options) => {
- options.success(note);
- spyOn($form, 'trigger');
- expect($form.trigger).toHaveBeenCalledWith('ajax:success', [note]);
- });
- });
-
- it('should show flash error message when new comment failed to be posted', () => {
- spyOn($, 'ajax').and.callFake((options) => {
- options.error();
- expect($notesContainer.parent().find('.flash-container .flash-text').is(':visible')).toEqual(true);
- });
- });
-
- it('should refill form textarea with original comment content when new comment failed to be posted', () => {
- spyOn($, 'ajax').and.callFake((options) => {
- options.error();
- expect($form.find('textarea.js-note-text')).toEqual(sampleComment);
- });
- });
-
- it('should show updated comment as _actively being posted_ while comment being updated', () => {
- spyOn($, 'ajax').and.callFake((options) => {
- options.success(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();
- expect($noteEl.hasClass('.being-posted')).toEqual(true);
- expect($noteEl.find('.note-text').text()).toEqual(updatedComment);
- });
- });
-
- it('should show updated comment when comment update is done posting', () => {
- spyOn($, 'ajax').and.callFake((options) => {
- options.success(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();
-
- spyOn($, 'ajax').and.callFake((updateOptions) => {
- const updatedNote = Object.assign({}, note);
- updatedNote.note = updatedComment;
- updatedNote.html = `<li class="note note-row-1234 timeline-entry" id="note_1234">
- <div class="note-text">${updatedComment}</div>
- </li>`;
- updateOptions.success(updatedNote);
- const $updatedNoteEl = $notesContainer.find(`#note_${updatedNote.id}`);
- expect($updatedNoteEl.hasClass('.being-posted')).toEqual(false); // Remove being-posted visuals
- expect($updatedNoteEl.find('note-text').text().trim()).toEqual(updatedComment); // Verify if comment text updated
- });
- });
- });
-
- it('should show flash error message when comment failed to be updated', () => {
- spyOn($, 'ajax').and.callFake((options) => {
- options.success(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();
-
- spyOn($, 'ajax').and.callFake((updateOptions) => {
- updateOptions.error();
- 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($notesContainer.parent().find('.flash-container .flash-text').is(':visible')).toEqual(true); // Flash error message shown
- });
- });
- });
- });
});
}).call(window);