Skip to content

🧪 Add tests for ActionButtons component#369

Open
is0692vs wants to merge 1 commit into
mainfrom
jules-17690030483839308914-74a6037c
Open

🧪 Add tests for ActionButtons component#369
is0692vs wants to merge 1 commit into
mainfrom
jules-17690030483839308914-74a6037c

Conversation

@is0692vs

@is0692vs is0692vs commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

🎯 What: This PR addresses a testing gap by adding comprehensive tests for the ActionButtons component, ensuring reliable behavior for its UI states and click interactions.

📊 Coverage: The tests now cover the following scenarios:

  • Renders the base buttons in the 'idle' state.
  • Properly toggles button content to display the 'Copied!' state.
  • Disables both the copy and download buttons correctly when previewUrl is null.
  • Enables the buttons when previewUrl is provided.
  • Triggers the appropriate click handlers (handleCopy and handleDownload) successfully on interaction.

Result: Test coverage for ActionButtons.tsx is now effectively 100%, contributing to a more robust component testing suite and safer future refactoring.


PR created automatically by Jules for task 17690030483839308914 started by @is0692vs

Greptile Summary

このPRは ActionButtons コンポーネントに対する新規テストファイルを追加し、vitest.config.ts のカバレッジ対象にも同コンポーネントを追加します。

  • ActionButtons.test.tsx に6つのテストケースを追加。idle/copied 状態の表示切り替え、previewUrl の null/非null によるボタンの enabled/disabled、クリックハンドラーの呼び出しを網羅。
  • vitest.config.ts のカバレッジ include リストに src/components/ActionButtons.tsx を追加し、カバレッジレポートの対象とした。

Confidence Score: 4/5

テストのみの変更であり、プロダクションコードへの影響はありません。安全にマージ可能です。

テストロジックは概ね正確で、コンポーネントの主要な振る舞いをカバーしています。ただし describe スコープで生成した vi.fn() モックがテスト間でリセットされない点、// @vitest-environment jsdom ディレクティブの冗長な記述、copyStatus="error" ケースのテスト欠落という軽微な改善点があります。

src/components/ActionButtons.test.tsx — モックのリセット処理と error 状態のテストカバレッジを確認してください。

Important Files Changed

Filename Overview
src/components/ActionButtons.test.tsx ActionButtons コンポーネントの新規テストファイル。idle/copied 状態、disabled/enabled、クリックハンドラーの6テストを追加。vi.fn() のモックリセットが不足している軽微な問題あり。
vitest.config.ts カバレッジ対象ファイルに ActionButtons.tsx を追加。既存設定への影響なし。

Sequence Diagram

sequenceDiagram
    participant Test as テストケース
    participant RTL as Testing Library
    participant Comp as ActionButtons

    Test->>RTL: "render(ActionButtons copyStatus=idle)"
    RTL->>Comp: マウント
    Comp-->>RTL: Copy Image / Download PNG ボタン描画
    RTL-->>Test: screen クエリ可能

    Test->>RTL: "render(ActionButtons copyStatus=copied)"
    RTL->>Comp: マウント
    Comp-->>RTL: Copied! ボタン描画

    Test->>RTL: "render(ActionButtons previewUrl=null)"
    RTL->>Comp: マウント
    Comp-->>RTL: 両ボタンを disabled で描画

    Test->>RTL: userEvent.click(copyButton)
    RTL->>Comp: onClick イベント発火
    Comp->>Test: handleCopy() 呼び出し確認
Loading
Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
src/components/ActionButtons.test.tsx:8-14
`describe` ブロックのトップレベルで `vi.fn()` を一度だけ生成しているため、各テスト間でモックがリセットされません。現在のテストコードでは `defaultProps.handleCopy` / `handleDownload` に対して直接アサーションしていないため実害はありませんが、将来テストを追加した際に呼び出し回数が蓄積されてテストが誤って失敗するリスクがあります。`beforeEach` でモックをクリアするのが望ましいです。

```suggestion
describe("ActionButtons", () => {
  const defaultProps = {
    handleCopy: vi.fn(),
    handleDownload: vi.fn(),
    previewUrl: "https://example.com/preview.png",
    copyStatus: "idle" as const,
  };

  beforeEach(() => {
    vi.clearAllMocks();
  });
```

### Issue 2 of 3
src/components/ActionButtons.test.tsx:1-2
`vitest.config.ts` ですでに `environment: "jsdom"` がグローバル設定されているため、このファイル先頭の `// @vitest-environment jsdom` ディレクティブは冗長です。削除することで設定の重複を避けられます。

```suggestion
import { render, screen } from "@testing-library/react";
```

### Issue 3 of 3
src/components/ActionButtons.test.tsx:22-30
**`copyStatus="error"` の状態がテストされていない**

`copyStatus` の型は `"idle" | "copied" | "error"` の3値ですが、`"error"` ケースのテストが存在しません。現在のコンポーネント実装では `"error"``"idle"` と同じ表示になりますが、将来の変更でエラー用の表示が追加された際にカバレッジが不足します。少なくとも `"error"` の場合に "Copy Image" ボタンが表示されることを確認するテストの追加を推奨します。

Reviews (1): Last reviewed commit: "test: add tests for ActionButtons and in..." | Re-trigger Greptile

Greptile also left 3 inline comments on this PR.

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
github-user-summary Ignored Ignored Jun 12, 2026 6:53am

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@is0692vs, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 45 minutes and 36 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5266ac5b-2184-421b-8e6b-4a3206b03700

📥 Commits

Reviewing files that changed from the base of the PR and between a475ecb and 547f049.

📒 Files selected for processing (2)
  • src/components/ActionButtons.test.tsx
  • vitest.config.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jules-17690030483839308914-74a6037c

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive suite of unit tests for the ActionButtons component in src/components/ActionButtons.test.tsx using Vitest and React Testing Library. It also updates vitest.config.ts to include src/components/ActionButtons.tsx in the configuration. No review comments were provided, and there is no additional feedback to address.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment on lines +8 to +14
describe("ActionButtons", () => {
const defaultProps = {
handleCopy: vi.fn(),
handleDownload: vi.fn(),
previewUrl: "https://example.com/preview.png",
copyStatus: "idle" as const,
};

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 describe ブロックのトップレベルで vi.fn() を一度だけ生成しているため、各テスト間でモックがリセットされません。現在のテストコードでは defaultProps.handleCopy / handleDownload に対して直接アサーションしていないため実害はありませんが、将来テストを追加した際に呼び出し回数が蓄積されてテストが誤って失敗するリスクがあります。beforeEach でモックをクリアするのが望ましいです。

Suggested change
describe("ActionButtons", () => {
const defaultProps = {
handleCopy: vi.fn(),
handleDownload: vi.fn(),
previewUrl: "https://example.com/preview.png",
copyStatus: "idle" as const,
};
describe("ActionButtons", () => {
const defaultProps = {
handleCopy: vi.fn(),
handleDownload: vi.fn(),
previewUrl: "https://example.com/preview.png",
copyStatus: "idle" as const,
};
beforeEach(() => {
vi.clearAllMocks();
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/components/ActionButtons.test.tsx
Line: 8-14

Comment:
`describe` ブロックのトップレベルで `vi.fn()` を一度だけ生成しているため、各テスト間でモックがリセットされません。現在のテストコードでは `defaultProps.handleCopy` / `handleDownload` に対して直接アサーションしていないため実害はありませんが、将来テストを追加した際に呼び出し回数が蓄積されてテストが誤って失敗するリスクがあります。`beforeEach` でモックをクリアするのが望ましいです。

```suggestion
describe("ActionButtons", () => {
  const defaultProps = {
    handleCopy: vi.fn(),
    handleDownload: vi.fn(),
    previewUrl: "https://example.com/preview.png",
    copyStatus: "idle" as const,
  };

  beforeEach(() => {
    vi.clearAllMocks();
  });
```

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

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +1 to +2
// @vitest-environment jsdom
import { render, screen } from "@testing-library/react";

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 vitest.config.ts ですでに environment: "jsdom" がグローバル設定されているため、このファイル先頭の // @vitest-environment jsdom ディレクティブは冗長です。削除することで設定の重複を避けられます。

Suggested change
// @vitest-environment jsdom
import { render, screen } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/components/ActionButtons.test.tsx
Line: 1-2

Comment:
`vitest.config.ts` ですでに `environment: "jsdom"` がグローバル設定されているため、このファイル先頭の `// @vitest-environment jsdom` ディレクティブは冗長です。削除することで設定の重複を避けられます。

```suggestion
import { render, screen } from "@testing-library/react";
```

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

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +22 to +30

it("renders '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("disables both buttons when previewUrl is null", () => {

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 copyStatus="error" の状態がテストされていない

copyStatus の型は "idle" | "copied" | "error" の3値ですが、"error" ケースのテストが存在しません。現在のコンポーネント実装では "error""idle" と同じ表示になりますが、将来の変更でエラー用の表示が追加された際にカバレッジが不足します。少なくとも "error" の場合に "Copy Image" ボタンが表示されることを確認するテストの追加を推奨します。

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

Comment:
**`copyStatus="error"` の状態がテストされていない**

`copyStatus` の型は `"idle" | "copied" | "error"` の3値ですが、`"error"` ケースのテストが存在しません。現在のコンポーネント実装では `"error"``"idle"` と同じ表示になりますが、将来の変更でエラー用の表示が追加された際にカバレッジが不足します。少なくとも `"error"` の場合に "Copy Image" ボタンが表示されることを確認するテストの追加を推奨します。

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant