28 lines
962 B
TypeScript
28 lines
962 B
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { toSvg } from '../src/lib/export-svg';
|
|
|
|
const shape = {
|
|
outer: [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 50 }, { x: 0, y: 50 }],
|
|
holes: [[{ x: 10, y: 10 }, { x: 20, y: 10 }, { x: 20, y: 20.5 }]],
|
|
};
|
|
|
|
describe('toSvg', () => {
|
|
it('declares its size in mm with a matching viewBox', () => {
|
|
const svg = toSvg(shape);
|
|
expect(svg).toContain('width="100mm"');
|
|
expect(svg).toContain('height="50mm"');
|
|
expect(svg).toContain('viewBox="0 0 100 50"');
|
|
});
|
|
|
|
it('writes one closed subpath per ring in a single evenodd path', () => {
|
|
const svg = toSvg(shape);
|
|
const d = svg.match(/ d="([^"]+)"/)![1];
|
|
expect(d.match(/M/g)).toHaveLength(2);
|
|
expect(d.match(/Z/g)).toHaveLength(2);
|
|
expect(d).toContain('M0,0 L100,0 L100,50 L0,50 Z');
|
|
expect(d).toContain('20,20.5');
|
|
expect(svg).toContain('fill-rule="evenodd"');
|
|
expect(svg).toContain('fill="none"');
|
|
});
|
|
});
|