baseEditor.spec.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. describe('BaseEditor', () => {
  2. const id = 'testContainer';
  3. beforeEach(function() {
  4. this.$container = $(`<div id="${id}" style="width: 300px; height: 200px; overflow: auto"></div>`).appendTo('body');
  5. });
  6. afterEach(function() {
  7. if (this.$container) {
  8. destroy();
  9. this.$container.remove();
  10. }
  11. });
  12. describe('ctrl + enter when editor is active', () => {
  13. it('should populate value from the currently active cell to every cell in the selected range', () => {
  14. handsontable({
  15. data: Handsontable.helper.createSpreadsheetData(6, 6)
  16. });
  17. selectCell(1, 1, 2, 2);
  18. expect(getDataAtCell(1, 1)).toEqual('B2');
  19. expect(getDataAtCell(2, 2)).toEqual('C3');
  20. keyDown(Handsontable.helper.KEY_CODES.ENTER);
  21. keyDown('ctrl+enter');
  22. expect(getDataAtCell(1, 1)).toEqual('B2');
  23. expect(getDataAtCell(1, 2)).toEqual('B2');
  24. expect(getDataAtCell(2, 1)).toEqual('B2');
  25. expect(getDataAtCell(2, 2)).toEqual('B2');
  26. loadData(Handsontable.helper.createSpreadsheetData(6, 6));
  27. selectCell(1, 2, 2, 1);
  28. expect(getDataAtCell(1, 2)).toEqual('C2');
  29. expect(getDataAtCell(2, 1)).toEqual('B3');
  30. keyDown(Handsontable.helper.KEY_CODES.ENTER);
  31. keyDown('ctrl+enter');
  32. expect(getDataAtCell(1, 1)).toEqual('C2');
  33. expect(getDataAtCell(1, 2)).toEqual('C2');
  34. expect(getDataAtCell(2, 1)).toEqual('C2');
  35. expect(getDataAtCell(2, 2)).toEqual('C2');
  36. loadData(Handsontable.helper.createSpreadsheetData(6, 6));
  37. selectCell(2, 2, 1, 1);
  38. expect(getDataAtCell(2, 2)).toEqual('C3');
  39. keyDown(Handsontable.helper.KEY_CODES.ENTER);
  40. keyDown('ctrl+enter');
  41. expect(getDataAtCell(1, 1)).toEqual('C3');
  42. expect(getDataAtCell(1, 2)).toEqual('C3');
  43. expect(getDataAtCell(2, 1)).toEqual('C3');
  44. expect(getDataAtCell(2, 2)).toEqual('C3');
  45. loadData(Handsontable.helper.createSpreadsheetData(6, 6));
  46. selectCell(2, 1, 1, 2);
  47. expect(getDataAtCell(2, 1)).toEqual('B3');
  48. keyDown(Handsontable.helper.KEY_CODES.ENTER);
  49. keyDown('ctrl+enter');
  50. expect(getDataAtCell(1, 1)).toEqual('B3');
  51. expect(getDataAtCell(1, 2)).toEqual('B3');
  52. expect(getDataAtCell(2, 1)).toEqual('B3');
  53. expect(getDataAtCell(2, 2)).toEqual('B3');
  54. });
  55. });
  56. it('should exported all editors into Handsontable.editors object', () => {
  57. expect(Handsontable.editors.AutocompleteEditor).toBeDefined();
  58. expect(Handsontable.editors.BaseEditor).toBeDefined();
  59. expect(Handsontable.editors.CheckboxEditor).toBeDefined();
  60. expect(Handsontable.editors.DateEditor).toBeDefined();
  61. expect(Handsontable.editors.DropdownEditor).toBeDefined();
  62. expect(Handsontable.editors.HandsontableEditor).toBeDefined();
  63. expect(Handsontable.editors.NumericEditor).toBeDefined();
  64. expect(Handsontable.editors.PasswordEditor).toBeDefined();
  65. expect(Handsontable.editors.SelectEditor).toBeDefined();
  66. expect(Handsontable.editors.TextEditor).toBeDefined();
  67. });
  68. describe('IME support', () => {
  69. it('should not throw an error when composition is started in multiple instances environment', async() => {
  70. const errorSpy = jasmine.createSpyObj('error', ['test']);
  71. const prevError = window.onerror;
  72. window.onerror = errorSpy.test;
  73. const hot1 = handsontable({});
  74. const container2 = $(`<div id="${id}2" style="width: 300px; height: 200px; overflow: auto"></div>`).appendTo('body');
  75. const hot2 = container2.handsontable().handsontable('getInstance');
  76. $(hot1.getCell(1, 1)).simulate('mousedown');
  77. $(hot1.getCell(1, 1)).simulate('mouseover');
  78. $(hot1.getCell(1, 1)).simulate('mouseup');
  79. document.documentElement.dispatchEvent(new CompositionEvent('compositionstart'));
  80. $(hot2.getCell(1, 1)).simulate('mousedown');
  81. $(hot2.getCell(1, 1)).simulate('mouseover');
  82. $(hot2.getCell(1, 1)).simulate('mouseup');
  83. document.documentElement.dispatchEvent(new CompositionEvent('compositionstart'));
  84. expect(errorSpy.test).not.toHaveBeenCalled();
  85. hot2.destroy();
  86. container2.remove();
  87. window.onerror = prevError;
  88. });
  89. });
  90. });