Loading client/src/components/Tool/utilities.js +3 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,9 @@ import { getAppRoot } from "onload/loadConfig"; import { copy } from "utils/clipboard"; export function copyLink(toolId, message) { copy(`${window.location.origin + getAppRoot()}root?tool_id=${toolId}`, message); const link = `${window.location.origin + getAppRoot()}root?tool_id=${toolId}`; // Encode the link to handle special characters in tool id copy(encodeURI(link), message); } export function copyId(toolId, message) { Loading client/src/components/Tool/utilities.test.ts 0 → 100644 +36 −0 Original line number Diff line number Diff line import { copyLink } from "./utilities"; const writeText = jest.fn(); Object.assign(navigator, { clipboard: { writeText, }, }); describe("copyLink", () => { beforeEach(() => { (navigator.clipboard.writeText as jest.Mock).mockResolvedValue(undefined); }); it("should copy the link to the clipboard", () => { const toolId = "MyToolId"; copyLink(toolId); expect(writeText).toHaveBeenCalledTimes(1); expect(writeText).toHaveBeenCalledWith(expect.stringContaining(toolId)); }); it("should encode the tool id with spaces", () => { const toolId = "My Tool Id"; copyLink(toolId); expect(writeText).toHaveBeenCalledTimes(1); expect(writeText).toHaveBeenCalledWith(expect.stringContaining("My%20Tool%20Id")); }); it("should not encode the character '+' in the tool id", () => { const toolId = "My Tool Id+1"; copyLink(toolId); expect(writeText).toHaveBeenCalledTimes(1); expect(writeText).toHaveBeenCalledWith(expect.stringContaining("My%20Tool%20Id+1")); }); }); Loading
client/src/components/Tool/utilities.js +3 −1 Original line number Diff line number Diff line Loading @@ -2,7 +2,9 @@ import { getAppRoot } from "onload/loadConfig"; import { copy } from "utils/clipboard"; export function copyLink(toolId, message) { copy(`${window.location.origin + getAppRoot()}root?tool_id=${toolId}`, message); const link = `${window.location.origin + getAppRoot()}root?tool_id=${toolId}`; // Encode the link to handle special characters in tool id copy(encodeURI(link), message); } export function copyId(toolId, message) { Loading
client/src/components/Tool/utilities.test.ts 0 → 100644 +36 −0 Original line number Diff line number Diff line import { copyLink } from "./utilities"; const writeText = jest.fn(); Object.assign(navigator, { clipboard: { writeText, }, }); describe("copyLink", () => { beforeEach(() => { (navigator.clipboard.writeText as jest.Mock).mockResolvedValue(undefined); }); it("should copy the link to the clipboard", () => { const toolId = "MyToolId"; copyLink(toolId); expect(writeText).toHaveBeenCalledTimes(1); expect(writeText).toHaveBeenCalledWith(expect.stringContaining(toolId)); }); it("should encode the tool id with spaces", () => { const toolId = "My Tool Id"; copyLink(toolId); expect(writeText).toHaveBeenCalledTimes(1); expect(writeText).toHaveBeenCalledWith(expect.stringContaining("My%20Tool%20Id")); }); it("should not encode the character '+' in the tool id", () => { const toolId = "My Tool Id+1"; copyLink(toolId); expect(writeText).toHaveBeenCalledTimes(1); expect(writeText).toHaveBeenCalledWith(expect.stringContaining("My%20Tool%20Id+1")); }); });