dropdownEditor.spec.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. describe('DropdownEditor', () => {
  2. const id = 'testContainer';
  3. const choices = ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white', 'purple', 'lime', 'olive', 'cyan'];
  4. beforeEach(function() {
  5. this.$container = $(`<div id="${id}" style="width: 300px; height: 200px; overflow: auto"></div>`).appendTo('body');
  6. });
  7. afterEach(function() {
  8. if (this.$container) {
  9. destroy();
  10. this.$container.remove();
  11. }
  12. });
  13. describe('open editor', () => {
  14. // see https://github.com/handsontable/handsontable/issues/3380
  15. it('should not throw error while selecting the next cell by hitting enter key', () => {
  16. const spy = jasmine.createSpyObj('error', ['test']);
  17. const prevError = window.onerror;
  18. window.onerror = function() {
  19. spy.test();
  20. };
  21. handsontable({
  22. columns: [{
  23. editor: 'dropdown',
  24. source: choices
  25. }]
  26. });
  27. selectCell(0, 0);
  28. keyDownUp('enter');
  29. keyDownUp('enter');
  30. keyDownUp('enter');
  31. expect(spy.test.calls.count()).toBe(0);
  32. window.onerror = prevError;
  33. });
  34. });
  35. describe('closing the editor', () => {
  36. it('should not close editor on scrolling', async() => {
  37. const hot = handsontable({
  38. data: [
  39. ['', 'two', 'three'],
  40. ['four', 'five', 'six']
  41. ],
  42. columns: [
  43. {
  44. type: 'dropdown',
  45. source: choices
  46. },
  47. {},
  48. {}
  49. ]
  50. });
  51. selectCell(0, 0);
  52. $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mousedown');
  53. $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mouseup');
  54. hot.view.wt.wtOverlays.topOverlay.scrollTo(1);
  55. const dropdown = hot.getActiveEditor();
  56. await sleep(50);
  57. expect($(dropdown.htContainer).is(':visible')).toBe(true);
  58. selectCell(0, 0);
  59. await sleep(50);
  60. $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mousedown');
  61. $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mouseup');
  62. hot.view.wt.wtOverlays.topOverlay.scrollTo(3);
  63. await sleep(50);
  64. expect($(dropdown.htContainer).is(':visible')).toBe(true);
  65. });
  66. });
  67. it('should mark all invalid values as invalid, after pasting them into dropdown-type cells', (done) => {
  68. handsontable({
  69. data: [
  70. ['', 'two', 'three'],
  71. ['four', 'five', 'six']
  72. ],
  73. columns: [
  74. {
  75. type: 'dropdown',
  76. source: choices
  77. },
  78. {},
  79. {}
  80. ]
  81. });
  82. populateFromArray(0, 0, [['invalid'], ['input']], null, null, 'paste');
  83. setTimeout(() => {
  84. expect(Handsontable.dom.hasClass(getCell(0, 0), 'htInvalid')).toBe(true);
  85. expect(Handsontable.dom.hasClass(getCell(1, 0), 'htInvalid')).toBe(true);
  86. done();
  87. }, 40);
  88. });
  89. // Input element can not lose the focus while entering new characters. It breaks IME editor functionality for Asian users.
  90. it('should not lose the focus on input element while inserting new characters (#839)', async() => {
  91. const focusListener = jasmine.createSpy('focus');
  92. const hot = handsontable({
  93. data: [
  94. ['one', 'two'],
  95. ['three', 'four']
  96. ],
  97. columns: [
  98. {
  99. type: 'dropdown',
  100. source: choices,
  101. },
  102. {},
  103. ],
  104. });
  105. selectCell(0, 0);
  106. hot.getActiveEditor().TEXTAREA.addEventListener('focus', focusListener);
  107. await sleep(50);
  108. expect(focusListener).toHaveBeenCalled();
  109. hot.getActiveEditor().TEXTAREA.removeEventListener('focus', focusListener);
  110. });
  111. describe('IME support', () => {
  112. it('should focus editable element after selecting the cell', async() => {
  113. handsontable({
  114. columns: [
  115. {
  116. type: 'dropdown',
  117. source: choices,
  118. }
  119. ]
  120. });
  121. selectCell(0, 0, 0, 0, true, false);
  122. await sleep(10);
  123. expect(document.activeElement).toBe(getActiveEditor().TEXTAREA);
  124. });
  125. });
  126. });