task(A4.4): migrate text/dimension/leader tools to v2 annotate plugin
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { lineTool, coreDrawingPlugin } from '../src/plugins/builtin/core-drawing';
|
||||
import { selectTool, coreModifyPlugin } from '../src/plugins/builtin/core-modify';
|
||||
import { coreAnnotatePlugin } from '../src/plugins/builtin/core-annotate';
|
||||
import { CADDocument } from '../src/kernel/document/CADDocument';
|
||||
import { createInMemoryDoc } from './helpers/inMemoryDoc';
|
||||
import type { ToolPointerEvent, FullToolContext } from '../src/plugins/types';
|
||||
@@ -199,6 +200,66 @@ describe('A4.3 pilot: polyline/polygon tools', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('A4.4 pilot: annotate tools', () => {
|
||||
it('dimension: down→up committet mit x1..y2-Properties; undo entfernt', () => {
|
||||
const { ydoc } = createInMemoryDoc();
|
||||
const doc = new CADDocument(ydoc);
|
||||
const ctx = makeCtx({ doc });
|
||||
const dim = coreAnnotatePlugin.tools!.find((t) => t.manifest.id === 'dimension')!;
|
||||
|
||||
dim.handlers.down!(pe(0, 0), ctx);
|
||||
dim.handlers.move!(pe(60, 0), ctx); // Preview war da
|
||||
expect(ctx.previews.length).toBe(1);
|
||||
dim.handlers.up!(pe(60, 0), ctx);
|
||||
|
||||
const all = doc.getAllElements();
|
||||
expect(all.length).toBe(1);
|
||||
expect(all[0].type).toBe('dimension');
|
||||
expect(all[0].x).toBe(30); // Mitte
|
||||
expect(all[0].properties.x2).toBe(60);
|
||||
expect(all[0].width).toBeCloseTo(60); // dist als Breite wie Legacy
|
||||
|
||||
expect(doc.undo()).toBe(true);
|
||||
expect(doc.getAllElements().length).toBe(0);
|
||||
});
|
||||
|
||||
it('leader: übernimmt Text/fontSize-Konvention aus Legacy', () => {
|
||||
const { ydoc } = createInMemoryDoc();
|
||||
const doc = new CADDocument(ydoc);
|
||||
const ctx = makeCtx({ doc });
|
||||
const leader = coreAnnotatePlugin.tools!.find((t) => t.manifest.id === 'leader')!;
|
||||
|
||||
leader.handlers.down!(pe(10, 20), ctx);
|
||||
leader.handlers.up!(pe(80, 90), ctx);
|
||||
|
||||
const all = doc.getAllElements();
|
||||
expect(all.length).toBe(1);
|
||||
expect(all[0].type).toBe('leader');
|
||||
expect(all[0].properties.x1).toBe(10);
|
||||
expect(all[0].properties.y2).toBe(90);
|
||||
expect(all[0].properties.text).toBe('');
|
||||
expect(all[0].properties.fontSize).toBe(12);
|
||||
});
|
||||
|
||||
it('text: Einzelklick platziert leeres Textelement mit fontSize-Option', () => {
|
||||
const { ydoc } = createInMemoryDoc();
|
||||
const doc = new CADDocument(ydoc);
|
||||
const ctx = makeCtx({ doc, options: { fontSize: 18 } });
|
||||
const txt = coreAnnotatePlugin.tools!.find((t) => t.manifest.id === 'text')!;
|
||||
|
||||
txt.handlers.down!(pe(40, 70), ctx); // kein up nötig — single-point tool
|
||||
|
||||
const all = doc.getAllElements();
|
||||
expect(all.length).toBe(1);
|
||||
expect(all[0].type).toBe('text');
|
||||
expect(all[0].x).toBe(40);
|
||||
expect(all[0].y).toBe(70);
|
||||
expect(all[0].width).toBe(100); // Legacy-Default-BBox
|
||||
expect(all[0].properties.fontSize).toBe(18); // aus options statt Default 12
|
||||
expect(all[0].properties.text).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('A3 pilot: select tool', () => {
|
||||
function makeBridge(elements: CADElement[]) {
|
||||
let ids: string[] = [];
|
||||
|
||||
Reference in New Issue
Block a user