summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/tests/test_utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web_editor/static/tests/test_utils.js')
-rw-r--r--addons/web_editor/static/tests/test_utils.js35
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,