import { describe, test } from "@odoo/hoot"; import { deleteBackward, insertLineBreak, insertText, undo } from "../_helpers/user_actions"; import { testEditor } from "../_helpers/editor"; import { animationFrame } from "@odoo/hoot-mock"; describe("range collapsed", () => { test("should not change the url when a link is not edited", async () => { await testEditor({ contentBefore: '

agoogle.comb

', contentAfter: '

agoogle.comb

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

agoogle.combcd[]

', stepFunction: async (editor) => { await insertText(editor, "e"); }, contentAfter: '

agoogle.combcde[]

', }); }); test("should change the url when the label change", async () => { await testEditor({ contentBefore: '

agoogle.co[]b

', stepFunction: async (editor) => { await insertText(editor, "m"); }, contentAfter: '

agoogle.com[]b

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

ago[]gle.comb

', stepFunction: async (editor) => { await insertText(editor, "o"); }, contentAfter: '

agoo[]gle.comb

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

ago[]gle.comb

', stepFunction: async (editor) => { await insertText(editor, "o"); }, contentAfter: '

agoo[]gle.comb

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

ahttp://go[]gle.comb

', stepFunction: async (editor) => { await insertText(editor, "o"); }, contentAfter: '

ahttp://goo[]gle.comb

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

ahello@moto[].com

', stepFunction: async (editor) => { await insertText(editor, "r"); }, contentAfter: '

ahello@motor[].com

', }); }); test("should change the url when the label change, without changing the protocol", async () => { await testEditor({ contentBefore: '

agoogle.co[]b

', stepFunction: async (editor) => { await insertText(editor, "m"); }, contentAfter: '

agoogle.com[]b

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

agoogle.co[]b

', stepFunction: async (editor) => { await insertText(editor, "m"); }, contentAfter: '

agoogle.com[]b

', }); }); test("should change the url when the label change, changing to the suitable protocol", async () => { await testEditor({ contentBefore: '

ahello[]moto.com

', stepFunction: async (editor) => { await insertText(editor, "@"); }, contentAfter: '

ahello@[]moto.com

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

ahello@[]moto.com

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

ahello[]moto.com

', }); }); test("should change the url in one step", async () => { await testEditor({ contentBefore: '

agoogle.co[]b

', stepFunction: async (editor) => { await insertText(editor, "m"); await undo(editor); }, contentAfter: '

agoogle.co[]b

', }); }); test("should not change the url when the label change (1)", async () => { await testEditor({ contentBefore: '

agoogle.com[]b

', stepFunction: async (editor) => { await insertText(editor, "u"); }, contentAfter: '

agoogle.comu[]b

', }); }); test("should not change the url when the label change (2)", async () => { await testEditor({ contentBefore: '

agoogle.com[]b

', stepFunction: async (editor) => { await animationFrame(); await insertLineBreak(editor); await insertText(editor, "odoo.com"); }, contentAfter: '

agoogle.com
odoo.com[]b

', }); }); }); describe("range not collapsed", () => { test("should change the url when the label change", async () => { await testEditor({ contentBefore: '

agoogle.[com]b

', stepFunction: async (editor) => { await insertText(editor, "be"); }, contentAfter: '

agoogle.be[]b

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

a[yahoo].comb

', stepFunction: async (editor) => { await insertText(editor, "google"); }, contentAfter: '

agoogle[].comb

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

ago[gle.c]omb

', stepFunction: async (editor) => { await insertText(editor, ".c"); }, contentAfter: '

ago.c[]omb

', }); }); test("should not change the url when the label change", async () => { await testEditor({ contentBefore: '

agoogl[e.com]b

', stepFunction: async (editor) => { await insertText(editor, "e"); }, contentAfter: '

agoogle[]b

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

agoogle.[com]b

', stepFunction: async (editor) => { await insertText(editor, "vvv"); }, contentAfter: '

agoogle.vvv[]b

', }); }); });