diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-08-14 16:48:10 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-08-14 16:48:10 +0200 |
| commit | 140ee6b8f0b0de7ddcc816496269963612c5d0c6 (patch) | |
| tree | 7bdaa065d215b88fea4fa56adbfa79cdc24deb69 /addons/web_editor/static/tests | |
| parent | 839696d2d7dd574fd8958d17726379926e94d590 (diff) | |
| parent | 98a55917a602c0c47093b4270ebc4e8b416ecf32 (diff) | |
[MERGE] forward port branch saas-12.4 up to 98a55917a60
Diffstat (limited to 'addons/web_editor/static/tests')
| -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, |
