From 7733daefe3472c49226d2d54c49e17ca5b62fad8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 12 Jun 2026 06:50:33 +0000 Subject: [PATCH 1/2] test: add unit tests for ActionButtons component Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- .../__tests__/ActionButtons.test.tsx | 65 +++++++++++++++++++ vitest.config.ts | 1 + 2 files changed, 66 insertions(+) create mode 100644 src/components/__tests__/ActionButtons.test.tsx diff --git a/src/components/__tests__/ActionButtons.test.tsx b/src/components/__tests__/ActionButtons.test.tsx new file mode 100644 index 00000000..1202fb9a --- /dev/null +++ b/src/components/__tests__/ActionButtons.test.tsx @@ -0,0 +1,65 @@ +import { render, screen, fireEvent } from "@testing-library/react"; +import { describe, it, expect, vi } from "vitest"; +import { ActionButtons } from "../ActionButtons"; + +describe("ActionButtons", () => { + const defaultProps = { + handleCopy: vi.fn(), + handleDownload: vi.fn(), + previewUrl: "https://example.com/image.png", + copyStatus: "idle" as const, + }; + + beforeEach(() => { + vi.clearAllMocks(); + }); + + it("renders both buttons", () => { + render(); + + expect(screen.getByRole("button", { name: /Copy Image/i })).toBeInTheDocument(); + expect(screen.getByRole("button", { name: /Download PNG/i })).toBeInTheDocument(); + }); + + it("calls handleCopy when Copy Image button is clicked", () => { + render(); + + const copyButton = screen.getByRole("button", { name: /Copy Image/i }); + fireEvent.click(copyButton); + + expect(defaultProps.handleCopy).toHaveBeenCalledTimes(1); + }); + + it("calls handleDownload when Download PNG button is clicked", () => { + render(); + + const downloadButton = screen.getByRole("button", { name: /Download PNG/i }); + fireEvent.click(downloadButton); + + expect(defaultProps.handleDownload).toHaveBeenCalledTimes(1); + }); + + it("disables both buttons when previewUrl is null", () => { + render(); + + const copyButton = screen.getByRole("button", { name: /Copy Image/i }); + const downloadButton = screen.getByRole("button", { name: /Download PNG/i }); + + expect(copyButton).toBeDisabled(); + expect(downloadButton).toBeDisabled(); + }); + + it("shows 'Copied!' text when copyStatus is 'copied'", () => { + render(); + + expect(screen.getByRole("button", { name: /Copied!/i })).toBeInTheDocument(); + expect(screen.queryByRole("button", { name: /Copy Image/i })).not.toBeInTheDocument(); + }); + + it("shows 'Copy Image' text when copyStatus is 'error'", () => { + render(); + + expect(screen.getByRole("button", { name: /Copy Image/i })).toBeInTheDocument(); + expect(screen.queryByRole("button", { name: /Copied!/i })).not.toBeInTheDocument(); + }); +}); diff --git a/vitest.config.ts b/vitest.config.ts index 94048567..12c2102d 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -21,6 +21,7 @@ export default defineConfig({ "src/components/LanguageChart.tsx", "src/components/SkillsCard.tsx", "src/components/LayoutEditor.tsx", + "src/components/ActionButtons.tsx", "src/lib/rateLimit.ts", "src/app/api/og/[username]/route.tsx" ], From 75a90b279c94d1f8c94a23abf841b7bd69d2eeff Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 12 Jun 2026 06:55:02 +0000 Subject: [PATCH 2/2] test: add unit tests for ActionButtons component Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/components/__tests__/ActionButtons.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/__tests__/ActionButtons.test.tsx b/src/components/__tests__/ActionButtons.test.tsx index 1202fb9a..544ac94d 100644 --- a/src/components/__tests__/ActionButtons.test.tsx +++ b/src/components/__tests__/ActionButtons.test.tsx @@ -1,5 +1,5 @@ import { render, screen, fireEvent } from "@testing-library/react"; -import { describe, it, expect, vi } from "vitest"; +import { describe, it, expect, vi, beforeEach } from "vitest"; import { ActionButtons } from "../ActionButtons"; describe("ActionButtons", () => {