passwordEditor.spec.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. describe('PasswordEditor', () => {
  2. const id = 'testContainer';
  3. beforeEach(function() {
  4. this.$container = $(`<div id="${id}" style="width: 300px; height: 300px;"></div>`).appendTo('body');
  5. });
  6. afterEach(function() {
  7. if (this.$container) {
  8. destroy();
  9. this.$container.remove();
  10. }
  11. });
  12. it('should display editor as password field', () => {
  13. handsontable({
  14. data: [
  15. ['Joe'],
  16. ['Timothy'],
  17. ['Margaret'],
  18. ['Jerry']
  19. ],
  20. columns: [
  21. {
  22. editor: Handsontable.editors.PasswordEditor
  23. }
  24. ]
  25. });
  26. selectCell(0, 0);
  27. keyDown('enter');
  28. const editor = $('.handsontableInput');
  29. expect(editor.is(':visible')).toBe(true);
  30. expect(editor.is(':password')).toBe(true);
  31. });
  32. it('should set passwordEditor using \'password\' alias', () => {
  33. handsontable({
  34. data: [
  35. ['Joe'],
  36. ['Timothy'],
  37. ['Margaret'],
  38. ['Jerry']
  39. ],
  40. columns: [
  41. {
  42. editor: 'password'
  43. }
  44. ]
  45. });
  46. selectCell(0, 0);
  47. keyDown('enter');
  48. const editor = $('.handsontableInput');
  49. expect(editor.is(':visible')).toBe(true);
  50. expect(editor.is(':password')).toBe(true);
  51. });
  52. it('should set passwordEditor using column type \'password\' ', () => {
  53. handsontable({
  54. data: [
  55. ['Joe'],
  56. ['Timothy'],
  57. ['Margaret'],
  58. ['Jerry']
  59. ],
  60. columns: [
  61. {
  62. type: 'password'
  63. }
  64. ]
  65. });
  66. selectCell(0, 0);
  67. keyDown('enter');
  68. const editorHolder = $('.handsontableInputHolder');
  69. const editor = editorHolder.find('.handsontableInput');
  70. expect(editorHolder.is(':visible')).toBe(true);
  71. expect(editor.is(':password')).toBe(true);
  72. });
  73. it('should save values typed in passwordEditor', () => {
  74. handsontable({
  75. data: [
  76. ['Joe'],
  77. ['Timothy'],
  78. ['Margaret'],
  79. ['Jerry']
  80. ],
  81. columns: [
  82. {
  83. editor: 'password'
  84. }
  85. ]
  86. });
  87. selectCell(0, 0);
  88. expect(getDataAtCell(0, 0)).toMatch('Joe');
  89. expect(getRenderedValue(0, 0)).toMatch('Joe');
  90. keyDown('enter');
  91. const editorHolder = $('.handsontableInputHolder');
  92. const editor = editorHolder.find('.handsontableInput');
  93. expect(parseInt(editorHolder.css('z-index'), 10)).toBeGreaterThan(0);
  94. editor.val('Edgar');
  95. selectCell(1, 0); // closes editor and saves current value
  96. expect(editorHolder.css('z-index')).toBe('-1');
  97. expect(getDataAtCell(0, 0)).toMatch('Edgar');
  98. expect(getRenderedValue(0, 0)).toMatch('Edgar');
  99. });
  100. // Input element can not lose the focus while entering new characters. It breaks IME editor functionality for Asian users.
  101. it('should not lose the focus on input element while inserting new characters (#839)', async() => {
  102. let blured = false;
  103. const listener = () => {
  104. blured = true;
  105. };
  106. const hot = handsontable({
  107. data: [
  108. ['Joe'],
  109. ['Timothy'],
  110. ['Margaret'],
  111. ['Jerry']
  112. ],
  113. columns: [
  114. { data: 'id', type: 'password' },
  115. ],
  116. });
  117. selectCell(0, 0);
  118. keyDownUp('enter');
  119. hot.getActiveEditor().TEXTAREA.addEventListener('blur', listener);
  120. await sleep(200);
  121. hot.getActiveEditor().TEXTAREA.value = '1';
  122. keyDownUp('1'.charCodeAt(0));
  123. hot.getActiveEditor().TEXTAREA.value = '12';
  124. keyDownUp('2'.charCodeAt(0));
  125. hot.getActiveEditor().TEXTAREA.value = '123';
  126. keyDownUp('3'.charCodeAt(0));
  127. expect(blured).toBeFalsy();
  128. hot.getActiveEditor().TEXTAREA.removeEventListener('blur', listener);
  129. });
  130. describe('IME support', () => {
  131. it('should focus editable element after selecting the cell', async() => {
  132. handsontable({
  133. type: 'password',
  134. });
  135. selectCell(0, 0, 0, 0, true, false);
  136. await sleep(10);
  137. expect(document.activeElement).toBe(getActiveEditor().TEXTAREA);
  138. });
  139. });
  140. });