From cc80572ee65b4713aea12c33fa0d1e7193e3bb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Wed, 18 May 2022 09:30:00 +0000 Subject: [PATCH] [FIX] web_editor: fix missing strikeThrough tests Add some unit test for strikeThrough format. Those tests reveal some bug in the current formating code. task-2850686 X-original-commit: 4d8e1dc381d01bb254d2e806a335a40733608f2e Part-of: odoo/odoo#91786 --- .../lib/odoo-editor/test/spec/format.test.js | 58 ++++++++++++++++++- .../static/lib/odoo-editor/test/utils.js | 2 +- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/lib/odoo-editor/test/spec/format.test.js b/addons/web_editor/static/lib/odoo-editor/test/spec/format.test.js index 1c372e84b7d..ab96465e8d9 100644 --- a/addons/web_editor/static/lib/odoo-editor/test/spec/format.test.js +++ b/addons/web_editor/static/lib/odoo-editor/test/spec/format.test.js @@ -1,4 +1,4 @@ -import { BasicEditor, testEditor } from '../utils.js'; +import { BasicEditor, testEditor, setTestSelection, Direction } from '../utils.js'; import { applyInlineStyle } from '../../src/commands/commands.js'; const bold = async editor => { @@ -281,6 +281,62 @@ describe('Format', () => { contentAfter: `

${s(`ab[`)}cde]${s(`fg`)}

`, }); }); + it('should make a few characters strikeThrough then remove style inside', async () => { + await testEditor(BasicEditor, { + contentBefore: `

ab[c d]ef

`, + stepFunction: async editor => { + await strikeThrough(editor); + const styleSpan = editor.editable.querySelector('span[style="text-decoration-line: line-through;"]').childNodes[0]; + const selection = { + anchorNode: styleSpan, + anchorOffset: 1, + focusNode: styleSpan, + focusOffset: 2, + direction: Direction.FORWARD, + }; + await setTestSelection(selection); + await strikeThrough(editor); + }, + contentAfter: `

ab${s(`c[`)} ]${s(`d`)}ef

`, + }); + }); + it('should make strikeThrough then more then remove', async () => { + await testEditor(BasicEditor, { + contentBefore: `

abc[ ]def

`, + stepFunction: async editor => { + await strikeThrough(editor); + const pElem = editor.editable.querySelector('p').childNodes; + const selection = { + anchorNode: pElem[0], + anchorOffset: 2, + focusNode: pElem[2], + focusOffset: 1, + direction: Direction.FORWARD, + }; + await setTestSelection(selection); + await strikeThrough(editor); + }, + contentAfter: `

ab${s(`[c d]`)}ef

`, + }); + await testEditor(BasicEditor, { + contentBefore: `

abc[ ]def

`, + stepFunction: async editor => { + await strikeThrough(editor); + const pElem = editor.editable.querySelector('p').childNodes; + const selection = { + anchorNode: pElem[0], + anchorOffset: 2, + focusNode: pElem[2], + focusOffset: 1, + direction: Direction.FORWARD, + }; + await setTestSelection(selection); + await strikeThrough(editor); + await strikeThrough(editor); + }, + contentAfter: `

ab[c d]ef

`, + }); + }); it('should make two paragraphs strikeThrough', async () => { await testEditor(BasicEditor, { contentBefore: '

[abc

def]

', diff --git a/addons/web_editor/static/lib/odoo-editor/test/utils.js b/addons/web_editor/static/lib/odoo-editor/test/utils.js index abad4c14e81..c1ac2e04f96 100644 --- a/addons/web_editor/static/lib/odoo-editor/test/utils.js +++ b/addons/web_editor/static/lib/odoo-editor/test/utils.js @@ -2,7 +2,7 @@ import { OdooEditor } from '../src/OdooEditor.js'; import { sanitize } from '../src/utils/sanitize.js'; import { insertText as insertTextSel } from '../src/utils/utils.js'; -const Direction = { +export const Direction = { BACKWARD: 'BACKWARD', FORWARD: 'FORWARD', };