import { describe, test } from "@odoo/hoot";
import { testEditor } from "../_helpers/editor";
import { insertLineBreak } from "../_helpers/user_actions";
describe("Selection collapsed", () => {
describe("Basic", () => {
test("should insert a
into an empty paragraph", async () => {
await testEditor({
contentBefore: "
[]
",
stepFunction: insertLineBreak,
contentAfter: "
[]
",
});
// TODO this cannot actually be tested currently as a
// backspace/delete in that case is not even detected
// (no input event to rollback)
// await testEditor({
// contentBefore: '[
]
',
// stepFunction: insertLineBreak,
// contentAfter: '
[]
',
// });
// TODO to check: the cursor cannot be in that position...
// await testEditor({
// contentBefore: '
[]
',
// stepFunction: insertLineBreak,
// contentAfter: '
[]
',
// });
});
test("should insert a
at the beggining of a paragraph", async () => {
await testEditor({
contentBefore: "[]abc
",
stepFunction: insertLineBreak,
contentAfter: "
[]abc
",
});
await testEditor({
contentBefore: "[] abc
",
stepFunction: insertLineBreak,
// The space should have been parsed away.
contentAfter: "
[]abc
",
});
});
test("should insert a
within text", async () => {
await testEditor({
contentBefore: "ab[]cd
",
stepFunction: insertLineBreak,
contentAfter: "ab
[]cd
",
});
await testEditor({
contentBefore: "ab []cd
",
stepFunction: insertLineBreak,
// The space is converted to a non-breaking space so it
// is visible (because it's before a
).
contentAfter: "ab
[]cd
",
});
await testEditor({
contentBefore: "ab[] cd
",
stepFunction: insertLineBreak,
// The space is converted to a non-breaking space so it
// is visible (because it's after a
).
contentAfter: "ab
[] cd
",
});
});
test("should insert a line break (2
) at the end of a paragraph", async () => {
await testEditor({
contentBefore: "abc[]
",
stepFunction: insertLineBreak,
// The second
is needed to make the first
// one visible.
contentAfter: "abc
[]
",
});
});
});
describe("Consecutive", () => {
test("should insert two
at the beggining of an empty paragraph", async () => {
await testEditor({
contentBefore: "[]
",
stepFunction: async (editor) => {
await insertLineBreak(editor);
await insertLineBreak(editor);
},
contentAfter: "
[]
",
});
// TODO this cannot actually be tested currently as a
// backspace/delete in that case is not even detected
// (no input event to rollback)
// await testEditor({
// contentBefore: '[
]
',
// stepFunction: async (editor) => {
// await insertLineBreak(editor);
// await insertLineBreak(editor);
// },
// contentAfter: '
[]
',
// });
// TODO seems like a theoretical case, if needed it could
// be about checking at the start of the shift-enter if
// we are not between left-state BR and right-state block.
// await testEditor({
// contentBefore: '
[]
',
// stepFunction: async (editor) => {
// await insertLineBreak(editor);
// await insertLineBreak(editor);
// },
// contentAfter: '
[]
',
// });
});
test("should insert two
at the beggining of a paragraph", async () => {
await testEditor({
contentBefore: "[]abc
",
stepFunction: async (editor) => {
await insertLineBreak(editor);
await insertLineBreak(editor);
},
contentAfter: "
[]abc
",
});
});
test("should insert two
within text", async () => {
await testEditor({
contentBefore: "ab[]cd
",
stepFunction: async (editor) => {
await insertLineBreak(editor);
await insertLineBreak(editor);
},
contentAfter: "ab
[]cd
",
});
});
test("should insert two line breaks (3
) at the end of a paragraph", async () => {
await testEditor({
contentBefore: "abc[]
",
stepFunction: async (editor) => {
await insertLineBreak(editor);
await insertLineBreak(editor);
},
// the last
is needed to make the first one
// visible.
contentAfter: "abc
[]
",
});
});
});
describe("Format", () => {
test("should insert a
before a format node", async () => {
await testEditor({
contentBefore: "abc[]def
",
stepFunction: insertLineBreak,
contentAfter: "abc
[]def
",
});
await testEditor({
// That selection is equivalent to []
contentBefore: "abc[]def
",
stepFunction: insertLineBreak,
// JW cAfter: 'abc
[]def
',
contentAfter: "abc
[]def
",
});
await testEditor({
contentBefore: "abc []def
",
stepFunction: insertLineBreak,
// The space is converted to a non-breaking space so it
// is visible (because it's before a
).
contentAfter: "abc
[]def
",
});
await testEditor({
contentBefore: "abc[] def
",
stepFunction: insertLineBreak,
// The space is converted to a non-breaking space so it
// is visible (because it's before a
).
contentAfter: "abc
[] def
",
});
});
test("should insert a
after a format node", async () => {
await testEditor({
contentBefore: "abc[]def
",
stepFunction: insertLineBreak,
// JW cAfter: 'abc[]
def
',
contentAfter: "abc
[]def
",
});
await testEditor({
// That selection is equivalent to []
contentBefore: "abc[]def
",
stepFunction: insertLineBreak,
// JW cAfter: 'abc[]
def
',
contentAfter: "abc
[]def
",
});
await testEditor({
contentBefore: "abc[] def
",
stepFunction: insertLineBreak,
// The space is converted to a non-breaking space so
// it is visible (because it's after a
).
// Visually, the caret does show _after_ the line
// break.
// JW cAfter: 'abc[]
def
',
contentAfter: "abc
[] def
",
});
await testEditor({
contentBefore: "abc []def
",
stepFunction: insertLineBreak,
// The space is converted to a non-breaking space so it
// is visible (because it's before a
).
contentAfter: "abc
[]def
",
});
});
test("should insert a
at the beginning of a format node", async () => {
await testEditor({
contentBefore: "[]abc
",
stepFunction: insertLineBreak,
// JW cAfter: '
[]abc
',
contentAfter: "
[]abc
",
});
await testEditor({
// That selection is equivalent to []
contentBefore: "[]abc
",
stepFunction: insertLineBreak,
contentAfter: "
[]abc
",
});
await testEditor({
contentBefore: "[] abc
",
stepFunction: insertLineBreak,
// The space should have been parsed away.
contentAfter: "
[]abc
",
});
});
test("should insert a
within a format node", async () => {
await testEditor({
contentBefore: "ab[]cd
",
stepFunction: insertLineBreak,
contentAfter: "ab
[]cd
",
});
await testEditor({
contentBefore: "ab []cd
",
stepFunction: insertLineBreak,
// The space is converted to a non-breaking space so it
// is visible (because it's before a
).
contentAfter: "ab
[]cd
",
});
await testEditor({
contentBefore: "ab[] cd
",
stepFunction: insertLineBreak,
// The space is converted to a non-breaking
// space so it is visible.
contentAfter: "ab
[] cd
",
});
});
test("should insert a line break (2
) at the end of a format node", async () => {
await testEditor({
contentBefore: "abc[]
",
stepFunction: insertLineBreak,
// The second
is needed to make the first
// one visible.
// JW cAfter: 'abc
[]
',
contentAfter: "abc
[]
",
});
await testEditor({
// That selection is equivalent to []
contentBefore: "abc[]
",
stepFunction: insertLineBreak,
// The second
is needed to make the first
// one visible.
contentAfter: "abc
[]
",
});
await testEditor({
contentBefore: "abc[]
",
stepFunction: insertLineBreak,
// The space should have been parsed away.
// The second
is needed to make the first
// one visible.
contentAfter: "abc
[]
",
});
});
});
describe("With attributes", () => {
test("should insert a line break before a span with class", async () => {
await testEditor({
contentBefore:
'dom to
[]edit
',
stepFunction: insertLineBreak,
contentAfter:
'dom to
[]edit
',
});
});
test("should insert a line break within a span with a bold", async () => {
await testEditor({
contentBefore: 'ab[]cd
',
stepFunction: insertLineBreak,
contentAfter: 'ab
[]cd
',
});
});
});
});
describe("Selection not collapsed", () => {
test("should delete the first half of a paragraph, then insert a
", async () => {
// Forward selection
await testEditor({
contentBefore: "[ab]cd
",
stepFunction: insertLineBreak,
contentAfter: "
[]cd
",
});
// Backward selection
await testEditor({
contentBefore: "]ab[cd
",
stepFunction: insertLineBreak,
contentAfter: "
[]cd
",
});
});
test("should delete part of a paragraph, then insert a
", async () => {
// Forward selection
await testEditor({
contentBefore: "a[bc]d
",
stepFunction: insertLineBreak,
contentAfter: "a
[]d
",
});
// Backward selection
await testEditor({
contentBefore: "a]bc[d
",
stepFunction: insertLineBreak,
contentAfter: "a
[]d
",
});
});
test("should delete the last half of a paragraph, then insert a line break (2
)", async () => {
// Forward selection
await testEditor({
contentBefore: "ab[cd]
",
stepFunction: insertLineBreak,
// the second
is needed to make the first one
// visible.
contentAfter: "ab
[]
",
});
// Backward selection
await testEditor({
contentBefore: "ab]cd[
",
stepFunction: insertLineBreak,
// the second
is needed to make the first one
// visible.
contentAfter: "ab
[]
",
});
});
test("should delete all contents of a paragraph, then insert a line break", async () => {
// Forward selection
await testEditor({
contentBefore: "[abcd]
",
stepFunction: insertLineBreak,
contentAfter: "
[]
",
});
// Backward selection
await testEditor({
contentBefore: "]abcd[
",
stepFunction: insertLineBreak,
contentAfter: "
[]
",
});
});
});
describe("table", () => {
test("should remove all contents of an anchor td and insert a line break on forward selection", async () => {
// Forward selection
await testEditor({
contentBefore: `
`,
stepFunction: insertLineBreak,
contentAfter: `
`,
});
});
test("should remove all contents of an anchor td and insert a line break on backward selection", async () => {
// Backward selection
await testEditor({
contentBefore: `
`,
stepFunction: insertLineBreak,
contentAfter: `
`,
});
});
});