🧪 test: cover fallback copy DOM operations in useCopyToClipboard - #517
🧪 test: cover fallback copy DOM operations in useCopyToClipboard#517is0692vs wants to merge 1 commit into
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
|
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Warning Review limit reached
Next review available in: 55 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. 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 |
📄 Knowledge reviewDosu skipped reviewing this PR because your organization has used its |
PR Summary by QodoTest fallback DOM copy path in useCopyToClipboard
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Code Review by Qodo
Context used✅ Compliance rules (platform):
30 rules 1. Select assertion too broad
|
| const selectSpy = vi.spyOn(HTMLTextAreaElement.prototype, "select"); | ||
|
|
||
| const { result } = renderHook(() => useCopyToClipboard()); | ||
|
|
||
| await act(async () => { | ||
| await result.current.copyToClipboard("fallback text"); | ||
| }); | ||
|
|
||
| expect(createElementSpy).toHaveBeenCalledWith("textarea"); | ||
| expect(appendChildSpy).toHaveBeenCalled(); | ||
| expect(selectSpy).toHaveBeenCalled(); | ||
| expect(document.execCommand).toHaveBeenCalledWith("copy"); |
There was a problem hiding this comment.
1. Select assertion too broad 🐞 Bug ⚙ Maintainability
The new test only asserts that HTMLTextAreaElement.prototype.select was called, but does not verify it was called on the textarea created by the fallback path, so it could pass due to an unrelated textarea selecting itself. This weakens the intended regression coverage for the specific fallback textarea selection step.
Agent Prompt
## Issue description
The test spies on `HTMLTextAreaElement.prototype.select` and asserts only `toHaveBeenCalled()`. That does not prove the fallback code called `select()` on the specific textarea created by `document.createElement('textarea')`, so the test can pass even if the wrong element is selected.
## Issue Context
`useCopyToClipboard` creates a textarea and calls `textArea.select()` before `document.execCommand("copy")`.
## Fix Focus Areas
- src/hooks/__tests__/useCopyToClipboard.test.ts[258-279]
## Suggested fix
After extracting `textarea` from `createElementSpy.mock.results`, assert the receiver of the `select()` call matches it, e.g.:
- `expect(selectSpy.mock.instances).toContain(textarea);` (or `mock.contexts` if preferred)
- Optionally also assert call count: `expect(selectSpy).toHaveBeenCalledTimes(1)` to reduce noise from unrelated calls.
This keeps the prototype spy approach but makes the assertion specific to the created textarea.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
🎯 What: The testing gap addressed
This PR addresses missing test coverage for the fallback copy path in the
useCopyToClipboardhook. Specifically, it ensures that when the primarynavigator.clipboard.writeTextAPI fails and the hook falls back to manipulating the DOM (creating a textarea, appending it to the body, and usingdocument.execCommand), these DOM operations are correctly executed and properly cleaned up.📊 Coverage: What scenarios are now tested
textareais created.textareais appended to the document body..select()method is called on thetextarea.document.execCommand("copy")is successfully executed.textareais safely removed from the document body in thefinallyblock to prevent DOM leakage.✨ Result: The improvement in test coverage
The codebase now includes explicit assertions on the fallback code path, providing a safety net to prevent accidental regressions related to legacy browser support for copy-to-clipboard functionality. Tests pass and test quality is strictly improved.
PR created automatically by Jules for task 17424069591778516712 started by @is0692vs
Greptile Summary
useCopyToClipboardの Clipboard API 失敗時に使用される DOM フォールバック処理のテスト範囲を拡充しています。execCommand("copy")の呼び出しを検証Confidence Score: 5/5
この PR はテストのみを拡充しており、安全にマージできると判断します。
本番コードの動作は変更されておらず、追加テストは textarea の生成からコピー、削除、状態リセットまで既存のフォールバック経路を一貫して検証しています。
Important Files Changed
Reviews (1): Last reviewed commit: "test: add missing tests for fallback cop..." | Re-trigger Greptile
Context used: