noEditor.spec.js 3.8 KB

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