diverse änderungen
This commit is contained in:
1 parent
3dc1ad623c
commit
f51631100d
85 files changed
+1880
-56
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { DrawEndschalter } from './drawEndschalter';
|
||||
import { parseEndschalterRequest } from '../../_dto/endschalter.dto';
|
||||
|
||||
describe('DrawEndschalter', () => {
|
||||
const generator = new DrawEndschalter();
|
||||
|
||||
it.each([
|
||||
['unten', 20, 40, 'M 4 31', 'M 4,31'],
|
||||
['oben', 20, 40, 'M 16 9', 'M 16,9'],
|
||||
['rechts', 40, 20, 'M 31 16', 'M 31,16'],
|
||||
['links', 40, 20, 'M 9 4', 'M 9,4'],
|
||||
] as const)('richtet die Erfassungsbögen nach %s aus und passt den Zeichenbereich an', (direction, width, height, svgStart, xamlStart) => {
|
||||
const result = generator.getObject({ scale: 2, raster: 4 }, { direction });
|
||||
expect([result.width, result.height]).toEqual([width, height]);
|
||||
for (const variant of result.varianten) {
|
||||
expect(variant.svg).toContain(svgStart);
|
||||
expect(variant.xaml).toContain(xamlStart);
|
||||
}
|
||||
const legacy = generator.getDrawObject({ direction });
|
||||
expect([legacy.px_width, legacy.px_height]).toEqual([width, height]);
|
||||
expect([legacy.length, legacy.height]).toEqual([width / 8, height / 8]);
|
||||
});
|
||||
|
||||
it('behält unten als Standard und validiert die neue Option', () => {
|
||||
expect(parseEndschalterRequest({ config: {} }).options.direction).toBe('unten');
|
||||
expect(() => parseEndschalterRequest({ config: {}, options: { direction: 'diagonal' } })).toThrow();
|
||||
expect(() => parseEndschalterRequest({ config: {}, options: { typo: 'oben' } })).toThrow();
|
||||
});
|
||||
|
||||
it('liefert das schlanke Symbol mit drei Zuständen als SVG und XAML', () => {
|
||||
const result = generator.getObject({ scale: 2, raster: 4 });
|
||||
expect(result.name).toBe('endschalter');
|
||||
expect(result.width).toBe(20);
|
||||
expect(result.height).toBe(40);
|
||||
expect(result.varianten.map(variant => variant.state)).toEqual(['inactive', 'active', 'error']);
|
||||
|
||||
for (const variant of result.varianten) {
|
||||
expect(variant.svg).toContain('<svg xmlns=');
|
||||
expect(variant.xaml).toContain('<Viewbox xmlns=');
|
||||
expect(variant.svg.match(/<path /g)).toHaveLength(4);
|
||||
expect(variant.xaml.match(/<Path /g)).toHaveLength(4);
|
||||
expect(variant.svg).not.toMatch(/NaN|Infinity|undefined/);
|
||||
expect(Buffer.from(variant.xamlBase64, 'base64').toString('utf8')).toBe(variant.xaml);
|
||||
}
|
||||
expect(result.varianten[1].svg).toContain('#00f000');
|
||||
expect(result.varianten[2].xaml).toContain('#f00000');
|
||||
});
|
||||
|
||||
it('skaliert Körper und Bögen und übernimmt die Zustandsfarben', () => {
|
||||
const config = { scale: 4, raster: 4 };
|
||||
const result = generator.getObject(config, { colorActive: '#123456' });
|
||||
expect(result.width).toBe(40);
|
||||
expect(result.height).toBe(80);
|
||||
expect(result.varianten[1].svg).toContain('#123456');
|
||||
expect(result.varianten[1].svg).toContain('stroke-width="2"');
|
||||
expect(generator.getDrawObject({ state: 'active' }).px_height).toBe(40);
|
||||
expect(generator.getSvg({ state: 'active', xaml: true })).toContain('<Viewbox');
|
||||
});
|
||||
|
||||
it('verhindert ungültige Skalierungen und Farben', () => {
|
||||
expect(() => generator.getObject({ scale: 0, raster: 4 })).toThrow();
|
||||
expect(() => generator.getObject({ scale: 2, raster: 4 }, { colorActive: 'red' })).toThrow();
|
||||
expect(() => generator.getObject({ scale: Number.MAX_VALUE / 4, raster: 1 })).toThrow();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user