index.spec.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. describe('editors', () => {
  2. const id = 'testContainer';
  3. const {
  4. registerEditor,
  5. getEditor,
  6. } = Handsontable.editors;
  7. beforeEach(function() {
  8. this.$container = $(`<div id="${id}"></div>`).appendTo('body');
  9. });
  10. afterEach(function() {
  11. if (this.$container) {
  12. destroy();
  13. this.$container.remove();
  14. }
  15. });
  16. it('should register custom editor', () => {
  17. class MyEditor extends Handsontable.editors.BaseEditor {
  18. init() {
  19. this.TEXTAREA = document.createElement('TEXTAREA');
  20. this.TEXTAREA_PARENT = document.createElement('DIV');
  21. this.TEXTAREA_PARENT.appendChild(this.TEXTAREA);
  22. this.instance.rootElement.appendChild(this.TEXTAREA_PARENT);
  23. }
  24. getValue() {
  25. return `--${this.TEXTAREA.value}--`;
  26. }
  27. setValue(value) {
  28. this.TEXTAREA.value = value;
  29. }
  30. open() {}
  31. close() {}
  32. focus() {
  33. this.TEXTAREA.focus();
  34. }
  35. }
  36. registerEditor('myEditor', MyEditor);
  37. const hot = handsontable({
  38. data: [
  39. [1, 6, 10],
  40. ],
  41. columns: [{
  42. editor: 'myEditor',
  43. }],
  44. });
  45. selectCell(0, 0);
  46. keyDown('enter');
  47. document.activeElement.value = 'hello';
  48. destroyEditor();
  49. expect(getDataAtCell(0, 0)).toBe('--hello--');
  50. });
  51. it('should retrieve predefined editors by its names', () => {
  52. expect(getEditor('autocomplete')).toBeFunction();
  53. expect(getEditor('base')).toBeFunction();
  54. expect(getEditor('checkbox')).toBeFunction();
  55. expect(getEditor('date')).toBeFunction();
  56. expect(getEditor('dropdown')).toBeFunction();
  57. expect(getEditor('handsontable')).toBeFunction();
  58. expect(getEditor('mobile')).toBeFunction();
  59. expect(getEditor('numeric')).toBeFunction();
  60. expect(getEditor('password')).toBeFunction();
  61. expect(getEditor('select')).toBeFunction();
  62. expect(getEditor('text')).toBeFunction();
  63. });
  64. it('should retrieve custom editor by its names', () => {
  65. class MyEditor {}
  66. registerEditor('myEditor', MyEditor);
  67. expect(getEditor('myEditor')).toBe(MyEditor);
  68. });
  69. });