testsAndMisc/bucket_catch/packages/frontend/src/test/canvasMock.ts
Krzysztof kuhy Rudnicki 5a9296d8aa Add bucket_catch: osu!catch browser game with 100% frontend test coverage
Frontend (React 19 + Vite 6 + TypeScript strict):
- DropZone, ModeSelect, GameCanvas, PuzzleCanvas, ScoreScreen, PuzzleResult
- File-drop game with AABB collision; download (JSZip) and upload (NestJS) modes
- Puzzle mode: NxN image slice via OffscreenCanvas; Union-Find spatial clustering
  guarantees 100% catch rate is always achievable regardless of piece speeds
- ESLint typescript-eslint strict-type-checked (zero errors)
- 145 Vitest tests; 100% coverage on statements/branches/functions/lines

Backend (NestJS 11):
- POST /files/upload (multer disk storage) and GET /health

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YZ8QTmreFcaqrsvVb38Grd
2026-06-27 12:21:35 +02:00

31 lines
789 B
TypeScript

import { vi } from "vitest";
export const mockGradient = { addColorStop: vi.fn() };
export const mockCtx = {
clearRect: vi.fn(),
fillRect: vi.fn(),
strokeRect: vi.fn(),
drawImage: vi.fn(),
fillText: vi.fn(),
measureText: vi.fn(() => ({ width: 0 })),
save: vi.fn(),
restore: vi.fn(),
beginPath: vi.fn(),
arc: vi.fn(),
fill: vi.fn(),
stroke: vi.fn(),
moveTo: vi.fn(),
lineTo: vi.fn(),
roundRect: vi.fn(),
createLinearGradient: vi.fn(() => mockGradient),
fillStyle: "" as string | CanvasGradient | CanvasPattern,
strokeStyle: "" as string | CanvasGradient | CanvasPattern,
lineWidth: 1,
lineJoin: "miter" as CanvasLineJoin,
font: "",
textAlign: "start" as CanvasTextAlign,
textBaseline: "alphabetic" as CanvasTextBaseline,
globalAlpha: 1,
};