test(components): cover useResponsePanelCopy with 23 tests#66
Merged
Conversation
The 160-line useResponsePanelCopy hook exposes 8 return-surface members
(copied, showCopyOverride, copyOverrideReason, copyOverrideSubmitting,
showExportMenu, exportMenuRef, plus 4 handlers and 3 setters) and
invokes the Tauri command boundary (auditResponseCopyOverride,
exportDraft) plus navigator.clipboard — yet had zero tests. This was
the most-cited AGENTS.md DoD gap in the audit.
Adds useResponsePanelCopy.test.ts with 23 tests grouped by handler:
handleExport (4)
- happy path: exportDraft payload + success toast + menu closes
- empty response short-circuits before calling the command
- exception path: onShowError fires, menu still closes
- saved=false: no success toast, no error, command was called
handleCopy (8)
- happy path: writes navigator.clipboard with the raw response
- uses parsed.output when hasSections is true
- copied flag resets to false after the 2s timeout (fake timers)
- opens override modal when confidence mode is not 'answer'
- opens override modal when there are zero citations
- empty response short-circuits
- clipboard rejection routes to onShowError without flipping copied
- undefined confidenceMode defaults to 'answer' for gating
handleConfirmCopyOverride (7)
- happy path: audits, writes clipboard, success toast, modal closes,
reason cleared
- undefined confidenceMode is sent to audit as null
- empty reason: onShowError, no audit, no clipboard
- whitespace-only reason: same as empty (trim applied)
- audit failure: error toast, submitting flag resets in finally
- empty response short-circuits
- uses parsed.output when hasSections is true
cancelCopyOverride (1)
- closes modal and clears reason atomically
Export-menu click-outside useEffect (3)
- outside mousedown closes the menu via the ref contract
- inside mousedown leaves the menu open
- no mousedown listener is registered while the menu is closed
Mocks only external boundaries: the Tauri command module is mocked via
vi.mock("./draftTauriCommands", ...) with hoisted mock fns;
navigator.clipboard.writeText is installed on the jsdom navigator.
Total: 69 test files / 264 tests (was 68 / 241 on master). Typecheck
and eslint clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/components/Draft/useResponsePanelCopy.ts(160 LOC, 8 public return-surface members, two Tauri command invocations, clipboard side effects, click-outside listener) had zero tests.useResponsePanelCopy.test.ts— 23 tests across 5describeblocks, one per handler.Coverage
handleExport(4): happy path, empty-response short-circuit, error routing,saved=falsebranchhandleCopy(8): happy path,hasSectionsbranching, 2s auto-reset (fake timers), both override-modal triggers (mode + citations), empty response, clipboard error, undefined-mode defaulthandleConfirmCopyOverride(7): happy path, null-mode audit, empty reason, whitespace reason, audit failure with submitting reset, empty response,hasSectionsbranchingcancelCopyOverride(1): atomic close-and-clearuseEffect(3): outside closes, inside stays open, no listener when menu closedMocks only external boundaries per DoD — Tauri command module via
vi.mock("./draftTauriCommands", ...),navigator.clipboard.writeTexton the jsdom navigator.Test plan
🤖 Generated with Claude Code