import { describe, expect, test } from "bun:test"; import { zoomPlugin } from "../plugins/zoomPlugin"; import { createKeyboardEvent, createTestCanvas, createWheelEvent } from "./canvasTestUtils"; describe("zoom plugin", () => { test("scales with modifier + wheel", () => { const harness = createTestCanvas( (canvas) => canvas.addPlugins(zoomPlugin()), { data: { size: { width: 1000, height: 1000 }, origin: { x: 0, y: 0 }, zoom: 1, }, } ); harness.handlers.onWheel?.( createWheelEvent({ deltaY: -10, metaKey: true }) ); expect(harness.getData().zoom).toBeCloseTo(1.2); expect(harness.getData().origin).toEqual({ x: -100, y: -100 }); }); test("supports keyboard shortcuts and preventDefault option", () => { const harness = createTestCanvas((canvas) => canvas.addPlugins(zoomPlugin({ onWheelShouldPreventDefault: true })), { data: { size: { width: 1000, height: 1000 }, origin: { x: 0, y: 0 }, zoom: 1, }, }); const wheelEvent = createWheelEvent({ deltaY: -10, metaKey: true }); harness.handlers.onWheel?.(wheelEvent); expect(wheelEvent.defaultPrevented).toBe(true); harness.handlers.onKeyDown?.(createKeyboardEvent("=", { metaKey: true })); expect(harness.getData().zoom).toBeGreaterThan(1); harness.handlers.onKeyDown?.(createKeyboardEvent("-", { metaKey: true })); harness.handlers.onKeyDown?.(createKeyboardEvent("0", { metaKey: true })); expect(harness.getData().zoom).toBe(1); }); });