Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/components/__tests__/ActionButtons.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { render, screen, fireEvent } from "@testing-library/react";
import { describe, it, expect, vi, beforeEach } 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(<ActionButtons {...defaultProps} />);

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(<ActionButtons {...defaultProps} />);

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(<ActionButtons {...defaultProps} />);

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(<ActionButtons {...defaultProps} previewUrl={null} />);

const copyButton = screen.getByRole("button", { name: /Copy Image/i });
const downloadButton = screen.getByRole("button", { name: /Download PNG/i });

expect(copyButton).toBeDisabled();
expect(downloadButton).toBeDisabled();
});
Comment on lines +43 to +50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 disabled 状態でのクリック動作が未検証

previewUrlnull の場合にボタンが disabled になることは確認していますが、disabled 状態でクリックしても handleCopy / handleDownload が呼ばれないことのテストがありません。fireEvent.click は disabled 属性を無視して onClick を呼び出すため、disabled 時にハンドラを実行しないという保証が現在のテストでは得られていません。

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/components/__tests__/ActionButtons.test.tsx
Line: 43-50

Comment:
**disabled 状態でのクリック動作が未検証**

`previewUrl``null` の場合にボタンが disabled になることは確認していますが、disabled 状態でクリックしても `handleCopy` / `handleDownload` が呼ばれないことのテストがありません。`fireEvent.click` は disabled 属性を無視して onClick を呼び出すため、disabled 時にハンドラを実行しないという保証が現在のテストでは得られていません。

How can I resolve this? If you propose a fix, please make it concise.


it("shows 'Copied!' text when copyStatus is 'copied'", () => {
render(<ActionButtons {...defaultProps} copyStatus="copied" />);

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(<ActionButtons {...defaultProps} copyStatus="error" />);

expect(screen.getByRole("button", { name: /Copy Image/i })).toBeInTheDocument();
expect(screen.queryByRole("button", { name: /Copied!/i })).not.toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
Loading