import { describe, expect, test } from "@odoo/hoot";
import { press } from "@odoo/hoot-dom";
import { setupEditor } from "./_helpers/editor";
describe("range collapsed", () => {
test("should ignore copying an empty selection with empty clipboardData", async () => {
await setupEditor("
[]
");
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
// Check that nothing was set as clipboard content
expect(clipboardData.types.length).toBe(0);
});
test("should ignore copying an empty selection with clipboardData", async () => {
await setupEditor("[]
");
const clipboardData = new DataTransfer();
clipboardData.setData("text/plain", "should stay");
await press(["ctrl", "c"], { dataTransfer: clipboardData });
// Check that clipboard data was not overwritten
expect(clipboardData.getData("text/plain")).toBe("should stay");
});
});
describe("range not collapsed", () => {
test("should copy a selection as text/plain, text/html and application/vnd.odoo.odoo-editor only text", async () => {
await setupEditor("a[bcd]e
");
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/plain")).toBe("bcd");
expect(clipboardData.getData("text/html")).toBe("bcd
");
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe("bcd
");
});
test("should copy a selection as text/plain, text/html and application/vnd.odoo.odoo-editor with a
", async () => {
await setupEditor("[abc
efg]
");
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/plain")).toBe("abc\nefg");
expect(clipboardData.getData("text/html")).toBe("abc
efg
");
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe("abc
efg
");
});
test.tags("focus required");
test("should copy a selection as text/plain, text/html and application/vnd.odoo.odoo-editor in table", async () => {
await setupEditor(
`]`
);
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/plain")).toBe("a");
expect(clipboardData.getData("text/html")).toBe(
""
);
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe(
""
);
});
test("should copy a selection as text/html and application/vnd.odoo.odoo-editor in table", async () => {
await setupEditor(
"[abcd
]"
);
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/html")).toBe(
"abcd
"
);
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe(
"abcd
"
);
});
test("should wrap the selected text with clones of ancestors up to a block element to keep styles (1)", async () => {
await setupEditor(
'[Test Test]
'
);
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/plain")).toBe("Test Test");
expect(clipboardData.getData("text/html")).toBe(
'Test Test
'
);
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe(
'Test Test
'
);
});
test("should wrap the selected text with clones of ancestors up to a block element to keep styles (2)", async () => {
await setupEditor(
'hello [there]
'
);
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/plain")).toBe("there");
expect(clipboardData.getData("text/html")).toBe(
'there
'
);
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe(
'there
'
);
});
test("should copy the selection as a single list item (1)", async () => {
await setupEditor("");
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/plain")).toBe("First");
expect(clipboardData.getData("text/html")).toBe("First");
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe("First");
});
test("should copy the selection as a single list item (2)", async () => {
await setupEditor("");
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/plain")).toBe("List");
expect(clipboardData.getData("text/html")).toBe("List");
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe("List");
});
test("should copy the selection as a single list item (3)", async () => {
await setupEditor(
''
);
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/plain")).toBe("First");
expect(clipboardData.getData("text/html")).toBe(
'First'
);
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe(
'First'
);
});
test("should copy the selection as a list with multiple list items", async () => {
await setupEditor("");
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/plain")).toBe("First\nSecond");
expect(clipboardData.getData("text/html")).toBe("");
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe(
""
);
});
test("should remove ufeff characters from link selection", async () => {
await setupEditor('[label]
');
const clipboardData = new DataTransfer();
await press(["ctrl", "c"], { dataTransfer: clipboardData });
expect(clipboardData.getData("text/plain")).toBe("label");
expect(clipboardData.getData("text/html")).toBe(
'label
'
);
expect(clipboardData.getData("application/vnd.odoo.odoo-editor")).toBe(
'label
'
);
});
});