import { describe, it, expect } from 'vitest'; import { dashArray, markerDef, readEdgeStyle, buildLineAttrs } from '../src/editor/edgeStyles'; import { defaultEdgeProps } from '../src/model/graph'; import { COLOR_SCHEMES, relationColor } from '../src/editor/colorSchemes'; describe('edge styles', () => { it('computes dash arrays per line style', () => { expect(dashArray('solid', 2)).toBeNull(); expect(dashArray('dashed', 2)).toBe('8,5'); expect(dashArray('dotted', 2)).toBe('2,4'); expect(dashArray('dashDot', 2)).toBe('8,4,2,4'); }); it('builds marker defs for all marker kinds', () => { expect(markerDef('arrow', '#f00')).toMatchObject({ type: 'path', fill: '#f00' }); expect(markerDef('circle', '#f00')).toMatchObject({ type: 'circle', stroke: '#f00' }); expect(markerDef('diamond', '#f00')).toMatchObject({ type: 'path' }); expect(markerDef('bar', '#f00')).toMatchObject({ type: 'path', fill: 'none' }); expect(markerDef('none', '#f00')).toMatchObject({ fill: 'none' }); }); it('reads style props from the edge default bag', () => { const style = readEdgeStyle(defaultEdgeProps()); expect(style).toEqual({ lineStyle: 'solid', lineWidth: 2, lineColor: '', sourceMarker: 'none', targetMarker: 'arrow', }); }); it('uses relation color unless overridden', () => { const style = readEdgeStyle(defaultEdgeProps()); const attrs = buildLineAttrs(style, '#123456'); expect(attrs.stroke).toBe('#123456'); const attrs2 = buildLineAttrs({ ...style, lineColor: '#abcdef' }, '#123456'); expect(attrs2.stroke).toBe('#abcdef'); }); it('color schemes define colors for every relation', () => { for (const scheme of COLOR_SCHEMES) { for (const rel of ['water', 'heat', 'gas', 'sewage', 'power', 'signal'] as const) { expect(scheme.relations[rel]).toMatch(/^#[0-9a-fA-F]{6}$/); } } expect(relationColor('classic', 'water')).toBe('#2563eb'); expect(relationColor('missing-scheme', 'water')).toBe('#2563eb'); // falls back to first scheme }); });