task(F3-frontend): save selection as block - svg thumbnail from elementToPrimitives, save button in library tree
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* BlockThumbnail Tests (Task F3) – SVG-Thumbnail aus elementToPrimitives
|
||||
*/
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { generateBlockSvg, primitivesToSvg } from '../src/utils/blockThumbnail';
|
||||
import { elementToPrimitives } from '../src/render/pixi/elementDrawers';
|
||||
import type { CADElement } from '../src/types/cad.types';
|
||||
|
||||
describe('blockThumbnail (F3)', () => {
|
||||
const chair: CADElement = {
|
||||
id: 'c1',
|
||||
type: 'chair',
|
||||
layerId: 'l0',
|
||||
x: 100,
|
||||
y: 200,
|
||||
width: 40,
|
||||
height: 40,
|
||||
properties: {},
|
||||
} as CADElement;
|
||||
|
||||
it('erzeugt SVG mit viewBox aus Element-BBox', () => {
|
||||
const svg = generateBlockSvg([chair]);
|
||||
expect(svg).toContain('<svg');
|
||||
expect(svg).toContain('viewBox');
|
||||
});
|
||||
|
||||
it('konvertiert rect-Primitive in SVG-rect', () => {
|
||||
const prims = elementToPrimitives(chair);
|
||||
expect(prims.length).toBeGreaterThan(0);
|
||||
const svg = primitivesToSvg(prims);
|
||||
expect(svg).toContain('<rect');
|
||||
});
|
||||
|
||||
it('liefert leeren String für leere Auswahl', () => {
|
||||
expect(generateBlockSvg([])).toBe('');
|
||||
});
|
||||
|
||||
it('BBox umfasst mehrere Elemente korrekt', () => {
|
||||
const a: CADElement = { ...chair, id: 'a', x: 0, y: 0 };
|
||||
const b: CADElement = { ...chair, id: 'b', x: 500, y: 300 };
|
||||
const svg = generateBlockSvg([a, b]);
|
||||
// chair-Drawer erzeugt rect-Zentrum bei (el.x - w/2) → BBox -40..500/-40..300 + PAD 10
|
||||
expect(svg).toContain('viewBox="-50 -50 560 360"');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user