Skip to content

test(components): cover useResponsePanelCopy with 23 tests#66

Merged
saagpatel merged 1 commit into
masterfrom
codex/test/use-response-panel-copy
Apr 22, 2026
Merged

test(components): cover useResponsePanelCopy with 23 tests#66
saagpatel merged 1 commit into
masterfrom
codex/test/use-response-panel-copy

Conversation

@saagpatel
Copy link
Copy Markdown
Owner

Summary

  • Closed the biggest AGENTS.md DoD gap from the audit: 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.
  • Adds useResponsePanelCopy.test.ts — 23 tests across 5 describe blocks, one per handler.

Coverage

  • handleExport (4): happy path, empty-response short-circuit, error routing, saved=false branch
  • handleCopy (8): happy path, hasSections branching, 2s auto-reset (fake timers), both override-modal triggers (mode + citations), empty response, clipboard error, undefined-mode default
  • handleConfirmCopyOverride (7): happy path, null-mode audit, empty reason, whitespace reason, audit failure with submitting reset, empty response, hasSections branching
  • cancelCopyOverride (1): atomic close-and-clear
  • export-menu click-outside useEffect (3): outside closes, inside stays open, no listener when menu closed

Mocks only external boundaries per DoD — Tauri command module via vi.mock("./draftTauriCommands", ...), navigator.clipboard.writeText on the jsdom navigator.

Test plan

  • 69/69 test files, 264/264 tests (was 68/241) pass
  • TypeScript compiles clean
  • ESLint 0 new issues

🤖 Generated with Claude Code

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>
@saagpatel saagpatel merged commit 1f047f7 into master Apr 22, 2026
25 of 26 checks passed
@saagpatel saagpatel deleted the codex/test/use-response-panel-copy branch May 31, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants