noEditor.spec.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. describe('noEditor', () => {
  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. it('shouldn\'t begin editing when enterBeginsEditing equals true', () => {
  13. handsontable({
  14. enterBeginsEditing: true,
  15. editor: false
  16. });
  17. selectCell(2, 2);
  18. keyDown('enter');
  19. expect(getSelected()).toEqual([[2, 2, 2, 2]]);
  20. expect(isEditorVisible()).toEqual(false);
  21. });
  22. it('shouldn\'t move down after editing', () => {
  23. handsontable({
  24. editor: false
  25. });
  26. selectCell(2, 2);
  27. keyDown('enter');
  28. keyDown('enter');
  29. expect(getSelected()).toEqual([[2, 2, 2, 2]]);
  30. });
  31. it('shouldn\'t move down when enterBeginsEditing equals false', () => {
  32. handsontable({
  33. enterBeginsEditing: false,
  34. editor: false
  35. });
  36. selectCell(2, 2);
  37. keyDown('enter');
  38. expect(getSelected()).toEqual([[3, 2, 3, 2]]);
  39. expect(isEditorVisible()).toEqual(false);
  40. });
  41. it('shouldn\'t render any value in editor', () => {
  42. handsontable({
  43. editor: false
  44. });
  45. setDataAtCell(2, 2, 'string');
  46. selectCell(2, 2);
  47. keyDown('enter');
  48. expect(keyProxy().length).toEqual(0);
  49. });
  50. it('shouldn\'t open editor after hitting F2', () => {
  51. handsontable({
  52. editor: false
  53. });
  54. selectCell(2, 2);
  55. expect(isEditorVisible()).toEqual(false);
  56. keyDown('f2');
  57. expect(isEditorVisible()).toEqual(false);
  58. });
  59. it('shouldn\'t open editor after hitting CapsLock', () => {
  60. handsontable({
  61. editor: false
  62. });
  63. selectCell(2, 2);
  64. expect(isEditorVisible()).toEqual(false);
  65. keyDown(Handsontable.helper.KEY_CODES.CAPS_LOCK);
  66. expect(isEditorVisible()).toEqual(false);
  67. });
  68. it('shouldn\'t open editor after double clicking on a cell', (done) => {
  69. const hot = handsontable({
  70. data: Handsontable.helper.createSpreadsheetData(5, 2),
  71. editor: false
  72. });
  73. const cell = $(getCell(0, 0));
  74. let clicks = 0;
  75. window.scrollTo(0, cell.offset().top);
  76. setTimeout(() => {
  77. mouseDown(cell);
  78. mouseUp(cell);
  79. clicks += 1;
  80. }, 0);
  81. setTimeout(() => {
  82. mouseDown(cell);
  83. mouseUp(cell);
  84. clicks += 1;
  85. }, 100);
  86. setTimeout(() => {
  87. expect(clicks).toBe(2);
  88. expect(hot.getActiveEditor()).toBe(undefined);
  89. expect(isEditorVisible()).toBe(false);
  90. done();
  91. }, 200);
  92. });
  93. it('should not open editor after pressing a printable character', () => {
  94. handsontable({
  95. data: Handsontable.helper.createSpreadsheetData(3, 3),
  96. editor: false
  97. });
  98. selectCell(0, 0);
  99. expect(isEditorVisible()).toBe(false);
  100. spec().$container.simulate('keydown', { keyCode: 'a'.charCodeAt(0) });
  101. expect(isEditorVisible()).toBe(false);
  102. });
  103. it('should not open editor after pressing a printable character with shift key', () => {
  104. handsontable({
  105. data: Handsontable.helper.createSpreadsheetData(3, 3),
  106. editor: false
  107. });
  108. selectCell(0, 0);
  109. expect(isEditorVisible()).toBe(false);
  110. spec().$container.simulate('keydown', { keyCode: 'a'.charCodeAt(0), shiftKey: true });
  111. expect(isEditorVisible()).toBe(false);
  112. });
  113. it('should not not open editor after hitting ALT', () => {
  114. handsontable({
  115. data: Handsontable.helper.createSpreadsheetData(4, 4),
  116. editor: false
  117. });
  118. expect(getDataAtCell(0, 0)).toEqual('A1');
  119. selectCell(0, 0);
  120. keyDown(Handsontable.helper.KEY_CODES.ALT);
  121. expect(isEditorVisible()).toBe(false);
  122. });
  123. describe('IME support', () => {
  124. it('should focus editable element (from copyPaste plugin) after selecting the cell', async() => {
  125. handsontable({
  126. editor: false,
  127. });
  128. selectCell(0, 0, 0, 0, true, false);
  129. await sleep(10);
  130. expect(document.activeElement).toBe(document.querySelector('#HandsontableCopyPaste'));
  131. });
  132. });
  133. });