dropdownEditor.spec.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. describe('DropdownEditor', () => {
  2. var id = 'testContainer';
  3. var choices = ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white', 'purple', 'lime', 'olive', 'cyan'];
  4. var hot;
  5. beforeEach(function() {
  6. this.$container = $(`<div id="${id}" style="width: 300px; height: 200px; overflow: auto"></div>`).appendTo('body');
  7. });
  8. afterEach(function() {
  9. if (hot) {
  10. hot = null;
  11. }
  12. if (this.$container) {
  13. destroy();
  14. this.$container.remove();
  15. }
  16. });
  17. describe('open editor', () => {
  18. // see https://github.com/handsontable/handsontable/issues/3380
  19. it('should not throw error while selecting the next cell by hitting enter key', () => {
  20. var spy = jasmine.createSpyObj('error', ['test']);
  21. var prevError = window.onerror;
  22. window.onerror = function(messageOrEvent, source, lineno, colno, error) {
  23. spy.test();
  24. };
  25. handsontable({
  26. columns: [{
  27. editor: 'dropdown',
  28. source: choices
  29. }]
  30. });
  31. selectCell(0, 0);
  32. keyDownUp('enter');
  33. keyDownUp('enter');
  34. keyDownUp('enter');
  35. expect(spy.test.calls.count()).toBe(0);
  36. window.onerror = prevError;
  37. });
  38. });
  39. describe('closing the editor', () => {
  40. it('should not close editor on scrolling', (done) => {
  41. hot = handsontable({
  42. data: [
  43. ['', 'two', 'three'],
  44. ['four', 'five', 'six']
  45. ],
  46. columns: [
  47. {
  48. type: 'dropdown',
  49. source: choices
  50. },
  51. {},
  52. {}
  53. ]
  54. });
  55. selectCell(0, 0);
  56. $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mousedown');
  57. $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mouseup');
  58. hot.view.wt.wtOverlays.topOverlay.scrollTo(1);
  59. var dropdown = hot.getActiveEditor();
  60. setTimeout(() => {
  61. expect($(dropdown.htContainer).is(':visible')).toBe(true);
  62. selectCell(0, 0);
  63. }, 30);
  64. setTimeout(() => {
  65. $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mousedown');
  66. $(getCell(0, 0)).find('.htAutocompleteArrow').simulate('mouseup');
  67. hot.view.wt.wtOverlays.topOverlay.scrollTo(3);
  68. }, 150);
  69. setTimeout(() => {
  70. expect($(dropdown.htContainer).is(':visible')).toBe(true);
  71. done();
  72. }, 200);
  73. });
  74. });
  75. it('should mark all invalid values as invalid, after pasting them into dropdown-type cells', (done) => {
  76. hot = handsontable({
  77. data: [
  78. ['', 'two', 'three'],
  79. ['four', 'five', 'six']
  80. ],
  81. columns: [
  82. {
  83. type: 'dropdown',
  84. source: choices
  85. },
  86. {},
  87. {}
  88. ]
  89. });
  90. populateFromArray(0, 0, [['invalid'], ['input']], null, null, 'paste');
  91. setTimeout(() => {
  92. expect(Handsontable.dom.hasClass(getCell(0, 0), 'htInvalid')).toBe(true);
  93. expect(Handsontable.dom.hasClass(getCell(1, 0), 'htInvalid')).toBe(true);
  94. done();
  95. }, 40);
  96. });
  97. });