123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- describe('settings', () => {
- describe('editor', () => {
- var id = 'testContainer';
- beforeEach(function() {
- this.$container = $(`<div id="${id}"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- describe('defined in constructor', () => {
- it('should use text editor by default', () => {
- var textEditorPrototype = Handsontable.editors.TextEditor.prototype;
- spyOn(textEditorPrototype, 'init').and.callThrough();
- handsontable();
- selectCell(0, 0);
- expect(textEditorPrototype.init).toHaveBeenCalled();
- });
- it('should use editor from predefined string', () => {
- var textEditorPrototype = Handsontable.editors.TextEditor.prototype;
- var checkboxEditorPrototype = Handsontable.editors.CheckboxEditor.prototype;
- spyOn(textEditorPrototype, 'init');
- spyOn(checkboxEditorPrototype, 'init');
- handsontable({
- columns: [
- {
- editor: 'checkbox'
- }
- ]
- });
- selectCell(0, 0);
- expect(textEditorPrototype.init).not.toHaveBeenCalled();
- expect(checkboxEditorPrototype.init).toHaveBeenCalled();
- });
- it('should use editor from predefined string when columns is a function', () => {
- var textEditorPrototype = Handsontable.editors.TextEditor.prototype;
- var checkboxEditorPrototype = Handsontable.editors.CheckboxEditor.prototype;
- spyOn(textEditorPrototype, 'init');
- spyOn(checkboxEditorPrototype, 'init');
- handsontable({
- columns(column) {
- return column === 0 ? {editor: 'checkbox'} : null;
- }
- });
- selectCell(0, 0);
- expect(textEditorPrototype.init).not.toHaveBeenCalled();
- expect(checkboxEditorPrototype.init).toHaveBeenCalled();
- });
- it('should use editor class passed directly', () => {
- var customEditor = jasmine.createSpy('customEditor');
- customEditor.and.callFake(function() {
- this.prepare = function() {};
- });
- handsontable({
- columns: [
- {
- editor: customEditor
- }
- ]
- });
- selectCell(0, 0);
- expect(customEditor).toHaveBeenCalled();
- });
- it('should use editor class passed directly when columns is a function', () => {
- var customEditor = jasmine.createSpy('customEditor');
- customEditor.and.callFake(function() {
- this.prepare = function() {};
- });
- handsontable({
- columns(column) {
- return column === 0 ? {editor: customEditor} : null;
- }
- });
- selectCell(0, 0);
- expect(customEditor).toHaveBeenCalled();
- });
- it('should use editor from custom string', () => {
- var customEditor = jasmine.createSpy('customEditor');
- customEditor.and.callFake(function() {
- this.prepare = function() {};
- });
- Handsontable.editors.registerEditor('myEditor', customEditor);
- handsontable({
- columns: [
- {
- editor: 'myEditor'
- }
- ]
- });
- selectCell(0, 0);
- expect(customEditor).toHaveBeenCalled();
- });
- it('should use editor from custom string when columns is a function', () => {
- var customEditor = jasmine.createSpy('customEditor');
- customEditor.and.callFake(function() {
- this.prepare = function() {};
- });
- Handsontable.editors.registerEditor('myEditor', customEditor);
- handsontable({
- columns(column) {
- return column === 0 ? {editor: 'myEditor'} : null;
- },
- });
- selectCell(0, 0);
- expect(customEditor).toHaveBeenCalled();
- });
- });
- });
- });
|