Skip to content

Add testing infrastructure and 166 tests#292

Merged
icaroharry merged 7 commits into
mainfrom
feature/testing-infrastructure
Mar 23, 2026
Merged

Add testing infrastructure and 166 tests#292
icaroharry merged 7 commits into
mainfrom
feature/testing-infrastructure

Conversation

@icaroharry
Copy link
Copy Markdown
Contributor

Summary

  • Set up Vitest + Testing Library with separate config from vite.config.ts (avoids reactRouter plugin issues in test env), jsdom, jest-dom matchers, matchMedia mock for Radix UI
  • 166 tests across 32 test files covering utilities, hooks, UI components, feature components, and route integration
  • CI workflow via GitHub Actions that runs tests on PRs and pushes to main
  • Coverage: 7.4% statements, 47.7% branches, 32.9% functions (from zero)

What's tested

Layer Files Tests
Utilities cn, classNames, formatDate, formatName, numbers, stringUtils, workshopUtils, pathUtils 55
Hooks useMediaQuery, usePrefersReducedMotion 5
UI Components Button, Chip, Skeleton, AlertBanner, ProBadge, UserAvatar, PriceCard, ChallengeCard 60
Feature Components Error500, NotFound, Input, LoadingButton, WhatsApp, LinkToLogin, RankingBadges, Wave, BackgroundBlur 36
Route Integration Blog, BlogPostCard, Ranking, Checkout success, Agenda 22

Key patterns established

  • renderWithRouter helper using createRoutesStub for components that need router context
  • vi.mock() for server modules (.server.ts) to prevent env var validation at import time
  • vi.mock() for useOutletContext when components depend on user context
  • Async route testing with findByText for stubbed loaders
  • Tooltip mock for components using Radix UI tooltip provider

Test plan

  • npm run test:run — 166 tests pass
  • npm run test:coverage — coverage report generates
  • Pre-commit hooks pass (eslint + prettier)

🤖 Generated with Claude Code

Install vitest, @testing-library/react, @testing-library/jest-dom,
@testing-library/user-event, jsdom, and @vitest/coverage-v8.

Create vitest.config.ts (separate from vite.config.ts to avoid
reactRouter plugin issues), setup file with jest-dom matchers and
matchMedia mock, TypeScript globals reference, test helper for
rendering components with router context via createRoutesStub,
and npm scripts for test, test:run, and test:coverage.
Test cn, classNames, formatDate, formatName, generateRandomInt,
toTitleCase, workshop status utils (hasHappened, isUpcoming, isNew),
and path utils (getOgGeneratorUrl, setActiveClassForPath).
Test useMediaQuery and usePrefersReducedMotion hooks with
mocked matchMedia responses and state assertions.
Test Chip, Button (variants, sizes, asChild, ref forwarding),
Skeleton, AlertBanner (5 variant types), ProBadge, UserAvatar
(pro/team badges, fallback URLs), PriceCard compound component
(Title, Pricing, Features, Coupon interaction, Divider), and
ChallengeCard (links, chips, avatar count, soon status).
Test Error500, NotFound, form Input, LoadingButton (idle/loading/
submitting/success states), WhatsApp button, LinkToLoginWithRedirect
(redirect logic, password-reset edge case), ranking badge SVGs,
Wave (top/bottom variants), and BackgroundBlur.
Test Blog route (stubbed loader with async rendering), BlogPostCard
(Link href, router context), Ranking (loader data, filter links),
Codando com IA checkout (paid/pending/denied/error states, boleto
flow), and Agenda (events list, type filters, empty state).
GitHub Actions workflow that runs on pull requests and pushes to main.
Installs dependencies, runs the test suite, and generates coverage.
@icaroharry icaroharry merged commit b249773 into main Mar 23, 2026
1 check passed
@icaroharry icaroharry deleted the feature/testing-infrastructure branch March 23, 2026 16:24
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