/** * @jest-environment node */ const { shapeSvg, SHAPE_KINDS, DEFAULT_WIDTH, DEFAULT_HEIGHT, } = require('../src/flowchart/flowchart-shapes'); describe('flowchart-shapes: shapeSvg', () => { test('process emits a at the given coordinates', () => { const svg = shapeSvg('process', 10, 20, 100, 50); expect(svg).toMatch(/ diamond', () => { const svg = shapeSvg('decision', 0, 0, 100, 60); expect(svg).toMatch(/ with rx (stadium)', () => { const svg = shapeSvg('terminator', 0, 0, 120, 40); expect(svg).toMatch(/ { expect(() => shapeSvg('hexagon', 0, 0, 100, 50)).toThrow(/hexagon/); }); // v4.12.0 — optional fill color. Defaults to #ffffff when omitted, used // when provided, and applied to every emitted element (rect/polygon and // both rects of the subroutine double-border). test('process emits a with default fill #ffffff when color is omitted', () => { const svg = shapeSvg('process', 10, 20, 100, 50); expect(svg).toMatch(/fill="#ffffff"/); }); test('process emits a with the given fill color', () => { const svg = shapeSvg('process', 0, 0, 100, 50, '#ff0000'); expect(svg).toMatch(/fill="#ff0000"/); expect(svg).toMatch(/ { const svg = shapeSvg('decision', 0, 0, 100, 60, '#336699'); expect(svg).toMatch(/s with the fill color', () => { const svg = shapeSvg('subroutine', 0, 0, 100, 50, '#aabbcc'); const fills = svg.match(/fill="#aabbcc"/g) || []; expect(fills.length).toBeGreaterThanOrEqual(2); }); test('terminator honors the fill color', () => { const svg = shapeSvg('terminator', 0, 0, 120, 40, '#123456'); expect(svg).toMatch(/fill="#123456"/); expect(svg).toMatch(/rx="/); }); test('document (parallelogram) honors the fill color', () => { const svg = shapeSvg('document', 0, 0, 120, 60, '#abcdef'); expect(svg).toMatch(/ { expect(shapeSvg('process', 0, 0, 100, 50, '')).toMatch(/fill="#ffffff"/); expect(shapeSvg('process', 0, 0, 100, 50, null)).toMatch(/fill="#ffffff"/); expect(shapeSvg('process', 0, 0, 100, 50, undefined)).toMatch(/fill="#ffffff"/); }); test('SHAPE_KINDS lists all 5 shapes', () => { expect(SHAPE_KINDS.sort()).toEqual([ 'decision', 'document', 'process', 'subroutine', 'terminator', ]); }); test('DEFAULT_WIDTH and DEFAULT_HEIGHT are positive numbers', () => { expect(DEFAULT_WIDTH).toBeGreaterThan(0); expect(DEFAULT_HEIGHT).toBeGreaterThan(0); }); });