Skip to content

feat: Add comprehensive testing infrastructure (Phase 1)#48

Open
moonejon wants to merge 2 commits into
mainfrom
moonejon/test-suite-planning
Open

feat: Add comprehensive testing infrastructure (Phase 1)#48
moonejon wants to merge 2 commits into
mainfrom
moonejon/test-suite-planning

Conversation

@moonejon

Copy link
Copy Markdown
Owner

Summary

This PR establishes a robust testing infrastructure following Kent C. Dodds' Testing Trophy approach, prioritizing integration tests over unit tests and focusing on testing user behavior rather than implementation details.

What's Included

Test Configuration:

  • Vitest configured for Next.js 15 + React 19
  • Testing Library + userEvent for component testing
  • MSW (Mock Service Worker) for API mocking
  • Coverage reporting with v8 provider

Test Helpers & Factories:

  • Database utilities: resetDatabase(), seedTestUser(), withTransaction()
  • User factory with Clerk ID generation
  • Book factory with valid ISBN-10/ISBN-13 checksum generation
  • Reading list factory with junction table management

Mock Utilities:

  • Clerk auth mocks (server & client): mockClerkUser(), mockUnauthenticated()
  • ISBNdb API handlers with success/error scenarios
  • Aggregated MSW handlers for different test scenarios

Unit Tests (101 tests):

  • Validation: ISBN-10, ISBN-13, URL, date, string sanitization (64 tests)
  • Permissions: Owner access, visibility checks, authorization (37 tests)

Component Fixes:

  • CreateReadingListModal: Changed default visibility to PUBLIC
  • Added proper ARIA labels and accessibility attributes
  • Improved form validation UX (show errors on submit vs disabled button)

Test Results

Test Files  3 passed (3)
Tests       137 passed (137)
Duration    3.05s

Test Commands

npm test              # Watch mode
npm run test:run      # Single run (CI)
npm run test:coverage # With coverage report

Documentation

  • docs/TESTING_STRATEGY.md - Comprehensive testing philosophy and approach
  • test/README.md - Test infrastructure guide
  • test/QUICK_START.md - Quick reference for writing tests

Test plan

  • All 137 tests passing
  • Vitest configuration works with Next.js 15
  • Path aliases (@/) resolve correctly
  • MSW intercepts API calls properly
  • Clerk mocks work for server and client components
  • Factories generate valid test data (including ISBN checksums)

🤖 Generated with Claude Code

Implement testing foundation following Kent C. Dodds' Testing Trophy approach:

- Configure Vitest for Next.js 15 + React 19 with path aliases
- Add Testing Library, MSW for component and API testing
- Create database helpers (reset, seed, transaction utilities)
- Create test factories for User, Book, ReadingList with valid ISBN generation
- Add Clerk authentication mocks (server and client)
- Add ISBNdb API mocks with error scenarios
- Write 101 unit tests for validation and permissions
- Fix CreateReadingListModal for accessibility (PUBLIC default, ARIA labels)

Test Results: 137 tests passing across 3 test suites

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 25, 2025

Copy link
Copy Markdown

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

Project Deployment Preview Comments Updated (UTC)
penumbra Error Error Nov 25, 2025 7:13pm

Server Action Integration Tests:
- books.test.ts: 48 tests for importBooks, fetchBooks, updateBook, etc.
- reading-lists.test.ts: 34 tests for CRUD operations and book management
- favorites.test.ts: 45 tests for FAVORITES_ALL and FAVORITES_YEAR

Component Integration Tests:
- TextSearch.test.tsx: 21 tests for library title search
- ISBNSearch.test.tsx: 31 tests for ISBN search and import flow
- AutoCompleteSearch.test.tsx: 42 tests for author/subject filters

Component Fixes:
- textSearch.tsx: Added screen reader accessible label
- search.tsx: Fixed validation and case-sensitive error matching

Test Results: 189 tests passing (excludes DB-dependent tests)

Note: Server action tests require PostgreSQL test database to run.
See test/README.md for database setup instructions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant