[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
This commit is contained in:
@@ -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: `<p>${s(`ab[`)}cde]${s(`fg`)}</p>`,
|
||||
});
|
||||
});
|
||||
it('should make a few characters strikeThrough then remove style inside', async () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: `<p>ab[c d]ef</p>`,
|
||||
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: `<p>ab${s(`c[`)} ]${s(`d`)}ef</p>`,
|
||||
});
|
||||
});
|
||||
it('should make strikeThrough then more then remove', async () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: `<p>abc[ ]def</p>`,
|
||||
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: `<p>ab${s(`[c d]`)}ef</p>`,
|
||||
});
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: `<p>abc[ ]def</p>`,
|
||||
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: `<p>ab[c d]ef</p>`,
|
||||
});
|
||||
});
|
||||
it('should make two paragraphs strikeThrough', async () => {
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<p>[abc</p><p>def]</p>',
|
||||
|
||||
@@ -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',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user