Skip to content

feat(testing): set up comprehensive testing infrastructure with Vitest and Playwright - #44

Open
akordavid373 wants to merge 5 commits into
stellar-network-builders:mainfrom
akordavid373:feat/testing-infrastructure
Open

feat(testing): set up comprehensive testing infrastructure with Vitest and Playwright#44
akordavid373 wants to merge 5 commits into
stellar-network-builders:mainfrom
akordavid373:feat/testing-infrastructure

Conversation

@akordavid373

Copy link
Copy Markdown

Summary

Closes #22

This PR sets up a comprehensive testing infrastructure for the Lumina frontend application as described in issue #22.

Testing Infrastructure

  • vitest.config.ts — Vitest with jsdom environment, path aliases, and coverage thresholds (50%)
  • playwright.config.ts — Playwright E2E configuration with Chromium, Firefox, and Mobile Chrome projects
  • src/test/setup.ts — Global browser API mocks (matchMedia, ResizeObserver, IntersectionObserver, crypto, Freighter wallet, scrollTo, rAF)
  • src/test/utils.tsx — Custom render utility wrapping components in NextIntlClientProvider
  • src/test/mocks/ — MSW server + handlers for all API endpoints (health, auth, vesting, dashboard) and error scenarios

Test Fixtures

  • wallet.ts — 4 wallet states (connected, disconnected, wrong network, not installed) + test accounts
  • vesting.ts — 4 vesting schedule states (active, pre-cliff, completed, revoked) + summary
  • soroban.ts — 7 Soroban RPC response mocks (success, failed, pending, simulate, events, empty)

Unit Tests — 95 tests across 9 files, all passing ✅

File Tests Coverage
security.test.ts 22 sanitizeAddress, validateRedirectUrl, stripSensitiveFromLogs, getNonce
performance.test.ts 12 measureRenderTime, debounceSearch, measureAsyncOperation, withPerformanceMark
format.test.ts 22 formatDate, formatNumber, formatTokenAmount, formatCurrency, formatRelativeTime
a11y.test.ts 13 announce, focusTrap, useSkipLink, useReducedMotion, useKeyboardNavigation
virtual-scroll.test.ts 5 useVirtualScroll
i18n-types.test.ts 6 isTranslationKey
useAnnounce.test.ts 4 useAnnounce hook
useFocusManagement.test.ts 5 useFocusManagement hook
ui-components.test.tsx 6 AriaLiveRegion, VisuallyHidden

E2E Tests

  • e2e/homepage.spec.ts — Homepage rendering, skip-to-content, locale switching, accessibility landmarks

Bug Fixes

  • Fixed isTranslationKey to verify resolved leaf values are strings, not objects
  • Fixed validateRedirectUrl to reject arbitrary non-URL strings

CI Pipeline

  • Updated .github/workflows/test.yml with typechecktest --coveragebuilde2e jobs
  • Added npm scripts: typecheck, test, test:ui, test:watch, test:coverage, test:e2e, test:e2e:ui

Verification

  • ✅ Lint: 0 errors, 0 warnings
  • ✅ TypeScript: no errors
  • ✅ 95/95 tests pass
  • ✅ Build succeeds
  • ✅ Coverage thresholds met

…t and Playwright

- Add vitest.config.ts with jsdom environment, path aliases, and coverage thresholds
- Add playwright.config.ts for E2E tests (chromium, firefox, mobile)
- Create src/test/setup.ts with global browser API mocks and Freighter wallet mock
- Create src/test/utils.tsx with custom render wrapped in NextIntlClientProvider
- Create MSW handlers and server for API endpoint mocking
- Add test fixtures for wallet states, vesting schedules, and Soroban RPC responses
- Add 95 unit tests across 9 files covering all lib/ functions and hooks
- Add component tests for AriaLiveRegion and VisuallyHidden
- Add E2E test spec for homepage, locale switching, and accessibility
- Update CI workflow (test.yml) with typecheck, test, coverage, and e2e jobs
- Add npm scripts: test, test:ui, test:watch, test:coverage, test:e2e
- Fix isTranslationKey to verify resolved leaf values are strings
- Fix validateRedirectUrl to reject arbitrary non-URL strings

Closes stellar-network-builders#22
- Add e2e/wallet-connect.spec.ts with Freighter API mocking via addInitScript
  - Tests disconnected, connected, and network mismatch states
  - Forward-looking skipped tests for wallet lifecycle UX (when UI is built)
  - Page error tracking to catch unhandled exceptions during tests
- Add e2e/dashboard-navigation.spec.ts with comprehensive navigation tests
  - Locale routing for all 4 languages with metadata validation
  - Responsive layout tests (mobile, tablet, desktop)
  - External link behavior validation
  - Error resilience (unknown locale 404, rapid locale switching)
  - All selectors use getByRole/getByLabel/getByText best practices
- Refactor e2e/homepage.spec.ts to remove duplication, use getByRole
- Add coverage/, test-results/, playwright-report/ to ESLint ignores

Related: stellar-network-builders#22
…e, and LocaleSwitcher

- Add SkipLink.test.tsx: tests anchor rendering, className, click/keydown handlers
- Add WebVitals.test.tsx: tests hook invocation on mount, renders null
- Add AxeCore.test.tsx: tests null rendering, production early-return, dev dynamic import
- Add LocaleSwitcher.test.tsx: tests select rendering, all 4 locales, announcePolite + router.replace on change, enabled state
- Add requestIdleCallback mock to test setup for @axe-core/react compatibility
- All tests use vi.mock with vi.hoisted for clean module-level mocking

Related: stellar-network-builders#22
- Merge package.json: combine Storybook/Radix deps from main with testing infra deps
- Merge vitest.config.ts: split into 'unit' (jsdom) and 'storybook' (browser) projects
- Pull .storybook/main.ts and .storybook/preview.tsx from main
- Add global @axe-core/react mock in setup.ts to prevent React.createElement error
- Move path alias and exclude into per-project config for correct vitest resolution

All 114 tests pass, typecheck clean, lint clean, build succeeds.
@Husten150

Copy link
Copy Markdown
Contributor

Summary

Closes #22

This PR sets up a comprehensive testing infrastructure for the Lumina frontend application as described in issue #22.

Testing Infrastructure

* **`vitest.config.ts`** — Vitest with jsdom environment, path aliases, and coverage thresholds (50%)

* **`playwright.config.ts`** — Playwright E2E configuration with Chromium, Firefox, and Mobile Chrome projects

* **`src/test/setup.ts`** — Global browser API mocks (matchMedia, ResizeObserver, IntersectionObserver, crypto, Freighter wallet, scrollTo, rAF)

* **`src/test/utils.tsx`** — Custom render utility wrapping components in `NextIntlClientProvider`

* **`src/test/mocks/`** — MSW server + handlers for all API endpoints (health, auth, vesting, dashboard) and error scenarios

Test Fixtures

* `wallet.ts` — 4 wallet states (connected, disconnected, wrong network, not installed) + test accounts

* `vesting.ts` — 4 vesting schedule states (active, pre-cliff, completed, revoked) + summary

* `soroban.ts` — 7 Soroban RPC response mocks (success, failed, pending, simulate, events, empty)

Unit Tests — 95 tests across 9 files, all passing ✅

File Tests Coverage
security.test.ts 22 sanitizeAddress, validateRedirectUrl, stripSensitiveFromLogs, getNonce
performance.test.ts 12 measureRenderTime, debounceSearch, measureAsyncOperation, withPerformanceMark
format.test.ts 22 formatDate, formatNumber, formatTokenAmount, formatCurrency, formatRelativeTime
a11y.test.ts 13 announce, focusTrap, useSkipLink, useReducedMotion, useKeyboardNavigation
virtual-scroll.test.ts 5 useVirtualScroll
i18n-types.test.ts 6 isTranslationKey
useAnnounce.test.ts 4 useAnnounce hook
useFocusManagement.test.ts 5 useFocusManagement hook
ui-components.test.tsx 6 AriaLiveRegion, VisuallyHidden

E2E Tests

* `e2e/homepage.spec.ts` — Homepage rendering, skip-to-content, locale switching, accessibility landmarks

Bug Fixes

* Fixed `isTranslationKey` to verify resolved leaf values are strings, not objects

* Fixed `validateRedirectUrl` to reject arbitrary non-URL strings

CI Pipeline

* Updated `.github/workflows/test.yml` with `typecheck` → `test --coverage` → `build` → `e2e` jobs

* Added npm scripts: `typecheck`, `test`, `test:ui`, `test:watch`, `test:coverage`, `test:e2e`, `test:e2e:ui`

Verification

* ✅ Lint: 0 errors, 0 warnings

* ✅ TypeScript: no errors

* ✅ 95/95 tests pass

* ✅ Build succeeds

* ✅ Coverage thresholds met

sorry it did not pass pipeline

@Husten150

Copy link
Copy Markdown
Contributor

did not pass pipeline and resolve conflict

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.

feat(testing): Set up comprehensive testing infrastructure with Vitest for unit tests and Playwright for E2E tests

2 participants