Files
web-cad/frontend/tests/helpers/mockAdapter.ts
T

70 lines
2.2 KiB
TypeScript
Raw Normal View History

2026-08-26 21:04:17 +02:00
/**
* MockAdapter Headless-Doppel der RenderEngine für Workflow-Tests.
* Zeichnet nichts; protokolliert alle Aufrufe in `calls` (Reihenfolge getreu).
*
* Methodenumfang = genau das, was InteractionEngine derzeit an RenderEngine
* ruft (verifiziert in Task A0): hitTest, render, setActiveSnapPoint,
* setOptions, setPreviewElement, setSnapPoints.
* Wird in C1 (RenderAdapter-Interface) um die vollen Adapter-Methoden erweitert.
*/
import type { CADElement } from '../../src/types/cad.types';
export interface RecordedCall {
method: string;
args: unknown[];
}
export class MockRenderEngine {
/** Alle Aufrufe in Reihenfolge. */
readonly calls: RecordedCall[] = [];
/** Von Tests konfigurierbare hitTest-Rückgabe. */
nextHitTestResult: CADElement | null = null;
// ── Von InteractionEngine genutzte Fläche ────────────────
hitTest(x: number, y: number, tolerance?: number): CADElement | null {
this.calls.push({ method: 'hitTest', args: [x, y, tolerance] });
return this.nextHitTestResult;
}
render(): void {
this.calls.push({ method: 'render', args: [] });
}
setActiveSnapPoint(pt: unknown): void {
this.calls.push({ method: 'setActiveSnapPoint', args: [pt] });
}
setOptions(opts: Record<string, unknown>): void {
this.calls.push({ method: 'setOptions', args: [opts] });
}
setPreviewElement(el: CADElement | null): void {
this.calls.push({ method: 'setPreviewElement', args: [el] });
}
setSnapPoints(pts: unknown[]): void {
this.calls.push({ method: 'setSnapPoints', args: [pts] });
}
// ── Test-Helfer ──────────────────────────────────────────
/** Anzahl Aufrufe einer Methode. */
countCalls(method: string): number {
return this.calls.filter((c) => c.method === method).length;
}
/** Letzte aufgezeichnete Argumentliste einer Methode (oder undefined). */
lastArgsOf(method: string): unknown[] | undefined {
const found = this.calls.filter((c) => c.method === method);
return found.length ? found[found.length - 1].args : undefined;
}
/** Protokoll leeren. */
reset(): void {
this.calls.length = 0;
this.nextHitTestResult = null;
}
}