🧪 Add missing tests for useCardSettings hook - #539
Conversation
Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
Warning Review limit reached
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 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 configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
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. Comment |
PR Summary by QodoAdd Vitest coverage for useCardSettings hook behaviors
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
| const { result } = renderHook(() => useCardSettings(true)); | ||
|
|
||
| act(() => { | ||
| // @ts-expect-error key may be incomplete in mock |
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Code Review by Qodo
1.
|
| // @vitest-environment jsdom | ||
| import { renderHook, act } from "@testing-library/react"; | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
| import { useCardSettings } from "../useCardSettings"; |
There was a problem hiding this comment.
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
| (cardSettings.loadCardSettings as unknown as ReturnType<typeof vi.fn>).mockReturnValue({ | ||
| layout: mockDefaultLayout, | ||
| options: mockDefaultOptions, | ||
| }); |
There was a problem hiding this comment.
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>
|
Closing as a duplicate of the older #533; both add useCardSettings hook tests in the same file. |
🎯 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, andisBlockVisible.✨ 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 の型チェックが失敗します。loadCardSettingsとsaveCardSettingsをモックして hydration と保存を検証Confidence Score: 4/5
不要な
@ts-expect-errorによって必須の型チェックが失敗するため、マージ前に削除する必要があります。showAvatarとshowBioは正規のCardDisplayOptionsキーなので抑制対象の型エラーがなく、CI のtsc --noEmitが未使用ディレクティブをエラーとして報告します。Files Needing Attention: src/hooks/tests/useCardSettings.test.ts
Important Files Changed
@ts-expect-errorが CI の型チェックを壊す。Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "test: add tests for useCardSettings hook" | Re-trigger Greptile
Context used: