task(C3fin-int): interactive handle drag for select tool (scale by corner)
This commit is contained in:
@@ -860,3 +860,65 @@ describe('D-Ext: array-polar tool', () => {
|
||||
expect(doc.getAllElements().length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('C3fin interaktiv: handle-drag on select tool', () => {
|
||||
function makeRect(id: string, x: number, y: number, w: number, h: number): CADElement {
|
||||
return {
|
||||
id, type: 'rect', layerId: 'l',
|
||||
x: x + w / 2, y: y + h / 2,
|
||||
width: w, height: h,
|
||||
properties: { fill: '#abc' },
|
||||
} as unknown as CADElement;
|
||||
}
|
||||
|
||||
it('down auf Handle startet Drag, move skaliert, up committet', () => {
|
||||
const { ydoc } = createInMemoryDoc();
|
||||
const doc = new CADDocument(ydoc);
|
||||
// Rect: (0,0) bis (50,50)
|
||||
doc.addElement(makeRect('r1', 0, 0, 50, 50));
|
||||
let selIds: string[] = ['r1'];
|
||||
const bridge = {
|
||||
getIds: () => selIds,
|
||||
setIds: (ids: string[]) => { selIds = ids; },
|
||||
hitTest: () => null,
|
||||
};
|
||||
const ctx = makeCtx({ doc, selection: bridge });
|
||||
const select = coreModifyPlugin.tools!.find((t) => t.manifest.id === 'select')!;
|
||||
|
||||
// down auf Handle der oberen linken Ecke (0,0):
|
||||
select.handlers.down!(pe(0, 0), ctx);
|
||||
// move zu neuem Punkt (-20, -20):
|
||||
select.handlers.move!(pe(-20, -20), ctx);
|
||||
// up → Commit (Skalierung auf neue BBox von (-20,-20) bis (50,50)):
|
||||
select.handlers.up!(pe(-20, -20), ctx);
|
||||
|
||||
const updated = doc.getElement('r1')!;
|
||||
// Neue BBox: 70×70 statt 50×50:
|
||||
expect(updated.width).toBe(70);
|
||||
expect(updated.height).toBe(70);
|
||||
expect(doc.undo()).toBe(true); // Skalierung ist undo-bar
|
||||
expect(doc.getElement('r1')!.width).toBe(50);
|
||||
});
|
||||
|
||||
it('down auf NICHT-Handle startet normale Selektion (kein Drag)', () => {
|
||||
const { ydoc } = createInMemoryDoc();
|
||||
const doc = new CADDocument(ydoc);
|
||||
doc.addElement(makeRect('r2', 0, 0, 50, 50));
|
||||
doc.addElement(makeRect('r3', 200, 200, 30, 30));
|
||||
let selIds: string[] = ['r2'];
|
||||
const bridge = {
|
||||
getIds: () => selIds,
|
||||
setIds: (ids: string[]) => { selIds = ids; },
|
||||
// Klick bei (210,210) trifft r3:
|
||||
hitTest: () => doc.getElement('r3')!,
|
||||
};
|
||||
const ctx = makeCtx({ doc, selection: bridge });
|
||||
const select = coreModifyPlugin.tools!.find((t) => t.manifest.id === 'select')!;
|
||||
|
||||
// Klick weit weg von Handles von r2 (r2-Ecken sind 0/50):
|
||||
select.handlers.down!(pe(210, 210), ctx);
|
||||
|
||||
// Normal-Selektion: r3 ist jetzt alleine selektiert (kein Drag gestartet):
|
||||
expect(selIds).toEqual(['r3']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user