diff --git a/apps/dokploy/__test__/utils/copy-input.test.ts b/apps/dokploy/__test__/utils/copy-input.test.ts new file mode 100644 index 0000000000..90fca63daa --- /dev/null +++ b/apps/dokploy/__test__/utils/copy-input.test.ts @@ -0,0 +1,32 @@ +import copy from "copy-to-clipboard"; +import { toast } from "sonner"; +import { beforeEach, describe, expect, test, vi } from "vitest"; +import { copyToClipboard } from "@/components/shared/copy-input"; + +vi.mock("copy-to-clipboard", () => ({ default: vi.fn() })); +vi.mock("sonner", () => ({ toast: { success: vi.fn() } })); + +describe("copyToClipboard", () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + test("copies the value to the clipboard", () => { + copyToClipboard("admin"); + expect(copy).toHaveBeenCalledWith("admin"); + }); + + test("shows a success toast", () => { + copyToClipboard("admin"); + expect(toast.success).toHaveBeenCalledWith("Value is copied to clipboard"); + }); + + test("returns the copied value", () => { + expect(copyToClipboard("admin")).toBe("admin"); + }); + + test("falls back to an empty string for undefined", () => { + expect(copyToClipboard(undefined)).toBe(""); + expect(copy).toHaveBeenCalledWith(""); + }); +}); diff --git a/apps/dokploy/components/dashboard/libsql/general/show-internal-libsql-credentials.tsx b/apps/dokploy/components/dashboard/libsql/general/show-internal-libsql-credentials.tsx index 6c13502426..19128fe3c7 100644 --- a/apps/dokploy/components/dashboard/libsql/general/show-internal-libsql-credentials.tsx +++ b/apps/dokploy/components/dashboard/libsql/general/show-internal-libsql-credentials.tsx @@ -1,4 +1,5 @@ import { SelectGroup } from "@radix-ui/react-select"; +import { CopyInput } from "@/components/shared/copy-input"; import { ToggleVisibilityInput } from "@/components/shared/toggle-visibility-input"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; @@ -28,7 +29,7 @@ export const ShowInternalLibsqlCredentials = ({ libsqlId }: Props) => {