task(A0): logger and test helpers
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* InMemoryDoc-Helper – Netzwerkfreie YjsDocument-Fabrik für Tests.
|
||||
*
|
||||
* YjsDocument läuft bereits komplett In-Memory (Y.Doc ohne Provider);
|
||||
* dieser Wrapper bietet bequemes Seeding und Reset für isolierte Tests.
|
||||
* Genutzt ab A3 (Tool-Workflow-Tests) und A2b (CADDocument-Tests).
|
||||
*/
|
||||
import { YjsDocument } from '../../src/crdt/YjsDocument';
|
||||
import type { CADElement } from '../../src/types/cad.types';
|
||||
|
||||
export interface SeededDoc {
|
||||
ydoc: YjsDocument;
|
||||
/** Fügt Elemente in EINER Transaktion hinzu (1 Undo-Schritt). */
|
||||
addAll(elements: CADElement[]): void;
|
||||
/** Entfernt alle Elemente/Layer-Inhalte (Dokument bleibt verwendbar). */
|
||||
clear(): void;
|
||||
}
|
||||
|
||||
/** Erzeugt ein frisches, leeres Test-Dokument. */
|
||||
export function createInMemoryDoc(): SeededDoc {
|
||||
const ydoc = new YjsDocument();
|
||||
return {
|
||||
ydoc,
|
||||
addAll(elements) {
|
||||
ydoc.doc.transact(() => {
|
||||
for (const el of elements) ydoc.data.elements.set(el.id, el);
|
||||
});
|
||||
},
|
||||
clear() {
|
||||
ydoc.doc.transact(() => {
|
||||
for (const id of Array.from(ydoc.data.elements.keys())) {
|
||||
ydoc.data.elements.delete(id);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Basis-CADLayer für Tests. */
|
||||
export function makeTestLayer(id = 'layer-1', name = 'Test-Layer') {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
visible: true,
|
||||
locked: false,
|
||||
color: '#ffffff',
|
||||
lineType: 'solid',
|
||||
transparency: 0,
|
||||
sortOrder: 0,
|
||||
parentId: null,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user