2017-10-31 05:18:30 -04:00
|
|
|
import Autosize from 'autosize';
|
2017-10-10 05:47:29 -04:00
|
|
|
import GLForm from '~/gl_form';
|
2017-05-16 17:01:51 -04:00
|
|
|
import '~/lib/utils/text_utility';
|
|
|
|
import '~/lib/utils/common_utils';
|
2017-01-31 15:38:45 -05:00
|
|
|
|
2017-10-31 05:18:30 -04:00
|
|
|
window.autosize = Autosize;
|
2017-01-03 07:04:33 -05:00
|
|
|
|
|
|
|
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');
|
|
|
|
spyOn(window, 'autosize');
|
|
|
|
|
|
|
|
this.glForm = new GLForm(this.form);
|
|
|
|
setTimeout(() => {
|
|
|
|
$.prototype.off.calls.reset();
|
|
|
|
$.prototype.on.calls.reset();
|
|
|
|
$.prototype.css.calls.reset();
|
2017-05-16 17:16:36 -04:00
|
|
|
window.autosize.calls.reset();
|
2017-01-03 07:04:33 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-05 18:17:08 -04:00
|
|
|
describe('setupAutosize', () => {
|
2017-01-03 07:04:33 -05:00
|
|
|
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 autosize the textarea', () => {
|
2017-05-16 17:16:36 -04:00
|
|
|
expect(window.autosize).toHaveBeenCalledWith(jasmine.any(Object));
|
2017-01-03 07:04:33 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should set the resize css property to vertical', () => {
|
|
|
|
expect($.prototype.css).toHaveBeenCalledWith('resize', 'vertical');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-05 18:17:08 -04:00
|
|
|
describe('setHeightData', () => {
|
2017-01-03 07:04:33 -05:00
|
|
|
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-05-05 18:17:08 -04:00
|
|
|
describe('destroyAutosize', () => {
|
2017-01-03 07:04:33 -05:00
|
|
|
describe('when called', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn($.prototype, 'data');
|
|
|
|
spyOn($.prototype, 'outerHeight').and.returnValue(200);
|
|
|
|
spyOn(window, 'outerHeight').and.returnValue(400);
|
2017-05-16 17:16:36 -04:00
|
|
|
spyOn(window.autosize, 'destroy');
|
2017-01-03 07:04:33 -05:00
|
|
|
|
|
|
|
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', () => {
|
2017-05-16 17:16:36 -04:00
|
|
|
expect(window.autosize.destroy).toHaveBeenCalledWith(this.textarea);
|
2017-01-03 07:04:33 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
2017-05-16 17:16:36 -04:00
|
|
|
spyOn(window.autosize, 'destroy');
|
2017-01-03 07:04:33 -05:00
|
|
|
expect(this.glForm.destroyAutosize()).toBeUndefined();
|
2017-05-16 17:16:36 -04:00
|
|
|
expect(window.autosize.destroy).not.toHaveBeenCalled();
|
2017-01-03 07:04:33 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|