gitlab-org--gitlab-foss/spec/javascripts/notes_spec.js

80 lines
2.3 KiB
JavaScript
Raw Normal View History

/* eslint-disable space-before-function-paren, no-unused-expressions, no-var, object-shorthand, comma-dangle, semi, padded-blocks, max-len */
/* global Notes */
2016-07-24 16:45:11 -04:00
/*= require notes */
2016-08-31 10:32:48 -04:00
/*= require autosize */
2016-07-24 16:45:11 -04:00
/*= require gl_form */
2016-08-31 10:32:48 -04:00
/*= require lib/utils/text_utility */
2016-07-24 16:45:11 -04:00
(function() {
window.gon || (window.gon = {});
window.gl = window.gl || {};
gl.utils = gl.utils || {};
2016-07-24 16:45:11 -04:00
describe('Notes', function() {
var commentsTemplate = 'issues/issue_with_comment.html.raw';
preloadFixtures(commentsTemplate);
2016-08-31 10:32:48 -04:00
beforeEach(function () {
loadFixtures(commentsTemplate);
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');
});
describe('task lists', function() {
2016-07-24 16:45:11 -04:00
beforeEach(function() {
$('form').on('submit', function(e) {
2016-08-31 10:32:48 -04:00
e.preventDefault();
2016-07-24 16:45:11 -04:00
});
2016-08-31 10:32:48 -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
it('submits the form on tasklist:changed', function() {
var submitted = false;
2016-07-24 16:45:11 -04:00
$('form').on('submit', function(e) {
submitted = true;
2016-08-31 10:32:48 -04:00
e.preventDefault();
2016-07-24 16:45:11 -04:00
});
2016-08-31 10:32:48 -04:00
2016-07-24 16:45:11 -04:00
$('.js-task-list-field').trigger('tasklist:changed');
2016-08-31 10:32:48 -04:00
expect(submitted).toBe(true);
});
});
describe('comments', function() {
var textarea = '.js-note-text';
beforeEach(function() {
this.notes = new Notes();
this.autoSizeSpy = spyOnEvent($(textarea), 'autosize:update');
spyOn(this.notes, 'renderNote').and.stub();
$(textarea).data('autosave', {
reset: function() {}
});
$('form').on('submit', function(e) {
e.preventDefault();
$('.js-main-target-form').trigger('ajax:success');
});
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();
})
2016-07-24 16:45:11 -04:00
});
});
}).call(this);