test_creta_keyboard.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. QUnit.module('creta_keyboard', function() {
  2. QUnit.test('new line', function(assert) {
  3. initial_values();
  4. first_div.innerText = "Lorem Ipsum";
  5. let selection = window.getSelection();
  6. let range = document.createRange();
  7. range.selectNodeContents(first_div);
  8. selection.removeAllRanges();
  9. selection.addRange(range);
  10. selection.collapseToEnd();
  11. first_div.dispatchEvent(new KeyboardEvent('keydown', {
  12. code: 'Enter',
  13. key: 'Enter',
  14. charCode: 13,
  15. keyCode: 13,
  16. view: window,
  17. bubbles: true
  18. }));
  19. assert.equal(visual_editor.get_text(), "<div>Lorem Ipsum</div>\n<div></div>");
  20. });
  21. QUnit.test('backspace', function(assert) {
  22. initial_values();
  23. first_div.innerText = "Lorem Ipsum";
  24. let selection = window.getSelection();
  25. let range = document.createRange();
  26. range.selectNodeContents(first_div);
  27. selection.removeAllRanges();
  28. selection.addRange(range);
  29. selection.collapseToEnd();
  30. first_div.dispatchEvent(new KeyboardEvent('keydown', {
  31. code: 'Enter',
  32. key: 'Enter',
  33. charCode: 13,
  34. keyCode: 13,
  35. view: window,
  36. bubbles: true
  37. }));
  38. selection = window.getSelection();
  39. range = document.createRange();
  40. range.selectNodeContents(first_div);
  41. selection.removeAllRanges();
  42. selection.addRange(range);
  43. first_div.nextSibling.dispatchEvent(new KeyboardEvent('keydown', {
  44. code: 'Backspace',
  45. key: 'Backspace',
  46. charCode: 0,
  47. keyCode: 8,
  48. view: window,
  49. bubbles: true
  50. }));
  51. assert.equal(visual_editor.get_text(), "<div>Lorem Ipsum</div>");
  52. });
  53. });