From 8556b6d35eb5386879da84ae6515087e48cde919 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= ab[c1}{c1][c2}{c2]c a[c2}{c2]c[c1}{c1]dc ab[c1}{c1][c2}{c2]c [c2}{c2]cd[c1}{c1]ec a[c1}{c1] ab[c1}{c1] a[c1}{c1]b[c2}{c2] ac[c1}{c1]bdef[c2}{c2] a[c1}{c1][c2}{c2] a[c1}{c1][c2}{c2] a a a a a a a a a
c`; + + await testEditor(BasicEditor, { + contentBefore: '
123[]4
', + stepFunction: async editor => { + await pasteHtml(editor, `a<${node.toLowerCase()}>b${node.toLowerCase()}>c`); + }, + contentAfter: '123' + html + '[]4
', + }); + } + } + + }); + it('should keep whitelisted Tags tag (2)', async () => { const tagsToKeep = [ 'a
d', // img tag
'a123[]
', stepFunction: async editor => { await pasteHtml(editor, tagToKeep); }, - contentAfter: '123' + tagToKeep + '[]', + contentAfter: '123' + tagToKeep + '[]
', }); } }); it('should keep tables Tags tag and add classes', async () => { await testEditor(BasicEditor, { - contentBefore: '123[]', + contentBefore: '123[]
', stepFunction: async editor => { await pasteHtml(editor, 'a| h |
|---|
| b |
| h |
|---|
| b |
123a
| h |
|---|
| b |
d[]
', }); }); it('should not keep span', async () => { await testEditor(BasicEditor, { - contentBefore: '123[]', + contentBefore: '123[]
', stepFunction: async editor => { await pasteHtml(editor, 'abcd'); }, - contentAfter: '123abcd[]', + contentAfter: '123abcd[]
', }); }); it('should not keep orphan LI', async () => { await testEditor(BasicEditor, { - contentBefore: '123[]', + contentBefore: '123[]
', stepFunction: async editor => { await pasteHtml(editor, 'abc
d[]', + contentAfter: '123a
bc
d[]
', }); }); it('should keep LI in UL', async () => { await testEditor(BasicEditor, { - contentBefore: '123[]', + contentBefore: '123[]
', stepFunction: async editor => { await pasteHtml(editor, 'a123a
d[]
', + }); + }); + it('should keep P and B and not span', async () => { + await testEditor(BasicEditor, { + contentBefore: '123[]xx
', + stepFunction: async editor => { + await pasteHtml(editor, 'abc
defgh'); + }, + contentAfter: '123a
bc
defgh[]xx
', }); }); it('should keep styled span', async () => { await testEditor(BasicEditor, { - contentBefore: '123[]', + contentBefore: '123[]
', stepFunction: async editor => { await pasteHtml(editor, 'abcd'); }, - contentAfter: '123abcd[]', + contentAfter: '123abcd[]
', }); }); }); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js index a55b460fc6a..3a214752a63 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js @@ -21,6 +21,70 @@ async function twoDeleteForward(editor) { } describe('Editor', () => { + describe('init', () => { + describe('No orphan inline elements compatibility mode', () => { + it('should transform root', async () => {
+ await testEditor(BasicEditor, {
+ contentBefore: 'ab
c',
+ contentAfter: '
ab
c
', + }); + }); + it('should keepab
c
', + }); + }); + it('should keep multiple conecutiveab
c
', + }); + }); + it('should transform complexab
c
dxxxe
f
', + }); + }); + it('should transform complexab
c
f
g
', + }); + }); + it('should not transform', async () => { + await testEditor(BasicEditor, { + contentBefore: '
ab
c
ab
c
ab
c
d
ab
c
d
ab
c
xx
ab
c
d
yy
', + }); + }); + it('should not transform indentation', async () => { + await testEditor(BasicEditor, { + contentBefore: ` +ab
+c
`, + contentAfter: ` +ab
+c
`, + }); + }); + it('should transform root .fa', async () => { + await testEditor(BasicEditor, { + contentBefore: 'ab
c
', + contentAfter: 'ab
c
', + }); + }); + }); + }); describe('deleteForward', () => { describe('Selection collapsed', () => { describe('Basic', () => { @@ -310,6 +374,11 @@ X[] stepFunction: deleteForward, contentAfter: 'abc[]def
', }); + await testEditor(BasicEditor, { + contentBefore: 'abc[]
def
orphan node', + stepFunction: deleteForward, + contentAfter: 'abc[]def
orphan node
', + }); }); it('should delete the space if the secondis display inline', async () => { await testEditor(BasicEditor, { @@ -1367,11 +1436,11 @@ X[] }); it('should remove a fontawesome', async () => { await testEditor(BasicEditor, { - contentBefore: `
abc
[]def
`, + contentBefore: `abc
[]def
abc
[]def
`, + contentAfter: `abc
[]def
[]cd
', + contentBefore: '[]cd
[]cd
ef', + contentBefore: '[]cd
efabc
[]def
', + contentBefore: 'abc
[]def
abc[]def
', + contentAfter: 'abc[]def
a http://test.com b http://test.com [] c http://test.com d
', }); }); - }) + }); describe('history', () => { describe('undo', () => { @@ -3537,252 +3606,250 @@ X[] describe('ArrowRight', () => { it('should move past a zws (collapsed)', async () => { await testEditor(BasicEditor, { - contentBefore: 'ab[]\u200Bcd', + contentBefore: 'ab[]\u200Bcd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight'}); }, - contentAfter: 'ab\u200B[]cd', - // Final state: 'ab\u200Bc[]d' + contentAfter: 'ab\u200B[]cd
', + // Final state: 'ab\u200Bc[]d
' }); await testEditor(BasicEditor, { - contentBefore: 'ab[]\u200Bcd', + contentBefore: 'ab[]\u200Bcd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight'}); }, - contentAfter: 'ab\u200B[]cd', - // Final state: 'ab\u200Bc[]d' + contentAfter: 'ab\u200B[]cd
', + // Final state: 'ab\u200Bc[]d
' }); }); it('should select a zws', async () => { await testEditor(BasicEditor, { - contentBefore: '[ab]\u200Bcd', + contentBefore: '[ab]\u200Bcd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: '[ab\u200B]cd', - // Final state: '[ab\u200Bc]d' + contentAfter: '[ab\u200B]cd
', + // Final state: '[ab\u200Bc]d
' }); await testEditor(BasicEditor, { - contentBefore: '[ab]\u200Bcd', + contentBefore: '[ab]\u200Bcd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: '[ab\u200B]cd', - // Final state: '[ab\u200Bc]d' + contentAfter: '[ab\u200B]cd
', + // Final state: '[ab\u200Bc]d
' }); }); it('should select a zws (2)', async () => { await testEditor(BasicEditor, { - contentBefore: 'a[b]\u200Bcd', + contentBefore: 'a[b]\u200Bcd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: 'a[b\u200B]cd', - // Final state: 'a[b\u200Bc]d' + contentAfter: 'a[b\u200B]cd
', + // Final state: 'a[b\u200Bc]d
' }); await testEditor(BasicEditor, { - contentBefore: 'a[b]\u200Bcd', + contentBefore: 'a[b]\u200Bcd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: 'a[b\u200B]cd', - // Final state: 'a[b\u200Bc]d' + contentAfter: 'a[b\u200B]cd
', + // Final state: 'a[b\u200Bc]d
' }); }); it('should select a zws (3)', async () => { await testEditor(BasicEditor, { - contentBefore: 'ab[]\u200Bcd', + contentBefore: 'ab[]\u200Bcd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: 'ab[\u200B]cd', - // Final state: 'ab[\u200Bc]d' + contentAfter: 'ab[\u200B]cd
', + // Final state: 'ab[\u200Bc]d
' }); await testEditor(BasicEditor, { - contentBefore: 'ab[]\u200Bcd', + contentBefore: 'ab[]\u200Bcd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: 'ab[\u200B]cd', - // Final state: 'ab[\u200Bc]d' + contentAfter: 'ab[\u200B]cd
', + // Final state: 'ab[\u200Bc]d
' }); }); it('should select a zws backwards', async () => { await testEditor(BasicEditor, { - contentBefore: 'ab]\u200B[cd', + contentBefore: 'ab]\u200B[cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: 'ab\u200B[]cd', - // Final state: 'ab\u200B[c]d' + contentAfter: 'ab\u200B[]cd
', + // Final state: 'ab\u200B[c]d
' }); await testEditor(BasicEditor, { - contentBefore: 'ab]\u200B[cd', + contentBefore: 'ab]\u200B[cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: 'ab\u200B[]cd', - // Final state: 'ab\u200B[c]d' + contentAfter: 'ab\u200B[]cd
', + // Final state: 'ab\u200B[c]d
' }); await testEditor(BasicEditor, { - contentBefore: 'ab]\u200B[cd', + contentBefore: 'ab]\u200B[cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: 'ab\u200B[]cd', - // Final state: 'ab\u200B[c]d' + contentAfter: 'ab\u200B[]cd
', + // Final state: 'ab\u200B[c]d
' }); await testEditor(BasicEditor, { - contentBefore: 'ab]\u200B[cd', + contentBefore: 'ab]\u200B[cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: 'ab\u200B[]cd', - // Final state: 'ab\u200B[c]d' + contentAfter: 'ab\u200B[]cd
', + // Final state: 'ab\u200B[c]d
' }); }); it('should select a zws backwards (2)', async () => { await testEditor(BasicEditor, { - contentBefore: 'ab]\u200Bc[d', + contentBefore: 'ab]\u200Bc[d
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: 'ab\u200B]c[d', - // Final state: 'ab\u200Bc[]d' + contentAfter: 'ab\u200B]c[d
', + // Final state: 'ab\u200Bc[]d
' }); await testEditor(BasicEditor, { - contentBefore: 'ab]\u200Bc[d', + contentBefore: 'ab]\u200Bc[d
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight', shiftKey: true }); }, - contentAfter: 'ab\u200B]c[d', - // Final state: 'ab\u200Bc[]d' + contentAfter: 'ab\u200B]c[d
', + // Final state: 'ab\u200Bc[]d
' }); }); }); describe('ArrowLeft', () => { it('should move past a zws (collapsed)', async () => { await testEditor(BasicEditor, { - contentBefore: 'ab\u200B[]cd', + contentBefore: 'ab\u200B[]cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft'}); }, - contentAfter: 'ab[]\u200Bcd', - // Final state: 'a[]b\u200Bcd' + contentAfter: 'ab[]\u200Bcd
', }); await testEditor(BasicEditor, { - contentBefore: 'ab\u200B[]cd', + contentBefore: 'ab\u200B[]cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft'}); }, - contentAfter: 'ab[]\u200Bcd', - // Final state: 'a[]b\u200Bcd' + contentAfter: 'ab[]\u200Bcd
', }); }); it('should select a zws backwards', async () => { await testEditor(BasicEditor, { - contentBefore: 'ab\u200B[]cd', + contentBefore: 'ab\u200B[]cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'ab]\u200B[cd', - // Final state: 'a]b\u200B[cd' + contentAfter: 'ab]\u200B[cd
', + // Final state: 'a]b\u200B[cd
' }); await testEditor(BasicEditor, { - contentBefore: 'ab\u200B[]cd', + contentBefore: 'ab\u200B[]cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'ab]\u200B[cd', - // Final state: 'a]b\u200B[cd' + contentAfter: 'ab]\u200B[cd
', + // Final state: 'a]b\u200B[cd
' }); }); it('should select a zws backwards (2)', async () => { await testEditor(BasicEditor, { - contentBefore: 'ab\u200B]cd[', + contentBefore: 'ab\u200B]cd[
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'ab]\u200Bcd[', - // Final state: 'a]b\u200Bcd[' + contentAfter: 'ab]\u200Bcd[
', + // Final state: 'a]b\u200Bcd[
' }); await testEditor(BasicEditor, { - contentBefore: 'ab\u200B]cd[', + contentBefore: 'ab\u200B]cd[
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'ab]\u200Bcd[', - // Final state: 'a]b\u200Bcd[' + contentAfter: 'ab]\u200Bcd[
', + // Final state: 'a]b\u200Bcd[
' }); }); it('should select a zws backwards (3)', async () => { await testEditor(BasicEditor, { - contentBefore: 'ab\u200B]c[d', + contentBefore: 'ab\u200B]c[d
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'ab]\u200Bc[d', - // Final state: 'a]b\u200Bc[d' + contentAfter: 'ab]\u200Bc[d
', + // Final state: 'a]b\u200Bc[d
' }); await testEditor(BasicEditor, { - contentBefore: 'ab\u200B]c[d', + contentBefore: 'ab\u200B]c[d
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'ab]\u200Bc[d', - // Final state: 'a]b\u200Bc[d' + contentAfter: 'ab]\u200Bc[d
', + // Final state: 'a]b\u200Bc[d
' }); }); it('should deselect a zws', async () => { await testEditor(BasicEditor, { - contentBefore: 'ab[\u200B]cd', + contentBefore: 'ab[\u200B]cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'ab[]\u200Bcd', - // Final state: 'a]b[\u200Bcd' + contentAfter: 'ab[]\u200Bcd
', + // Final state: 'a]b[\u200Bcd
' }); await testEditor(BasicEditor, { - contentBefore: 'ab[\u200B]cd', + contentBefore: 'ab[\u200B]cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'ab[]\u200Bcd', - // Final state: 'a]b[\u200Bcd' + contentAfter: 'ab[]\u200Bcd
', + // Final state: 'a]b[\u200Bcd
' }); await testEditor(BasicEditor, { - contentBefore: 'ab[\u200B]cd', + contentBefore: 'ab[\u200B]cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'ab[]\u200Bcd', - // Final state: 'a]b[\u200Bcd' + contentAfter: 'ab[]\u200Bcd
', + // Final state: 'a]b[\u200Bcd
' }); await testEditor(BasicEditor, { - contentBefore: 'ab[\u200B]cd', + contentBefore: 'ab[\u200B]cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'ab[]\u200Bcd', - // Final state: 'a]b[\u200Bcd' + contentAfter: 'ab[]\u200Bcd
', + // Final state: 'a]b[\u200Bcd
' }); }); it('should deselect a zws (2)', async () => { await testEditor(BasicEditor, { - contentBefore: 'a[b\u200B]cd', + contentBefore: 'a[b\u200B]cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'a[b]\u200Bcd', - // Final state: 'a[]b\u200Bcd' + contentAfter: 'a[b]\u200Bcd
', + // Final state: 'a[]b\u200Bcd
' }); await testEditor(BasicEditor, { - contentBefore: 'a[b\u200B]cd', + contentBefore: 'a[b\u200B]cd
', stepFunction: async editor => { triggerEvent(editor.editable, 'keydown', { key: 'ArrowLeft', shiftKey: true }); }, - contentAfter: 'a[b]\u200Bcd', - // Final state: 'a[]b\u200Bcd' + contentAfter: 'a[b]\u200Bcd
', + // Final state: 'a[]b\u200Bcd
' }); }); }); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/insertHTML.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/insertHTML.test.js index c82ae3d2b1f..dc382438aec 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/insertHTML.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/insertHTML.test.js @@ -1,6 +1,6 @@ import { BasicEditor, testEditor } from '../utils.js'; -describe('insetHTML', () => { +describe('insert HTML', () => { describe('collapsed selection', () => { it('should insert html in an empty paragraph', async () => { await testEditor(BasicEditor, { @@ -37,55 +37,55 @@ describe('insetHTML', () => { }); it('should insert html in an empty editable', async () => { await testEditor(BasicEditor, { - contentBefore: '[][]
\u200b[]
[]
a[]b
a\u200b[]b
a[]b
a[]e
b
c
d
'); }, - contentAfter: 'abc
d[]eab
c
d[]e
[a]
\u200b[]
[]
a[b]c
a\u200b[]c
a[]c