test_creta_keybindings.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. QUnit.module('creta_keybinding', function() {
  2. QUnit.test('clean keybinding', function(assert) {
  3. initial_values();
  4. first_div.innerText = "Lorem Ipsum";
  5. first_div.dispatchEvent(new KeyboardEvent('keydown', {
  6. code: 'C',
  7. key: 'C',
  8. charCode: 99,
  9. keyCode: 99,
  10. view: window,
  11. bubbles: true,
  12. shiftKey: true,
  13. ctrlKey: true
  14. }));
  15. assert.equal(visual_editor.get_text(), "");
  16. });
  17. QUnit.test('link keybinding', function(assert) {
  18. initial_values();
  19. first_div.innerText = "Lorem Ipsum";
  20. let selection = window.getSelection();
  21. let range = document.createRange();
  22. range.selectNodeContents(first_div);
  23. selection.removeAllRanges();
  24. selection.addRange(range);
  25. first_div.dispatchEvent(new KeyboardEvent('keydown', {
  26. code: 'K',
  27. key: 'K',
  28. charCode: 75,
  29. keyCode: 75,
  30. view: window,
  31. bubbles: true,
  32. shiftKey: true,
  33. ctrlKey: true
  34. }));
  35. visual_editor_div.getElementsByClassName('link_input')[0].value = "url";
  36. let accept_button = visual_editor_div.getElementsByClassName('accept_link')[0];
  37. accept_button.click();
  38. assert.equal(visual_editor.get_text(),
  39. "<div><a href=\"https://url\">Lorem Ipsum</a></div>");
  40. });
  41. QUnit.test('table keybinding', function(assert) {
  42. initial_values();
  43. first_div.innerText = "Lorem Ipsum";
  44. first_div.dispatchEvent(new KeyboardEvent('keydown', {
  45. code: 'T',
  46. key: 'T',
  47. charCode: 84,
  48. keyCode: 84,
  49. view: window,
  50. bubbles: true,
  51. shiftKey: true,
  52. ctrlKey: true
  53. }));
  54. visual_editor_div.getElementsByClassName('w')[0].value = "2";
  55. visual_editor_div.getElementsByClassName('h')[0].value = "2";
  56. let accept_button = visual_editor_div.getElementsByClassName('accept_table')[0];
  57. accept_button.click();
  58. assert.equal(visual_editor.get_text(),
  59. "<div>Lorem Ipsum</div>\n<table style=\"border: 1px solid black;\">\n <tbody>\n <tr>\n <td style=\"border: 1px solid black;\"></td>\n <td style=\"border: 1px solid black;\"></td>\n </tr>\n <tr>\n <td style=\"border: 1px solid black;\"></td>\n <td style=\"border: 1px solid black;\"></td>\n </tr>\n </tbody>\n</table>\n<div></div>");
  60. });
  61. QUnit.test('list keybinding', function(assert) {
  62. initial_values();
  63. first_div.innerText = "Lorem Ipsum";
  64. first_div.dispatchEvent(new KeyboardEvent('keydown', {
  65. code: 'L',
  66. key: 'L',
  67. charCode: 73,
  68. keyCode: 73,
  69. view: window,
  70. bubbles: true,
  71. shiftKey: true,
  72. ctrlKey: true
  73. }));
  74. assert.equal(visual_editor.get_text(),
  75. "<div>Lorem Ipsum</div>\n<div>\n <ul>\n <li></li>\n </ul>\n</div>");
  76. });
  77. QUnit.test('sublist keybinding', function(assert) {
  78. initial_values();
  79. first_div.innerText = "Lorem Ipsum";
  80. first_div.dispatchEvent(new KeyboardEvent('keydown', {
  81. code: 'L',
  82. key: 'L',
  83. charCode: 52,
  84. keyCode: 52,
  85. view: window,
  86. bubbles: true,
  87. shiftKey: true,
  88. ctrlKey: true
  89. }));
  90. let sel = window.getSelection();
  91. let range = sel.getRangeAt(0);
  92. range.insertNode(document.createTextNode("Item"));
  93. visual_editor.core.get_selected_node_line().dispatchEvent(new KeyboardEvent('keydown', {
  94. code: '4',
  95. key: '4',
  96. charCode: 73,
  97. keyCode: 73,
  98. view: window,
  99. bubbles: true,
  100. ctrlKey: true
  101. }));
  102. assert.equal(visual_editor.get_text(),
  103. "<div>Lorem Ipsum</div>\n<div>\n <ul>\n <li>Item<ul>\n <li></li>\n </ul>\n </li>\n </ul>\n</div>");
  104. });
  105. QUnit.test('block keybinding', function(assert) {
  106. initial_values();
  107. first_div.innerText = "Lorem Ipsum";
  108. let selection = window.getSelection();
  109. let range = document.createRange();
  110. range.selectNodeContents(first_div);
  111. selection.removeAllRanges();
  112. selection.addRange(range);
  113. first_div.dispatchEvent(new KeyboardEvent('keydown', {
  114. code: 'B',
  115. key: 'B',
  116. charCode: 66,
  117. keyCode: 66,
  118. view: window,
  119. bubbles: true,
  120. shiftKey: true,
  121. ctrlKey: true
  122. }));
  123. visual_editor_div.getElementsByClassName('block_input')[0].value = "block_class";
  124. let accept_button = visual_editor_div.getElementsByClassName('accept_block')[0];
  125. accept_button.click();
  126. assert.equal(visual_editor.get_text(),
  127. "<div><div class=\"block_class\">Lorem Ipsum</div></div>");
  128. });
  129. QUnit.test('metatag keybinding', function(assert) {
  130. initial_values();
  131. first_div.innerText = "Lorem Ipsum";
  132. let selection = window.getSelection();
  133. let range = document.createRange();
  134. range.selectNodeContents(first_div);
  135. selection.removeAllRanges();
  136. selection.addRange(range);
  137. first_div.dispatchEvent(new KeyboardEvent('keydown', {
  138. code: 'M',
  139. key: 'M',
  140. charCode: 77,
  141. keyCode: 77,
  142. view: window,
  143. bubbles: true,
  144. shiftKey: true,
  145. ctrlKey: true
  146. }));
  147. assert.equal(visual_editor.get_text(),
  148. "<div><code>Lorem Ipsum</code></div>");
  149. });
  150. QUnit.test('embed keybinding', function(assert) {
  151. initial_values();
  152. first_div.innerText = "Lorem Ipsum";
  153. let selection = window.getSelection();
  154. let range = document.createRange();
  155. range.selectNodeContents(first_div);
  156. selection.removeAllRanges();
  157. selection.addRange(range);
  158. first_div.dispatchEvent(new KeyboardEvent('keydown', {
  159. code: 'E',
  160. key: 'E',
  161. charCode: 69,
  162. keyCode: 69,
  163. view: window,
  164. bubbles: true,
  165. shiftKey: true,
  166. ctrlKey: true
  167. }));
  168. assert.equal(visual_editor.get_text(),
  169. "<div class=\"embed\">Lorem Ipsum</div>");
  170. });
  171. });