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: '

a\u200Bbcd[]e

', stepFunction: unlinkFromPopover, contentAfter: '

abcd[]e

', }); // With fontawesome at the middle of the link. await testEditor({ contentBefore: '

abc\u200Bd[]e

', stepFunction: unlinkFromPopover, contentAfter: '

abcd[]e

', }); // With fontawesome at the end of the link. await testEditor({ contentBefore: '

abcd[]\u200Be

', 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: '

a\u200Bb[]cde

', stepFunction: unlinkFromPopover, contentAfter: '

ab[]cde

', }); // With fontawesome at the middle of the link. await testEditor({ contentBefore: '

ab[]c\u200Bde

', stepFunction: unlinkFromPopover, contentAfter: '

ab[]cde

', }); // With fontawesome at the end of the link. await testEditor({ contentBefore: '

ab[]cd\u200Be

', 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: '

a\u200B[]bcde

', stepFunction: unlinkFromPopover, contentAfter: '

a[]bcde

', }); // With fontawesome at the middle of the link. await testEditor({ contentBefore: '

a[]bc\u200Bde

', stepFunction: unlinkFromPopover, contentAfter: '

a[]bcde

', }); // With fontawesome at the end of the link. await testEditor({ contentBefore: '

a[]bcd\u200Be

', 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: '

abc[]def

', stepFunction: unlinkFromPopover, contentAfter: '

abc[]def

', }); // With fontawesome at the start of the link. await testEditor({ contentBefore: '

ab\u200Bc[]def

', stepFunction: unlinkFromPopover, contentAfter: '

abc[]def

', }); // With fontawesome at the middle of the link. await testEditor({ contentBefore: '

abc\u200Bd[]efg

', stepFunction: unlinkFromPopover, contentAfter: '

abcd[]efg

', }); // With fontawesome at the end of the link. await testEditor({ contentBefore: '

abc[]d\u200Bef

', stepFunction: unlinkFromPopover, contentAfter: '

abc[]def

', }); }); }); 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: '

ab[c]de

', }); // BACKWARD await testEditor({ contentBefore: '

ab]c[de

', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: '

ab]c[de

', }); }); 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: '

[abcdef]

', stepFunction: async (editor) => { await unlinkByCommand(editor); }, contentAfter: '

[abcdef]

', }); }); }); });