[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
This commit is contained in:
Antoine Guenet
2022-11-08 09:41:06 +01:00
parent 4f8b9d0a21
commit e5c504e8b1
@@ -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) {