Skip to content

test: add unit tests for use-page-tree-actions hook (#1126)#1128

Merged
sw-factory-automations merged 1 commit into
mainfrom
feat/1126-test-use-page-tree-actions
May 17, 2026
Merged

test: add unit tests for use-page-tree-actions hook (#1126)#1128
sw-factory-automations merged 1 commit into
mainfrom
feat/1126-test-use-page-tree-actions

Conversation

@sw-factory-automations

Copy link
Copy Markdown
Collaborator

Closes #1126

What

Adds 35 unit tests for the usePageTreeActions hook in src/components/sidebar/use-page-tree-actions.test.ts. This hook handles all sidebar page operations and had zero test coverage despite being the most complex hook in the sidebar domain.

How

Tests follow the established mocking pattern from use-database-rows.test.ts:

  • Supabase lazy client mocked with chainable query builder
  • computeSwapPositions, computeNest, computeUnnest, getDescendantIds, getNextSiblingPosition mocked to isolate mutation logic from already-tested tree computation
  • Toast, router, Sentry capture, and analytics mocked and verified

Coverage by action

Action Tests Covers
handleCreate 6 Success + navigation, parent expansion, FK violation, insufficient privilege, unknown error → Sentry, null workspace guard
handleCreateDatabase 4 Success + navigation + refresh, error → Sentry, insufficient privilege suppression, null workspace guard
handleDuplicate 4 Regular page duplication, database page via duplicateDatabase, error handling for both paths
handleDelete 5 Soft delete via RPC, descendant cleanup, navigation redirect when deleting current page, no redirect for other pages, error handling
handleMoveUp 3 Position swap, no-op at boundary, DB error → Sentry
handleMoveDown 2 Position swap, no-op at boundary
handleNest 3 Parent/position update + expanded state, no-op when first sibling, DB error → Sentry
handleUnnest 3 Parent/position update + sibling shifts, no-op when no parent, DB error → Sentry
handleToggleFavorite 5 Add favorite, remove favorite (optimistic), remove error → rollback, add error → Sentry, null workspace guard

Testing

  • pnpm lint — 0 errors
  • pnpm typecheck — passes
  • pnpm test — 1953 tests pass (144 files)
  • Updated .agents/quality.md with new test counts

@vercel

vercel Bot commented May 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
memo Ready Ready Preview, Comment May 17, 2026 0:14am

Request Review

@sw-factory-automations sw-factory-automations merged commit c4a971e into main May 17, 2026
9 checks passed
@sw-factory-automations sw-factory-automations deleted the feat/1126-test-use-page-tree-actions branch May 17, 2026 12:33
@sw-factory-automations

Copy link
Copy Markdown
Collaborator Author

✅ UI verification skipped — this PR contains only test files and documentation updates. No UI components, pages, or layouts were changed.

@sw-factory-automations

Copy link
Copy Markdown
Collaborator Author

✅ Post-merge verification skipped — test: PR does not affect the live app.

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.

test: add unit tests for use-page-tree-actions hook

1 participant