123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- QUnit.module('creta_keybinding', function() {
- QUnit.test('clean keybinding', function(assert) {
-
- initial_values();
- first_div.innerText = "Lorem Ipsum";
- first_div.dispatchEvent(new KeyboardEvent('keydown', {
- code: 'C',
- key: 'C',
- charCode: 99,
- keyCode: 99,
- view: window,
- bubbles: true,
- shiftKey: true,
- ctrlKey: true
- }));
- assert.equal(visual_editor.get_text(), "");
-
- });
-
- QUnit.test('link keybinding', function(assert) {
-
- initial_values();
- first_div.innerText = "Lorem Ipsum";
- let selection = window.getSelection();
- let range = document.createRange();
- range.selectNodeContents(first_div);
- selection.removeAllRanges();
- selection.addRange(range);
- first_div.dispatchEvent(new KeyboardEvent('keydown', {
- code: 'K',
- key: 'K',
- charCode: 75,
- keyCode: 75,
- view: window,
- bubbles: true,
- shiftKey: true,
- ctrlKey: true
- }));
- visual_editor_div.getElementsByClassName('link_input')[0].value = "url";
-
- let accept_button = visual_editor_div.getElementsByClassName('accept_link')[0];
- accept_button.click();
-
- assert.equal(visual_editor.get_text(),
- "<div><a href=\"https://url\">Lorem Ipsum</a></div>");
-
- });
-
- QUnit.test('table keybinding', function(assert) {
-
- initial_values();
- first_div.innerText = "Lorem Ipsum";
-
- first_div.dispatchEvent(new KeyboardEvent('keydown', {
- code: 'T',
- key: 'T',
- charCode: 84,
- keyCode: 84,
- view: window,
- bubbles: true,
- shiftKey: true,
- ctrlKey: true
- }));
-
- visual_editor_div.getElementsByClassName('w')[0].value = "2";
- visual_editor_div.getElementsByClassName('h')[0].value = "2";
-
- let accept_button = visual_editor_div.getElementsByClassName('accept_table')[0];
- accept_button.click();
-
- assert.equal(visual_editor.get_text(),
- "<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>");
-
- });
-
- QUnit.test('list keybinding', function(assert) {
-
- initial_values();
- first_div.innerText = "Lorem Ipsum";
-
- first_div.dispatchEvent(new KeyboardEvent('keydown', {
- code: 'L',
- key: 'L',
- charCode: 73,
- keyCode: 73,
- view: window,
- bubbles: true,
- shiftKey: true,
- ctrlKey: true
- }));
-
- assert.equal(visual_editor.get_text(),
- "<div>Lorem Ipsum</div>\n<div>\n <ul>\n <li></li>\n </ul>\n</div>");
-
- });
-
- QUnit.test('sublist keybinding', function(assert) {
-
- initial_values();
- first_div.innerText = "Lorem Ipsum";
-
- first_div.dispatchEvent(new KeyboardEvent('keydown', {
- code: 'L',
- key: 'L',
- charCode: 52,
- keyCode: 52,
- view: window,
- bubbles: true,
- shiftKey: true,
- ctrlKey: true
- }));
- let sel = window.getSelection();
- let range = sel.getRangeAt(0);
- range.insertNode(document.createTextNode("Item"));
-
- visual_editor.core.get_selected_node_line().dispatchEvent(new KeyboardEvent('keydown', {
- code: '4',
- key: '4',
- charCode: 73,
- keyCode: 73,
- view: window,
- bubbles: true,
- ctrlKey: true
- }));
-
- assert.equal(visual_editor.get_text(),
- "<div>Lorem Ipsum</div>\n<div>\n <ul>\n <li>Item<ul>\n <li></li>\n </ul>\n </li>\n </ul>\n</div>");
-
- });
-
- QUnit.test('block keybinding', function(assert) {
-
- initial_values();
- first_div.innerText = "Lorem Ipsum";
- let selection = window.getSelection();
- let range = document.createRange();
- range.selectNodeContents(first_div);
- selection.removeAllRanges();
- selection.addRange(range);
- first_div.dispatchEvent(new KeyboardEvent('keydown', {
- code: 'B',
- key: 'B',
- charCode: 66,
- keyCode: 66,
- view: window,
- bubbles: true,
- shiftKey: true,
- ctrlKey: true
- }));
-
- visual_editor_div.getElementsByClassName('block_input')[0].value = "block_class";
-
- let accept_button = visual_editor_div.getElementsByClassName('accept_block')[0];
- accept_button.click();
-
- assert.equal(visual_editor.get_text(),
- "<div><div class=\"block_class\">Lorem Ipsum</div></div>");
-
- });
-
- QUnit.test('metatag keybinding', function(assert) {
-
- initial_values();
- first_div.innerText = "Lorem Ipsum";
- let selection = window.getSelection();
- let range = document.createRange();
- range.selectNodeContents(first_div);
- selection.removeAllRanges();
- selection.addRange(range);
- first_div.dispatchEvent(new KeyboardEvent('keydown', {
- code: 'M',
- key: 'M',
- charCode: 77,
- keyCode: 77,
- view: window,
- bubbles: true,
- shiftKey: true,
- ctrlKey: true
- }));
-
- assert.equal(visual_editor.get_text(),
- "<div><code>Lorem Ipsum</code></div>");
-
- });
-
- QUnit.test('embed keybinding', function(assert) {
-
- initial_values();
- first_div.innerText = "Lorem Ipsum";
- let selection = window.getSelection();
- let range = document.createRange();
- range.selectNodeContents(first_div);
- selection.removeAllRanges();
- selection.addRange(range);
- first_div.dispatchEvent(new KeyboardEvent('keydown', {
- code: 'E',
- key: 'E',
- charCode: 69,
- keyCode: 69,
- view: window,
- bubbles: true,
- shiftKey: true,
- ctrlKey: true
- }));
-
- assert.equal(visual_editor.get_text(),
- "<div class=\"embed\">Lorem Ipsum</div>");
-
- });
- });
-
|