import { describe, test } from "@odoo/hoot"; import { testEditor } from "./_helpers/editor"; import { unformat } from "./_helpers/format"; import { BOLD_TAGS } from "./_helpers/tags"; /** * content of the "init" sub suite in editor.test.js */ describe("No orphan inline elements compatibility mode", () => { test("should wrap inline node inside a div baseContainer", async () => { await testEditor({ contentBefore: "

abc

def

orphan node", contentAfter: "

abc

def

orphan node
", }); }); test("should wrap inline node inside a div baseContainer (2)", async () => { await testEditor({ contentBefore: "

ab

cd

ef

", contentAfter: "

ab

cd

ef

", }); }); test("should transform root
into a div baseContainer", async () => { await testEditor({ contentBefore: "ab
c", contentAfter: "
ab
c
", }); }); test("should keep
if necessary", async () => { await testEditor({ contentBefore: "ab

c", contentAfter: "
ab

c
", }); }); test("should keep multiple conecutive
if necessary", async () => { await testEditor({ contentBefore: "ab



c", contentAfter: "
ab



c
", }); }); test("should transform complex
", async () => { await testEditor({ contentBefore: 'ab
c
dxxxe
f', contentAfter: '
ab
c
dxxxe
f
', }); }); test("should transform complex
+ keep li ", async () => { await testEditor({ contentBefore: "ab
c f
g", contentAfter: "
ab
c
f
g
", }); }); test("should not transform
inside

", async () => { await testEditor({ contentBefore: "

ab
c

", contentAfter: "

ab
c

", }); await testEditor({ contentBefore: "

ab
c

d

", contentAfter: "

ab
c

d

", }); await testEditor({ contentBefore: "xx

ab
c

d
yy", contentAfter: "
xx

ab
c

d
yy
", }); }); test("should not transform indentation", async () => { await testEditor({ contentBefore: `

ab

c

`, contentAfter: `

ab

c

`, }); }); test("should transform root .fa", async () => { await testEditor({ contentBefore: '

ab

c

', contentAfter: '

ab

c

', }); }); test("should wrap a div.o_image direct child of the editable into a block", async () => { await testEditor({ contentBefore: '

abc

def

', contentBeforeEdit: '

abc

def

', contentAfter: '

abc

def

', }); }); }); describe("allowInlineAtRoot options", () => { test("should wrap inline node inside a p by default", async () => { await testEditor({ contentBefore: "abc", contentAfter: "
abc
", }); }); test("should wrap inline node inside a p if value is false", async () => { await testEditor( { contentBefore: "abc", contentAfter: "
abc
", }, { allowInlineAtRoot: false } ); }); test("should keep inline nodes unchanged if value is true", async () => { await testEditor({ contentBefore: "abc", contentAfter: "abc", config: { allowInlineAtRoot: true }, }); }); }); describe("sanitize spans/fonts", () => { test("should NOT sanitize attributeless spans away", async () => { await testEditor({ contentBefore: "

abc

", contentAfter: "

abc

", }); }); test("should NOT sanitize attributeless fonts away", async () => { await testEditor({ contentBefore: "

abc

", contentAfter: "

abc

", }); }); }); describe("list normalization", () => { test("should keep P in LI (regardless of class)", async () => { await testEditor({ contentBefore: '', contentAfter: '', }); }); test("should keep inlines in LI", async () => { await testEditor({ contentBefore: "", contentAfter: "", }); }); test("should wrap inlines in P to prevent mixing block and inline in LI", async () => { await testEditor({ contentBefore: "", contentAfter: "", }); }); }); describe("link normalization", () => { test("should move inline color from anchor to font", async () => { await testEditor({ contentBefore: '

test

', contentAfter: '

test

', }); }); test("should remove anchor color and retain font color", async () => { await testEditor({ contentBefore: '

test

', contentAfter: '

test

', }); }); test("should handle inline color styles in multiple anchor elements", async () => { await testEditor({ contentBefore: '

test

test

', contentAfter: '

test

test

', }); }); }); describe("color normalization", () => { test("should unwrap nested identical tags with gradient (class and style same)", async () => { await testEditor({ contentBefore: unformat(`

parent child

`), contentAfter: unformat(`

parentchild

`), }); }); test("should unwrap nested identical tags with color (class and style same)", async () => { await testEditor({ contentBefore: unformat(`

parent child

`), contentAfter: unformat(`

parentchild

`), }); }); test("should unwrap nested with same style but no class", async () => { await testEditor({ contentBefore: unformat(`

parent child

`), contentAfter: unformat(`

parentchild

`), }); }); test("should unwrap nested with same class only", async () => { await testEditor({ contentBefore: unformat(`

parent child

`), contentAfter: unformat(`

parentchild

`), }); }); test("should unwrap nested with no class or style", async () => { await testEditor({ contentBefore: unformat(`

parent child

`), contentAfter: unformat(`

parentchild

`), }); }); test("should unwrap nested with same style and class as closest ", async () => { await testEditor({ contentBefore: unformat(`

parent text1 child text2

`), contentAfter: unformat(`

parenttext1childtext2

`), }); }); }); describe("formatting normalization", () => { test("should unwrap nested identical bold tags", async () => { for (const tag of BOLD_TAGS) { await testEditor({ contentBefore: `

a${tag(`b${tag(`c${tag(`d`)}`)}e`)}f

`, contentAfter: `

a${tag("bcde")}f

`, }); } }); test("should merge nested strong inside formatting tags", async () => { await testEditor({ contentBefore: unformat(`

text1 text2 text3

`), contentAfter: unformat(`

text1text2text3

`), }); }); });