import { describe, test } from "@odoo/hoot"; import { testEditor } from "../_helpers/editor"; import { deleteBackward, deleteForward } from "../_helpers/user_actions"; import { unformat } from "../_helpers/format"; describe("backward", () => { describe("selection collapsed", () => { describe("start empty", () => { test("should delete empty p after an unbreakable (backward)", async () => { await testEditor({ contentBefore: `
a

[]

`, stepFunction: deleteBackward, contentAfter: `
a[]
`, }); }); test("should delete empty p/br after an unbreakable (backward)", async () => { await testEditor({ contentBefore: `
a

[]

`, stepFunction: deleteBackward, contentAfter: `
a[]
`, }); }); test("should delete empty unbreakable (backward)", async () => { await testEditor({ contentBefore: unformat(`

a

[]
`), stepFunction: deleteBackward, contentAfter: unformat(`

a[]

`), }); }); test("should not delete an empty unbreakable when there is no elements to delete before (backward)", async () => { await testEditor({ contentBefore: unformat(`
[]
a
`), stepFunction: deleteBackward, contentAfter: unformat(`
[]
a
`), }); }); }); describe("start text", () => { test("should not merge p with an unbreakable (backward)", async () => { await testEditor({ contentBefore: `
b

[]a

`, stepFunction: deleteBackward, contentAfter: `
b

[]a

`, }); }); test("should not merge unbreakable before an unbreakable (backward)", async () => { await testEditor({ contentBefore: unformat(`
a
[]b
`), stepFunction: deleteBackward, contentAfter: unformat(`
a
[]b
`), }); }); test("should not merge unbreakable before a p (backward)", async () => { await testEditor({ contentBefore: unformat(`

a

[]b
`), stepFunction: deleteBackward, contentAfter: unformat(`

a

[]b
`), }); }); test("should not merge unbreakable before an empty unbreakable (backward)", async () => { await testEditor({ contentBefore: unformat(`

[]b
`), stepFunction: deleteBackward, contentAfter: unformat(`

[]b
`), }); }); test("should not merge unbreakable before an empty p (backward)", async () => { await testEditor({ contentBefore: unformat(`


[]b
`), stepFunction: deleteBackward, contentAfter: unformat(`


[]b
`), }); }); }); }); describe("selection not collapsed", () => { describe("monolevel", () => { describe("anchor start", () => { test("should remove sandwitched unbreakable (anchor start, focus start) (backward)", async () => { await testEditor({ contentBefore: unformat(`
[ab
cd
ef]
`), stepFunction: deleteBackward, contentAfter: unformat(`
[]
`), }); }); test("should remove sandwitched unbreakable (anchor start, focus between) (backward)", async () => { await testEditor({ contentBefore: unformat(`
[ab
cd
e]f
`), stepFunction: deleteBackward, contentAfter: unformat(`
[]f
`), }); }); }); describe("anchor between", () => { test("should remove sandwitched unbreakable (anchor between, focus between) (backward)", async () => { await testEditor({ contentBefore: unformat(`
a[b
cd
e]f
`), stepFunction: deleteBackward, contentAfter: unformat(`
a[]
f
`), }); }); test("should remove sandwitched unbreakable (anchor between, focus end) (backward)", async () => { await testEditor({ contentBefore: unformat(`
a[b
cd
ef]
`), stepFunction: deleteBackward, contentAfter: unformat(`
a[]
`), }); }); }); }); describe("multilevel", () => { describe("anchor start", () => { test("should remove sandwitched unbreakable (multilevel, anchor start, focus between) (backward)", async () => { await testEditor({ contentBefore: unformat(`
[ab
cd
ef
gh
ij
k]l
`), stepFunction: deleteBackward, contentAfter: unformat(`
[]l
`), }); }); }); describe("anchor between", () => { test("should remove sandwitched unbreakable (multilevel, anchor between, focus between) (backward)", async () => { await testEditor({ contentBefore: unformat(`
a[b
cd
ef
gh
ij
k]l
`), stepFunction: deleteBackward, contentAfter: unformat(`
a[]
l
`), }); }); test("should remove sandwitched unbreakable (multilevel, anchor between, focus end) (backward)", async () => { await testEditor({ contentBefore: unformat(`
a[b
cd
ef
gh
ij
kl]
`), stepFunction: (editor) => deleteBackward(editor), contentAfter: unformat(`
a[]
`), }); }); }); }); test("should delete last character of paragraph but not merge it with unbreakable", async () => { await testEditor({ contentBefore: `

ab[c

]def

`, stepFunction: deleteBackward, contentAfter: `

ab[]

def

`, }); }); test("should delete last character of paragraph and fully selected empty unbreakable", async () => { await testEditor({ contentBefore: `

ab[c

]

def

`, stepFunction: deleteBackward, contentAfter: `

ab[]

def

`, }); }); test("should delete first character of unbreakable, ignoring selected paragraph break (backward)", async () => { await testEditor({ contentBefore: `

abc[

d]ef

`, stepFunction: deleteBackward, contentAfter: `

abc[]

ef

`, }); }); }); }); describe("forward", () => { describe("selection collapsed", () => { describe("start empty", () => { test("should delete empty p just before an unbreakable (forward)", async () => { await testEditor({ contentBefore: `

[]

a
`, stepFunction: deleteForward, contentAfter: `
[]a
`, }); }); test("should delete empty p/br just before an unbreakable (forward)", async () => { await testEditor({ contentBefore: `


[]

a
`, stepFunction: deleteForward, contentAfter: `
[]a
`, }); }); test("should delete empty unbreakables (forward)", async () => { await testEditor({ contentBefore: unformat(`
[]

a

`), stepFunction: deleteForward, contentAfter: unformat(`

[]a

`), }); }); test("should not delete an empty unbreakable when there is no elements to delete after (forward)", async () => { await testEditor({ contentBefore: unformat(`
a
[]
`), stepFunction: deleteForward, contentAfter: unformat(`
a
[]
`), }); }); }); describe("start text", () => { test("should not merge p with an unbreakable (forward)", async () => { await testEditor({ contentBefore: `

a[]

b
`, stepFunction: deleteForward, contentAfter: `

a[]

b
`, }); }); test("should not remove unbreakable after an unbreakable (forward)", async () => { await testEditor({ contentBefore: unformat(`
b[]
a
`), stepFunction: deleteForward, contentAfter: unformat(`
b[]
a
`), }); }); test("should not merge unbreakable after a p (forward)", async () => { await testEditor({ contentBefore: unformat(`
b[]

a

`), stepFunction: deleteForward, contentAfter: unformat(`
b[]

a

`), }); }); test("should not merge unbreakable after an empty unbreakable (forward)", async () => { await testEditor({ contentBefore: unformat(`
b[]

`), stepFunction: deleteForward, contentAfter: unformat(`
b[]

`), }); }); test("should not merge unbreakable after an empty p (forward)", async () => { await testEditor({ contentBefore: unformat(`
b[]


`), stepFunction: deleteForward, contentAfter: unformat(`
b[]


`), }); }); }); }); // Only few tests are made with the selection not collapsed it should use the // same logic as for the backward (deleteRange). describe("selection not collapsed", () => { test("should not break unbreakables (delete forward) (1)", async () => { await testEditor({ contentBefore: unformat(`
a[bc
de]f
`), stepFunction: deleteForward, contentAfter: unformat(`
a[]
f
`), }); }); test("should not break unbreakables (delete forward) (2)", async () => { await testEditor({ contentBefore: unformat(`

a[b

c]d

`), stepFunction: deleteForward, contentAfter: unformat(`

a[]

d

`), // JW without oe_breakable classes of course }); }); test("should delete first character of unbreakable, ignoring selected paragraph break (forward)", async () => { await testEditor({ contentBefore: '

abc[

d]ef

', stepFunction: deleteForward, contentAfter: '

abc[]

ef

', }); }); }); }); describe("list", () => { describe("selection collapsed", () => { test("should not outdent while nested within a list item if the list is unbreakable", async () => { // Only one LI. await testEditor({ contentBefore: '

abc

  1. []def
', stepFunction: deleteBackward, contentAfter: '

abc

  1. []def
', }); // First LI. await testEditor({ contentBefore: '
  1. []abc
  2. def
', stepFunction: deleteBackward, contentAfter: '
  1. []abc
  2. def
', }); // In the middle. await testEditor({ contentBefore: '
  1. abc
  2. []def
  3. ghi
', stepFunction: deleteBackward, contentAfter: '
  1. abc
  2. []def
  3. ghi
', }); // Last LI. await testEditor({ contentBefore: '
  1. abc
  2. []def
', stepFunction: deleteBackward, contentAfter: '
  1. abc
  2. []def
', }); // With a div before the list: await testEditor({ contentBefore: '
abc
  1. def
  2. []ghi
  3. jkl
', stepFunction: deleteBackward, contentAfter: '
abc
  1. def
  2. []ghi
  3. jkl
', }); }); test("shoud not outdent list item in unsplittable list, but merge with previous LI", async () => { await testEditor({ contentBefore: unformat(`
  1. abc
  2. []def
`), stepFunction: deleteBackward, contentAfter: unformat(`
  1. abc[]def
`), }); }); test("shoud not outdent list item in unsplittable list, nor merge it with previous block", async () => { await testEditor({ contentBefore: unformat(`

abc

  1. []abc
  2. def
`), stepFunction: deleteBackward, contentAfter: unformat(`

abc

  1. []abc
  2. def
`), }); }); test("shoud not outdent list item nested in unsplittable list", async () => { await testEditor({ contentBefore: unformat(`

abc

    1. []abc
    2. def
`), stepFunction: deleteBackward, contentAfter: unformat(`

abc

    1. []abc
    2. def
`), }); }); }); describe("selection not collapsed", () => { test("shoud not merge list item in the previous unbreakable sibling (1)", async () => { await testEditor({ contentBefore: unformat(`

a[bc

  1. d]ef
  2. ghi
`), stepFunction: deleteBackward, contentAfter: unformat(`

a[]

  1. ef
  2. ghi
`), }); }); test("shoud not merge list item in the previous unbreakable sibling (2)", async () => { await testEditor({ contentBefore: unformat(`

a[bc

  1. d]ef
  2. ghi
`), stepFunction: deleteBackward, contentAfter: unformat(`

a[]

  1. ef
  2. ghi
`), }); }); }); });