diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-08-08 11:52:13 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-08-08 11:52:13 +0200 |
| commit | b792ba7d9a80e856e3c69c2852e6d44b78d0e13f (patch) | |
| tree | a3ee5b7ef9f9317866deeb2b3e5964020c87b8fb /addons/web_editor/static/tests/test_utils.js | |
| parent | 22e0f88bce5bf162a6c67e915a3c27b101f74f2b (diff) | |
| parent | 752b2553c6fad061ebf23e13585f7b7489b20840 (diff) | |
[MERGE] forward port branch saas-12.3 up to 752b2553c6f
Diffstat (limited to 'addons/web_editor/static/tests/test_utils.js')
| -rw-r--r-- | addons/web_editor/static/tests/test_utils.js | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/addons/web_editor/static/tests/test_utils.js b/addons/web_editor/static/tests/test_utils.js index 99510bb3bae..c6d043a0722 100644 --- a/addons/web_editor/static/tests/test_utils.js +++ b/addons/web_editor/static/tests/test_utils.js @@ -508,9 +508,10 @@ var testKeyboard = function ($editable, assert, keyboardTests, addTests) { keypress.keyCode = keypress.keyCode; var event = $.Event("keydown", keypress); $target.trigger(event); + if (!event.isDefaultPrevented()) { if (keypress.key.length === 1) { - document.execCommand("insertText", 0, keypress.key); + textInput($target[0], keypress.key); } else { console.warn('Native "' + keypress.key + '" is not supported in test'); } @@ -773,8 +774,40 @@ var keydown = function (key, $editable, options) { var $target = $(target.tagName ? target : target.parentNode); var event = $.Event("keydown", keyPress); $target.trigger(event); + + if (!event.isDefaultPrevented()) { + if (keyPress.key.length === 1) { + textInput($target[0], keyPress.key); + } else { + console.warn('Native "' + keyPress.key + '" is not supported in test'); + } + } }; +var textInput = function (target, char) { + var ev = new CustomEvent('textInput', { + bubbles: true, + cancelBubble: false, + cancelable: true, + composed: true, + data: char, + defaultPrevented: false, + detail: 0, + eventPhase: 3, + isTrusted: true, + returnValue: true, + sourceCapabilities: null, + type: "textInput", + which: 0, + }); + ev.data = char; + target.dispatchEvent(ev); + + if (!ev.defaultPrevented) { + document.execCommand("insertText", 0, ev.data); + } +} + return { wysiwygData: wysiwygData, createWysiwyg: createWysiwyg, |
