Skip to content

🧪 Add missing tests for useCardSettings hook - #539

Closed
is0692vs wants to merge 2 commits into
mainfrom
test/use-card-settings-2593032690094081324
Closed

🧪 Add missing tests for useCardSettings hook#539
is0692vs wants to merge 2 commits into
mainfrom
test/use-card-settings-2593032690094081324

Conversation

@is0692vs

@is0692vs is0692vs commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🎯 What: Added missing test file for useCardSettings.ts
📊 Coverage: Covered initialization, hydration from local storage, saving to storage on update, and hook methods toggleMainBlockVisibility, toggleDisplayOption, and isBlockVisible.
Result: Improved test coverage and reliability for card layout and display settings.


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

Greptile Summary

useCardSettings の初期化、hydration、永続化、表示切り替え、および可視性判定を対象とするテストを追加しています。ただし、表示オプションのテストにある未使用の型抑制によって CI の型チェックが失敗します。

  • loadCardSettingssaveCardSettings をモックして hydration と保存を検証
  • レイアウトおよび表示オプションの切り替えを検証
  • ブロック可視性の判定を検証

Confidence Score: 4/5

不要な @ts-expect-error によって必須の型チェックが失敗するため、マージ前に削除する必要があります。

showAvatarshowBio は正規の CardDisplayOptions キーなので抑制対象の型エラーがなく、CI の tsc --noEmit が未使用ディレクティブをエラーとして報告します。

Files Needing Attention: src/hooks/tests/useCardSettings.test.ts

Important Files Changed

Filename Overview
src/hooks/tests/useCardSettings.test.ts フックの主要動作を網羅するテストを追加しているが、84行目と94行目の不要な @ts-expect-error が CI の型チェックを壊す。
Prompt To Fix All With AI
### Issue 1
src/hooks/__tests__/useCardSettings.test.ts:84
**未使用の型エラー抑制**

CI がこのテストを含めて `tsc --noEmit` を実行すると、`showAvatar` と94行目の `showBio` はどちらも有効な `CardDisplayOptions` キーであるため、`@ts-expect-error` が TS2578 として報告され、必須の typecheck ジョブが失敗します。

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "test: add tests for useCardSettings hook" | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used:

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 Aug 7, 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 Aug 7, 2026 6:50am

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 51 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

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.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5f2df49e-6c8e-4498-aefa-b5a47dcb6fcd

📥 Commits

Reviewing files that changed from the base of the PR and between eb95c48 and 2d66c77.

📒 Files selected for processing (1)
  • src/hooks/__tests__/useCardSettings.test.ts

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.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add Vitest coverage for useCardSettings hook behaviors

🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Add a jsdom hook test suite for useCardSettings initialization and hydration.
• Verify persistence behavior by asserting load/save calls on mount.
• Cover key hook APIs: block visibility toggling, display option toggling, visibility lookup.
Diagram

graph TD
  T["useCardSettings.test.ts"] --> H["useCardSettings hook"] --> CS["cardSettings lib"] --> LS[("Local storage")]
  H --> CL["cardLayout lib"]
  CS --> CSLOAD["loadCardSettings()"]
  CS --> CSSAVE["saveCardSettings()"]
  CL --> CLTOG["toggleBlockVisibility()"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Integration-style tests with real localStorage (no cardSettings mock)
  • ➕ Validates actual serialization/deserialization and storage key usage
  • ➕ Catches regressions in cardSettings implementation, not just hook wiring
  • ➖ More brittle (depends on storage schema and environment specifics)
  • ➖ Harder to isolate failures to hook vs persistence layer
2. Parameterize toggleDisplayOption coverage via table-driven tests
  • ➕ Reduces duplication and makes it easy to add new option keys
  • ➕ Clearer coverage map of supported option toggles
  • ➖ Slightly more abstraction for a small test suite
  • ➖ Still requires careful typing/mocks for option keys

Recommendation: Keep the current unit-test approach (mocking cardSettings/cardLayout) because it cleanly validates useCardSettings behavior and call contracts with minimal flakiness. If persistence bugs have been common, consider adding one additional integration test that uses real localStorage and the real cardSettings implementation to cover the end-to-end storage path.

Files changed (1) +112 / -0

Tests (1) +112 / -0
useCardSettings.test.tsAdd jsdom hook tests for useCardSettings persistence and toggles +112/-0

Add jsdom hook tests for useCardSettings persistence and toggles

• Introduces a new Vitest test suite using @testing-library/react to validate useCardSettings initial state, hydration behavior when mounted, and persistence via saveCardSettings. Adds coverage for toggleMainBlockVisibility, toggleDisplayOption, and isBlockVisible, mocking cardSettings and cardLayout for isolation.

src/hooks/tests/useCardSettings.test.ts

const { result } = renderHook(() => useCardSettings(true));

act(() => {
// @ts-expect-error key may be incomplete in mock

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.

P1 未使用の型エラー抑制

CI がこのテストを含めて tsc --noEmit を実行すると、showAvatar と94行目の showBio はどちらも有効な CardDisplayOptions キーであるため、@ts-expect-error が TS2578 として報告され、必須の typecheck ジョブが失敗します。

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/hooks/__tests__/useCardSettings.test.ts
Line: 84

Comment:
**未使用の型エラー抑制**

CI がこのテストを含めて `tsc --noEmit` を実行すると、`showAvatar` と94行目の `showBio` はどちらも有効な `CardDisplayOptions` キーであるため、`@ts-expect-error` が TS2578 として報告され、必須の typecheck ジョブが失敗します。

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@qodo-code-review

qodo-code-review Bot commented Aug 7, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Action required

1. Unused ts-expect-error ✓ Resolved 🐞 Bug ≡ Correctness
Description
useCardSettings.test.ts uses @ts-expect-error before calling
toggleDisplayOption("showAvatar"/"showBio"), but those arguments are valid `keyof
CardDisplayOptions`. If the call type-checks (as it should), TypeScript will fail the build due to
an unused @ts-expect-error directive.
Code

src/hooks/tests/useCardSettings.test.ts[R84-86]

+      // @ts-expect-error key may be incomplete in mock
+      result.current.toggleDisplayOption("showAvatar");
+    });
Evidence
The hook’s API explicitly accepts keyof CardDisplayOptions, and CardDisplayOptions defines
showAvatar/showBio, so these calls are type-correct; therefore @ts-expect-error becomes an
unused directive error.

src/hooks/tests/useCardSettings.test.ts[80-97]
src/hooks/useCardSettings.ts[48-50]
src/lib/types.ts[129-145]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`@ts-expect-error` is used on lines calling `toggleDisplayOption("showAvatar")` / `toggleDisplayOption("showBio")`, but these keys are valid for `keyof CardDisplayOptions`. When no TypeScript error occurs on the next line, `@ts-expect-error` itself becomes an error (unused directive), breaking CI/typecheck.

### Issue Context
- `toggleDisplayOption` is typed as `(key: keyof CardDisplayOptions) => void`.
- `CardDisplayOptions` includes `showAvatar` and `showBio` keys.

### Fix Focus Areas
- src/hooks/__tests__/useCardSettings.test.ts[83-96]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Relative import ../useCardSettings 📘 Rule violation ✧ Quality
Description
The new test imports useCardSettings via a relative path even though the target is under src/,
which violates the requirement to use the @/ alias for src imports. This reduces consistency and
can make refactors/moves harder across the src tree.
Code

src/hooks/tests/useCardSettings.test.ts[4]

+import { useCardSettings } from "../useCardSettings";
Evidence
PR Compliance ID 226103 requires all imports that resolve to modules under src/ to use the @/
alias instead of relative paths. The added test file imports useCardSettings using
../useCardSettings, which resolves to src/hooks/useCardSettings.ts and therefore violates the
rule; the repo also defines the @/* alias in tsconfig.json.

Rule 226103: Use @/ path alias for src imports in frontend code
src/hooks/tests/useCardSettings.test.ts[4-4]
tsconfig.json[21-23]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A `src/` import is using a relative specifier (`../useCardSettings`) instead of the required `@/` path alias.

## Issue Context
`tsconfig.json` defines the `@/* -> ./src/*` alias, so the test should import the hook via `@/hooks/useCardSettings`.

## Fix Focus Areas
- src/hooks/__tests__/useCardSettings.test.ts[4-4]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Unsafe mock typing casts 🐞 Bug ⚙ Maintainability
Description
The test casts mocked functions through unknown and ReturnType<typeof vi.fn>, bypassing type
checking for mock setup and return shapes. This weakens refactor safety and can hide incorrect mock
return values without compiler feedback.
Code

src/hooks/tests/useCardSettings.test.ts[R36-39]

+    (cardSettings.loadCardSettings as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
+      layout: mockDefaultLayout,
+      options: mockDefaultOptions,
+    });
Evidence
The new test file uses unsafe casts for mock setup, while other tests in the repo demonstrate
vi.mocked(...) usage for type-safe mocking.

src/hooks/tests/useCardSettings.test.ts[34-40]
src/hooks/tests/useCardSettings.test.ts[68-71]
src/hooks/tests/useCardPreview.test.ts[120-123]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
Mocked functions are typed via unsafe casts (`as unknown as ReturnType<typeof vi.fn>`). This bypasses TypeScript’s ability to validate mock configuration/return shapes.

### Issue Context
Vitest supports typed mock helpers like `vi.mocked(fn)` (or explicit `MockedFunction` typing) to avoid `unknown` casts.

### Fix Focus Areas
- src/hooks/__tests__/useCardSettings.test.ts[34-40]
- src/hooks/__tests__/useCardSettings.test.ts[68-71]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context used
✅ Compliance rules (platform): 30 rules

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

// @vitest-environment jsdom
import { renderHook, act } from "@testing-library/react";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { useCardSettings } from "../useCardSettings";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. Relative import ../usecardsettings 📘 Rule violation ✧ Quality

The new test imports useCardSettings via a relative path even though the target is under src/,
which violates the requirement to use the @/ alias for src imports. This reduces consistency and
can make refactors/moves harder across the src tree.
Agent Prompt
## Issue description
A `src/` import is using a relative specifier (`../useCardSettings`) instead of the required `@/` path alias.

## Issue Context
`tsconfig.json` defines the `@/* -> ./src/*` alias, so the test should import the hook via `@/hooks/useCardSettings`.

## Fix Focus Areas
- src/hooks/__tests__/useCardSettings.test.ts[4-4]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/hooks/__tests__/useCardSettings.test.ts Outdated
Comment on lines +36 to +39
(cardSettings.loadCardSettings as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
layout: mockDefaultLayout,
options: mockDefaultOptions,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Informational

3. Unsafe mock typing casts 🐞 Bug ⚙ Maintainability

The test casts mocked functions through unknown and ReturnType<typeof vi.fn>, bypassing type
checking for mock setup and return shapes. This weakens refactor safety and can hide incorrect mock
return values without compiler feedback.
Agent Prompt
### Issue description
Mocked functions are typed via unsafe casts (`as unknown as ReturnType<typeof vi.fn>`). This bypasses TypeScript’s ability to validate mock configuration/return shapes.

### Issue Context
Vitest supports typed mock helpers like `vi.mocked(fn)` (or explicit `MockedFunction` typing) to avoid `unknown` casts.

### Fix Focus Areas
- src/hooks/__tests__/useCardSettings.test.ts[34-40]
- src/hooks/__tests__/useCardSettings.test.ts[68-71]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

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

is0692vs commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of the older #533; both add useCardSettings hook tests in the same file.

@is0692vs is0692vs closed this Aug 9, 2026
@is0692vs
is0692vs deleted the test/use-card-settings-2593032690094081324 branch August 9, 2026 13:44
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