Ilya Ashikhmin e70ec822c9 test: cover domain, engine and controller scenarios; add headless mode
Add Vitest suites for relations, properties, catalogue, symbols, edge
styles, flow solver, settings, JointJS shapes/serialization and the
controller lifecycle (add/connect/edit/delete, undo-redo, copy-paste,
flow, save-load). Introduce headless DiagramController (Paper-less) so the
controller is testable outside a browser, and fix the flow direction sign.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-02 23:31:12 +02:00

24 lines
1.1 KiB
TypeScript

// jsdom lacks a few SVG/DOM APIs JointJS pokes at during construction.
import { vi } from 'vitest'
if (!('performance' in globalThis)) {
// @ts-expect-error minimal shim
globalThis.performance = { now: () => 0 }
}
if (!globalThis.requestAnimationFrame) {
globalThis.requestAnimationFrame = ((cb: FrameRequestCallback) =>
setTimeout(() => cb(0), 16) as unknown as number) as typeof requestAnimationFrame
globalThis.cancelAnimationFrame = ((id: number) => clearTimeout(id)) as typeof cancelAnimationFrame
}
// jsdom's SVGElement.getBBox / getScreenCTM are stubs; provide safe values.
if (typeof SVGElement !== 'undefined') {
// @ts-expect-error patching prototype for tests
SVGElement.prototype.getBBox ||= () => ({ x: 0, y: 0, width: 60, height: 60 })
// @ts-expect-error patching prototype for tests
SVGElement.prototype.getScreenCTM ||= () => ({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, inverse: () => ({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }) })
}
vi.stubGlobal('matchMedia', vi.fn().mockReturnValue({ matches: false, addListener: vi.fn(), removeListener: vi.fn() }))