debian-mirror-gitlab/spec/javascripts/gl_form_spec.js

109 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-03-27 19:54:05 +05:30
import autosize from 'autosize';
2018-03-17 18:26:18 +05:30
import GLForm from '~/gl_form';
2017-09-10 17:25:29 +05:30
import '~/lib/utils/text_utility';
import '~/lib/utils/common_utils';
2017-08-17 22:00:37 +05:30
describe('GLForm', () => {
describe('when instantiated', function () {
beforeEach((done) => {
this.form = $('<form class="gfm-form"><textarea class="js-gfm-input"></form>');
this.textarea = this.form.find('textarea');
spyOn($.prototype, 'off').and.returnValue(this.textarea);
spyOn($.prototype, 'on').and.returnValue(this.textarea);
spyOn($.prototype, 'css');
2018-03-27 19:54:05 +05:30
this.glForm = new GLForm(this.form, false);
2017-08-17 22:00:37 +05:30
setTimeout(() => {
$.prototype.off.calls.reset();
$.prototype.on.calls.reset();
$.prototype.css.calls.reset();
done();
});
});
2017-09-10 17:25:29 +05:30
describe('setupAutosize', () => {
2017-08-17 22:00:37 +05:30
beforeEach((done) => {
this.glForm.setupAutosize();
setTimeout(() => {
done();
});
});
it('should register an autosize event handler on the textarea', () => {
expect($.prototype.off).toHaveBeenCalledWith('autosize:resized');
expect($.prototype.on).toHaveBeenCalledWith('autosize:resized', jasmine.any(Function));
});
it('should register a mouseup event handler on the textarea', () => {
expect($.prototype.off).toHaveBeenCalledWith('mouseup.autosize');
expect($.prototype.on).toHaveBeenCalledWith('mouseup.autosize', jasmine.any(Function));
});
it('should set the resize css property to vertical', () => {
expect($.prototype.css).toHaveBeenCalledWith('resize', 'vertical');
});
});
2017-09-10 17:25:29 +05:30
describe('setHeightData', () => {
2017-08-17 22:00:37 +05:30
beforeEach(() => {
spyOn($.prototype, 'data');
spyOn($.prototype, 'outerHeight').and.returnValue(200);
this.glForm.setHeightData();
});
it('should set the height data attribute', () => {
expect($.prototype.data).toHaveBeenCalledWith('height', 200);
});
it('should call outerHeight', () => {
expect($.prototype.outerHeight).toHaveBeenCalled();
});
});
2017-09-10 17:25:29 +05:30
describe('destroyAutosize', () => {
2017-08-17 22:00:37 +05:30
describe('when called', () => {
beforeEach(() => {
spyOn($.prototype, 'data');
spyOn($.prototype, 'outerHeight').and.returnValue(200);
spyOn(window, 'outerHeight').and.returnValue(400);
2018-03-27 19:54:05 +05:30
spyOn(autosize, 'destroy');
2017-08-17 22:00:37 +05:30
this.glForm.destroyAutosize();
});
it('should call outerHeight', () => {
expect($.prototype.outerHeight).toHaveBeenCalled();
});
it('should get data-height attribute', () => {
expect($.prototype.data).toHaveBeenCalledWith('height');
});
it('should call autosize destroy', () => {
2018-03-27 19:54:05 +05:30
expect(autosize.destroy).toHaveBeenCalledWith(this.textarea);
2017-08-17 22:00:37 +05:30
});
it('should set the data-height attribute', () => {
expect($.prototype.data).toHaveBeenCalledWith('height', 200);
});
it('should set the outerHeight', () => {
expect($.prototype.outerHeight).toHaveBeenCalledWith(200);
});
it('should set the css', () => {
expect($.prototype.css).toHaveBeenCalledWith('max-height', window.outerHeight);
});
});
it('should return undefined if the data-height equals the outerHeight', () => {
spyOn($.prototype, 'outerHeight').and.returnValue(200);
spyOn($.prototype, 'data').and.returnValue(200);
2018-03-27 19:54:05 +05:30
spyOn(autosize, 'destroy');
2017-08-17 22:00:37 +05:30
expect(this.glForm.destroyAutosize()).toBeUndefined();
2018-03-27 19:54:05 +05:30
expect(autosize.destroy).not.toHaveBeenCalled();
2017-08-17 22:00:37 +05:30
});
});
});
});