import { describe, test } from "@odoo/hoot"; import { testEditor } from "../_helpers/editor"; import { unlinkFromPopover, unlinkByCommand, unlinkFromToolbar } from "../_helpers/user_actions"; describe("range collapsed, remove by popover unlink button", () => { test("should remove the link if collapsed range at the end of a link", async () => { await testEditor({ contentBefore: '
abcd[]e
', stepFunction: unlinkFromPopover, contentAfter: "abcd[]e
", }); // With fontawesome at the start of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: 'abcd[]e
', }); // With fontawesome at the middle of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: 'abcd[]e
', }); // With fontawesome at the end of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: 'abcd[]e
', }); }); test("should remove the link if collapsed range in the middle a link", async () => { await testEditor({ contentBefore: 'ab[]cde
', stepFunction: unlinkFromPopover, contentAfter: "ab[]cde
", }); // With fontawesome at the start of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: 'ab[]cde
', }); // With fontawesome at the middle of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: 'ab[]cde
', }); // With fontawesome at the end of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: 'ab[]cde
', }); }); test("should remove the link if collapsed range at the start of a link", async () => { await testEditor({ contentBefore: 'a[]bcde
', stepFunction: unlinkFromPopover, contentAfter: "a[]bcde
", }); // With fontawesome at the start of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: 'a[]bcde
', }); // With fontawesome at the middle of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: 'a[]bcde
', }); // With fontawesome at the end of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: 'a[]bcde
', }); }); test("should remove only the current link if collapsed range in the middle of a link", async () => { await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: '', }); // With fontawesome at the start of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: '', }); // With fontawesome at the middle of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: '', }); // With fontawesome at the end of the link. await testEditor({ contentBefore: '', stepFunction: unlinkFromPopover, contentAfter: '', }); }); }); describe("range not collapsed", () => { describe("remove by toolbar unlink button", () => { test("should remove the link in the selected range at the end of a link", async () => { // FORWARD await testEditor({ contentBefore: 'abc[d]e
', stepFunction: unlinkFromToolbar, contentAfter: 'abc[d]e
', }); }); }); describe("remove by command", () => { test("should remove the link in the selected range at the end of a link", async () => { // FORWARD await testEditor({ contentBefore: 'abc[d]e
', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: 'abc[d]e
', }); // BACKWARD await testEditor({ contentBefore: 'abc]d[e
', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: 'abc]d[e
', }); }); test("should remove the link in the selected range in the middle of a link", async () => { // FORWARD await testEditor({ contentBefore: 'ab[c]de
', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: '', }); // BACKWARD await testEditor({ contentBefore: 'ab]c[de
', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: '', }); }); test("should remove the link in the selected range at the start of a link", async () => { // FORWARD await testEditor({ contentBefore: 'a[b]cde
', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: 'a[b]cde
', }); // BACKWARD await testEditor({ contentBefore: 'a]b[cde
', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: 'a]b[cde
', }); }); test("should remove the link in the selected range overlapping the end of a link", async () => { // FORWARD await testEditor({ contentBefore: 'abc[de]f
', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: 'abc[de]f
', }); // BACKWARD await testEditor({ contentBefore: 'abc]de[f
', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: 'abc]de[f
', }); }); test("should remove the link in the selected range overlapping the start of a link", async () => { // FORWARD await testEditor({ contentBefore: 'a[bc]def
', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: 'a[bc]def
', }); // BACKWARD await testEditor({ contentBefore: 'a]bc[def
', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: 'a]bc[def
', }); }); test("should not unlink selected non-editable links", async () => { await testEditor({ contentBefore: '', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: '[abcdef]
', }); }); }); });