Commit 71237cf5 authored by davelopez's avatar davelopez
Browse files

Add unit test for Tools copyLink utility

parent f7e6d16d
Loading
Loading
Loading
Loading
+29 −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", () => {
        const toolId = "My Tool Id";
        copyLink(toolId);
        expect(writeText).toHaveBeenCalledTimes(1);
        expect(writeText).toHaveBeenCalledWith(expect.stringContaining("My%20Tool%20Id"));
    });
});