diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js index 85db3a0e96d..88cc0779037 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js @@ -5,7 +5,6 @@ import { BasicEditor, click, deleteBackward, - deleteBackwardMobile, insertText, insertParagraphBreak, insertLineBreak, @@ -557,7 +556,7 @@ describe('Link', () => { } }); }); - it('should keep isolated link after a keyboard delete', async () => { + it('should keep isolated link after a delete', async () => { await testEditor(BasicEditor, { contentBefore: '

ab[]c

', stepFunction: async editor => { @@ -571,20 +570,6 @@ describe('Link', () => { contentAfter: '

a[]c

', }); }); - it('should keep isolated link after a mobile delete', async () => { - await testEditor(BasicEditor, { - contentBefore: '

ab[]c

', - stepFunction: async editor => { - const a = await clickOnLink(editor); - console.log(a.closest('.odoo-editor-editable').outerHTML); - await deleteBackwardMobile(editor); - console.log(a.closest('.odoo-editor-editable').outerHTML); - window.chai.expect(a.parentElement.isContentEditable).to.be.equal(false); - }, - contentAfterEdit: '

a[]\u200Bc

', - contentAfter: '

a[]c

', - }); - }); it('should keep isolated link after a delete and typing', async () => { await testEditor(BasicEditor, { contentBefore: '

ab[]c

', @@ -603,24 +588,6 @@ describe('Link', () => { contentAfter: '

a123[]c

', }); }); - it('should keep isolated link after a mobile delete and typing', async () => { - await testEditor(BasicEditor, { - contentBefore: '

ab[]c

', - stepFunction: async editor => { - const a = await clickOnLink(editor); - window.chai.expect(a.parentElement.isContentEditable).to.be.equal(false); - await deleteBackwardMobile(editor); - window.chai.expect(a.parentElement.isContentEditable).to.be.equal(false); - await insertText(editor, '1'); - window.chai.expect(a.parentElement.isContentEditable).to.be.equal(false); - await insertText(editor, '2'); - window.chai.expect(a.parentElement.isContentEditable).to.be.equal(false); - await insertText(editor, '3'); - window.chai.expect(a.parentElement.isContentEditable).to.be.equal(false); - }, - contentAfter: '

a123[]c

', - }); - }); it('should delete the content from the link when popover is active', async () => { await testEditor(BasicEditor, { contentBefore: '

abc[]abc

', 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 7a842122b53..572a656ac8b 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 @@ -9,6 +9,11 @@ export const Direction = { FORWARD: 'FORWARD', }; +// True iff test is being run with its mobile implementation. +let isMobileTest = false; +// True iff test has mobile implementation for any called method. +let hasMobileTest = false; + function _nextNode(node) { let next = node.firstChild || node.nextSibling; if (!next) { @@ -276,6 +281,9 @@ export function customErrorMessage(assertLocation, value, expected) { } export async function testEditor(Editor = OdooEditor, spec, options = {}) { + hasMobileTest = false; + isMobileTest = options.isMobile; + const testNode = document.createElement('div'); const testContainer = document.querySelector('#editor-test-container'); testContainer.innerHTML = ''; @@ -324,7 +332,12 @@ export async function testEditor(Editor = OdooEditor, spec, options = {}) { if (spec.stepFunction) { editor.observerActive('beforeUnitTests'); - await spec.stepFunction(editor); + try { + await spec.stepFunction(editor); + } catch (e) { + e.message = (isMobileTest ? '[MOBILE VERSION] ' : '') + e.message; + throw e; + } editor.observerUnactive('afterUnitTests'); } @@ -374,6 +387,8 @@ export async function testEditor(Editor = OdooEditor, spec, options = {}) { if (error) { throw error; + } else if (hasMobileTest && !isMobileTest) { + await testEditor(Editor, spec, { ...options, isMobile: true }); } } @@ -445,29 +460,31 @@ export async function deleteForward(editor) { } export async function deleteBackward(editor) { - const selection = document.getSelection(); - if (selection.isCollapsed) { - editor.execCommand('oDeleteBackward'); + // This method has two implementations (desktop and mobile). + if (isMobileTest) { + // Some mobile keyboard use input event to trigger delete. + // This is a way to simulate this behavior. + const inputEvent = new InputEvent('input', { + inputType: 'deleteContentBackward', + data: null, + bubbles: true, + cancelable: false, + }); + editor._onInput(inputEvent); } 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'); + hasMobileTest = true; // Flag test for a re-run as mobile. + 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) { - // Some mobile keyboard use input event to trigger delete. - // This is a way to simulate this behavior. - const inputEvent = new InputEvent('input', { - inputType: 'deleteContentBackward', - data: null, - bubbles: true, - cancelable: false, - }); - editor._onInput(inputEvent); -} - export async function insertParagraphBreak(editor) { editor.execCommand('oEnter'); }