Files
rk-backend/src/graphics/elements/drawPunkt.spec.ts
T

43 lines
2.6 KiB
TypeScript

import { describe, expect, it } from '@jest/globals';
import { DrawPunkt } from './drawPunkt';
import { parsePunktRequest } from '../../_dto/punkt.dto';
describe('DrawPunkt', () => {
it('liefert einen Kreis ohne Text, mit schwarzem Rand sowie SVG, XAML und Base64 für beide Zustände', () => {
const result = new DrawPunkt().getObject({ scale: 2, raster: 4 }, { colorInactive: '#123456', colorActive: '#abcdef' });
expect(result.name).toBe('punkt'); expect(result.width).toBe(24); expect(result.height).toBe(24);
expect(result.varianten.map(v => v.state)).toEqual(['inactive', 'active']);
for (const [i, variant] of result.varianten.entries()) {
const color = i === 0 ? '#123456' : '#abcdef';
expect(variant.svg).toContain('<ellipse'); expect(variant.svg).toContain('stroke="#000000"');
expect(variant.svg).toContain(`fill="${color}"`); expect(variant.svg).not.toContain('<text');
expect(variant.xaml).toContain('<Ellipse'); expect(variant.xaml).toContain('Stroke="#000000"'); expect(variant.xaml).toContain(`Fill="${color}"`);
expect(Buffer.from(variant.xamlBase64, 'base64').toString('utf8')).toBe(variant.xaml);
}
});
it('hält den Rand vollständig innerhalb der Zeichenfläche, auch bei kleinen Größen', () => {
for (const scale of [0.01, 1, 4]) {
const result = new DrawPunkt().getObject({ scale, raster: 4 });
const svg = result.varianten[0].svg;
const radius = Number(/rx="([^"]+)"/.exec(svg)?.[1]);
const stroke = Number(/stroke-width="([^"]+)"/.exec(svg)?.[1]);
expect(2 * radius + stroke).toBeCloseTo(result.width);
expect(svg).toContain(`ry="${radius}"`);
}
});
it('verwendet Motor-kompatible Größenparameter und Standardfarben', () => {
const parsed = parsePunktRequest({ config: {} });
expect(parsed.config).toEqual({ scale: 2, raster: 4 });
const punkt = new DrawPunkt();
expect(punkt.getObject(parsed.config).varianten[0].svg).toContain('#808080');
expect(punkt.getObject(parsed.config).varianten[1].svg).toContain('#00f000');
expect(punkt.getDrawObject({}).px_width).toBe(24);
expect(punkt.getSvg({ state: 'active', colorActive: '#112233' })).toContain('#112233');
expect(punkt.getSvg({ xaml: true })).toContain('<Viewbox');
});
it.each([null, {}, { config: { scale: 0 } }, { config: { raster: -1 } }, { config: { diameter: 20 } },
{ config: {}, options: { colorActive: 'red' } }, { config: {}, options: { colorError: '#ff0000' } }])('verhindert ungültige Parameter %j', input => {
expect(() => parsePunktRequest(input)).toThrow();
});
});