import { describe, expect, test } from "@odoo/hoot";
import { setupEditor, testEditor } from "../_helpers/editor";
import { getContent } from "../_helpers/selection";
import { execCommand } from "../_helpers/userCommands";
async function insertSeparator(editor) {
execCommand(editor, "insertSeparator");
}
describe("insert separator", () => {
test("should insert a separator inside editable with contenteditable set to false", async () => {
await testEditor({
contentBefore: "
[]
",
stepFunction: insertSeparator,
contentAfterEdit: `
[]
`,
contentAfter: "
[]
",
});
});
test("should insert a separator before current element", async () => {
await testEditor({
contentBefore: "content
[]
",
stepFunction: insertSeparator,
contentAfterEdit: `content
[]
`,
contentAfter: "content
[]
",
});
});
test("should insert a separator before current paragraph related element but remain inside the div", async () => {
await testEditor({
contentBefore: "",
stepFunction: insertSeparator,
contentAfter: "",
});
});
test("should not insert a separator inside a list", async () => {
await testEditor({
contentBefore: "",
stepFunction: insertSeparator,
contentAfter: "",
});
});
test("should insert a separator before a p element inside a table cell", async () => {
await testEditor({
contentBefore: "",
stepFunction: insertSeparator,
contentAfter: "",
});
});
test("should insert a seperator within a block node", async () => {
await testEditor({
contentBefore: "[]
",
stepFunction: insertSeparator,
contentAfter: "
[]
",
});
});
test("should set the contenteditable attribute to false on the separator when inserted as a child after normalization", async () => {
const { el, editor } = await setupEditor("[]
");
const div = editor.document.createElement("div");
const separator = editor.document.createElement("hr");
div.append(separator);
el.append(div);
editor.shared.history.addStep();
expect(getContent(el)).toBe(
`[]
`
);
});
});