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(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
test("should not delete an empty unbreakable when there is no elements to delete before (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
});
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(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
test("should not merge unbreakable before a p (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
test("should not merge unbreakable before an empty unbreakable (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
test("should not merge unbreakable before an empty p (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
});
});
describe("selection not collapsed", () => {
describe("monolevel", () => {
describe("anchor start", () => {
test("should remove sandwitched unbreakable (anchor start, focus start) (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
test("should remove sandwitched unbreakable (anchor start, focus between) (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
});
describe("anchor between", () => {
test("should remove sandwitched unbreakable (anchor between, focus between) (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
test("should remove sandwitched unbreakable (anchor between, focus end) (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
});
});
describe("multilevel", () => {
describe("anchor start", () => {
test("should remove sandwitched unbreakable (multilevel, anchor start, focus between) (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
});
describe("anchor between", () => {
test("should remove sandwitched unbreakable (multilevel, anchor between, focus between) (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
`),
});
});
test("should remove sandwitched unbreakable (multilevel, anchor between, focus end) (backward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: (editor) => deleteBackward(editor),
contentAfter: unformat(`
`),
});
});
});
});
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(`
`),
stepFunction: deleteForward,
contentAfter: unformat(`
`),
});
});
test("should not delete an empty unbreakable when there is no elements to delete after (forward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteForward,
contentAfter: unformat(`
`),
});
});
});
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(`
`),
stepFunction: deleteForward,
contentAfter: unformat(`
`),
});
});
test("should not merge unbreakable after a p (forward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteForward,
contentAfter: unformat(`
`),
});
});
test("should not merge unbreakable after an empty unbreakable (forward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteForward,
contentAfter: unformat(`
`),
});
});
test("should not merge unbreakable after an empty p (forward)", async () => {
await testEditor({
contentBefore: unformat(`
`),
stepFunction: deleteForward,
contentAfter: unformat(`
`),
});
});
});
});
// 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(`
`),
stepFunction: deleteForward,
contentAfter: unformat(`
`),
});
});
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
- []def
',
stepFunction: deleteBackward,
contentAfter: 'abc
- []def
',
});
// First LI.
await testEditor({
contentBefore:
'- def
',
stepFunction: deleteBackward,
contentAfter:
'- def
',
});
// In the middle.
await testEditor({
contentBefore:
'abc
- ghi
',
stepFunction: deleteBackward,
contentAfter:
'abc
- ghi
',
});
// Last LI.
await testEditor({
contentBefore:
'- abc
',
stepFunction: deleteBackward,
contentAfter:
'- abc
',
});
// With a div before the list:
await testEditor({
contentBefore:
'abc
- def
- jkl
',
stepFunction: deleteBackward,
contentAfter:
'abc
- def
- jkl
',
});
});
test("shoud not outdent list item in unsplittable list, but merge with previous LI", async () => {
await testEditor({
contentBefore: unformat(`
- abc
- []def
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
- abc[]def
`),
});
});
test("shoud not outdent list item in unsplittable list, nor merge it with previous block", async () => {
await testEditor({
contentBefore: unformat(`
abc
- []abc
- def
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
abc
- []abc
- def
`),
});
});
test("shoud not outdent list item nested in unsplittable list", async () => {
await testEditor({
contentBefore: unformat(`
abc
-
- []abc
- def
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
abc
-
- []abc
- def
`),
});
});
});
describe("selection not collapsed", () => {
test("shoud not merge list item in the previous unbreakable sibling (1)", async () => {
await testEditor({
contentBefore: unformat(`
a[bc
- d]ef
- ghi
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
a[]
- ef
- ghi
`),
});
});
test("shoud not merge list item in the previous unbreakable sibling (2)", async () => {
await testEditor({
contentBefore: unformat(`
- d]ef
- ghi
`),
stepFunction: deleteBackward,
contentAfter: unformat(`
- ef
- ghi
`),
});
});
});
});