Commit Graph

4 Commits

Author SHA1 Message Date
Cal Corum
345ef7af9d Create Phaser testing infrastructure - TEST-001 complete (55 tests)
Build foundation for game engine testing with comprehensive mocks and utilities:

Infrastructure Created:
- src/test/mocks/phaser.ts (33 tests)
  * MockEventEmitter - Event system with on/once/off/emit
  * MockScene - Scene lifecycle and factories
  * MockGame - Game instance with scale and scene manager
  * MockContainer - Game object container with child management
  * MockSprite - Image sprites with texture support
  * MockText - Styled text objects
  * MockGraphics - Shape drawing API
  * MockLoader - Asset loading simulation

- src/test/helpers/gameTestUtils.ts (22 tests)
  * createMockGameState() - Complete game state with players
  * createMockCardDefinition() - Card definitions with type helpers
  * createMockCardInstance() - Card instances with damage/status
  * createGameScenario() - Full game setups with cards in zones
  * setupMockScene() - Scene setup with game instance
  * Type-specific helpers: createMockPokemonCard(), createMockEnergyCard(), etc.

- src/test/README.md
  * Complete documentation with usage examples
  * Testing patterns and best practices
  * Troubleshooting guide

This infrastructure enables testing of all Phaser game objects (Board, Card, Zone,
MatchScene, etc.) without requiring WebGL/Canvas. All 1,256 tests passing.

Foundation for TEST-002 through TEST-009 (scene and state testing).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 10:25:51 -06:00
Cal Corum
63bcff8d9f Complete TEST-017, TEST-018, TEST-019 - 138 new tests
Add comprehensive test coverage for drag/drop, deck builder components, and pages:

TEST-017: Drag/drop edge cases (17 tests)
- Expand useDragDrop.spec.ts with edge case coverage
- DataTransfer fallback, touch events, invalid JSON handling
- Multiple drop targets and validation rules

TEST-018: Deck builder edge cases (75 tests)
- DeckActionButtons.spec.ts: save/cancel states, validation (19 tests)
- DeckHeader.spec.ts: name input, special chars, rapid typing (18 tests)
- DeckCardRow.spec.ts: quantity stepper, drag/drop integration (38 tests)

TEST-019: Page tests (44 tests)
- HomePage.spec.ts: auth states, navigation, accessibility (18 tests)
- CampaignPage.spec.ts: placeholder rendering, layout (8 tests)
- MatchPage.spec.ts: connection states, routing, cleanup (18 tests)

All 138 tests passing. Week 5 testing backlog complete.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 10:12:29 -06:00
Cal Corum
d03dc1ddd2 Update test coverage plan with lessons learned and progress
Documentation updates after completing quick wins 1-2:

Progress:
- Tests: 1000 → 1045 (+45, +4.5%)
- Coverage: 63% → ~65% (+2%)
- Quick wins completed: 2/3
- Hours spent: ~4 hours
- TEST-015 (CardBack): 25 tests, ~95% coverage
- TEST-020 (Socket factories): 20 tests, 100% coverage

Key Lessons Learned:
1. Phaser mocking pattern - mock classes inside vi.mock() factory
2. Disable ESLint explicit-any for complex Phaser mocks
3. Test docstrings are essential for maintainability
4. Always verify actual dimensions/constants before asserting
5. Include integration tests for full object lifecycle
6. Factory function testing strategy (structure, uniqueness, variations)
7. Avoid testing browser internals (crypto, etc)
8. Pre-commit hooks catch everything - working perfectly
9. Quick wins build momentum - start simple
10. Coverage updates automatically after tests added

Updated PROJECT_PLAN_TEST_COVERAGE.json:
- Mark TEST-015 and TEST-020 as completed
- Add progress tracking metadata
- Update current coverage estimate
2026-02-02 15:48:35 -06:00
Cal Corum
0d416028c0
Fix prize zone rendering in Mantimon TCG mode (#2)
* Fix hand card rotation direction

Cards now fan outward correctly instead of curling inward

* Update StateRenderer to require MatchScene type for type safety

- Change constructor parameter from Phaser.Scene to MatchScene
- Update scene property type to MatchScene
- Add import for MatchScene type
- Update JSDoc example to reflect type-safe constructor

* Defer Board creation to StateRenderer for correct rules config

- Make board property nullable (Board | null instead of Board?)
- Remove Board and createBoard imports (now handled by StateRenderer)
- Update setupBoard() to skip Board creation
- Add setBoard() method for StateRenderer to call
- Update clearBoard() to use null instead of undefined
- Add JSDoc explaining why Board creation is deferred

* Create Board in StateRenderer with correct layout options

- Add Board and createBoard imports
- Add board property to StateRenderer
- Create Board in render() on first call with correct rules_config
- Add debug logging for Board creation and zone creation
- Update clear() to destroy Board when clearing
- Board now created after we have rules_config from first state

* Add fatal error handling with toast notification and auto-redirect

- Add 'fatal-error' event to GameBridgeEvents type
- Import and initialize useToast in GamePage
- Listen for 'fatal-error' event from Phaser
- Show error toast that persists until redirect
- Show full-screen fatal error overlay with countdown
- Auto-redirect to /play after 3 seconds
- Update StateRenderer to emit 'fatal-error' when Board creation fails

* Gate debug logging with DEV flag

- Add DEBUG_RENDERER constant gated by import.meta.env.DEV
- Update all console.log statements in StateRenderer to only log in development
- Keep console.error and console.warn as they are (always show errors)
- Debug logs now only appear during development, not in production

* Fix code audit issues - add missing imports and improve error UX

Critical fixes:
- Add missing gameBridge import to StateRenderer (fixes runtime error in fatal error handler)
- Add missing Board type import to MatchScene (fixes TypeScript compilation error)

UX improvements:
- Replace fatal error auto-redirect with manual 'Return to Menu' button
- Add toast notification when resignation fails
- Give users unlimited time to read fatal errors before returning

Addresses issues found in frontend code audit:
- errors.missing-import (StateRenderer.ts:166)
- errors.missing-type-import (MatchScene.ts:84)
- errors.catch-only-console (GamePage.vue:145)
- architecture.missing-fatal-error-handling (GamePage.vue:261)

* Add CONTRIBUTING policy and fix pre-existing lint/test errors

- Add CONTRIBUTING.md with strict policy: never use --no-verify without approval
- Add comprehensive testing documentation (TESTING.md, VISUAL-TEST-GUIDE.md)
- Add test-prize-fix.md quick test checklist and verify-fix.sh script

Lint fixes (enables pre-commit hooks):
- Remove unused imports in 9 files
- Fix unused variables (underscore convention)
- Replace 'as any' type assertions with proper VisibleGameState types
- Add missing CARD_WIDTH_MEDIUM import in layout.spec.ts
- All ESLint errors now resolved (only acceptable warnings remain)

Test fixes (all 1000 tests now passing):
- Fix layout.spec.ts: Add missing CARD_WIDTH_MEDIUM import
- Fix PlayPage.spec.ts: Update test to use actual hardcoded UUIDs
- Fix useAuth.spec.ts: Mock API profile fetch in initialization tests
- Fix PhaserGame.spec.ts: Add scenes export to mock and update createGame call expectations

This ensures pre-commit hooks work properly going forward and prevents
bypassing TypeScript/lint checks that catch errors early.

* Add comprehensive test coverage improvement plan

- Create PROJECT_PLAN_TEST_COVERAGE.json with 25 structured tasks
- Create TEST_COVERAGE_PLAN.md with executive summary and roadmap
- Plan addresses critical gaps: game engine (0%), WebSocket (27%)
- 6-week roadmap to reach 85% coverage from current 63%
- Target: Phase 1 (weeks 1-3) - critical game engine and network tests
- Includes quick wins, production blockers, and success metrics

Based on coverage analysis showing:
- Strong: Composables (84%), Components (90%), Stores (88%)
- Critical gaps: Phaser game engine (~5,500 untested lines)
- High priority: WebSocket/multiplayer reliability

See TEST_COVERAGE_PLAN.md for overview and week-by-week breakdown.

* Add coverage tooling and ignore coverage directory

- Add @vitest/coverage-v8 package for coverage analysis
- Add coverage/ directory to .gitignore
- Used during test coverage analysis for PROJECT_PLAN_TEST_COVERAGE.json
2026-02-02 15:30:27 -06:00