From e5c504e8b1adf45c09f50720d1cc877039f45627 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Thu, 27 Oct 2022 10:08:20 +0000 Subject: [PATCH] [FIX] web_editor: test the real browser flow for delete/backspace range deleteBackward and deleteForward tests were just directly calling the editor's implementation, without triggering events that are sometimes crucial to the behavior. This is at least preventable in cases where the selection isn't collapsed, by triggering the keydown event and calling the document's `execCommand` function with the "delete" command. task-3032817 X-original-commit: cd7c647f45487e8d8a763875a30e327422af4e68 Part-of: odoo/odoo#105217 --- .../src/js/editor/odoo-editor/test/utils.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/utils.js index da6fa350c42..3fe08df5b44 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/utils.js @@ -429,11 +429,27 @@ export async function click(el, options) { } export async function deleteForward(editor) { - editor.execCommand('oDeleteForward'); + const selection = document.getSelection(); + if (selection.isCollapsed) { + editor.execCommand('oDeleteForward'); + } else { + // Better representation of what happened in the editor when the user + // presses the delete key. + await triggerEvent(editor.editable, 'keydown', { key: 'Delete' }); + editor.document.execCommand('delete'); + } } export async function deleteBackward(editor) { - editor.execCommand('oDeleteBackward'); + const selection = document.getSelection(); + if (selection.isCollapsed) { + editor.execCommand('oDeleteBackward'); + } else { + // Better representation of what happened in the editor when the user + // presses the backspace key. + await triggerEvent(editor.editable, 'keydown', { key: 'Backspace' }); + editor.document.execCommand('delete'); + } } export async function deleteBackwardMobile(editor) {