openpencil/tests/engine/tools/describe.test.ts
rcoenen 9f80c35838
fix(tools): describe visible strokes (#447)
- Include stroke color and rounded weight in node and child summaries
- Select the first visible stroke when hidden paints precede it
- Cover both describe output paths with mixed stroke visibility

Co-authored-by: Rob Coenen <753704+rcoenen@users.noreply.github.com>
2026-08-01 17:40:30 +03:00

68 lines
1.8 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import type { Color, Stroke } from '@open-pencil/scene-graph'
import { expectDefined } from '#tests/helpers/assert'
import { getTool, setupToolTest, type ToolResult } from '#tests/helpers/tools'
const NAVY: Color = { r: 2 / 255, g: 26 / 255, b: 59 / 255, a: 1 }
const HIDDEN_STROKE: Stroke = {
color: { r: 1, g: 0, b: 0, a: 1 },
weight: 4,
opacity: 1,
visible: false,
align: 'CENTER',
cap: 'NONE',
join: 'MITER'
}
const VISIBLE_STROKE: Stroke = {
color: NAVY,
weight: 10.126,
opacity: 1,
visible: true,
align: 'CENTER',
cap: 'NONE',
join: 'MITER'
}
interface ChildSummary {
summary: string
}
function setupStrokedChild() {
const { figma, graph } = setupToolTest()
const frame = figma.createFrame()
frame.name = 'Outline'
frame.resize(200, 200)
const outline = figma.createRectangle()
outline.resize(100, 4)
frame.appendChild(outline)
graph.updateNode(outline.id, {
fills: [],
strokes: [HIDDEN_STROKE, VISIBLE_STROKE]
})
return { figma, frameId: frame.id, outlineId: outline.id }
}
describe('describe stroke summaries', () => {
test('reports the first visible stroke in a child summary', () => {
const { figma, frameId } = setupStrokedChild()
const result = getTool('describe').execute(figma, { id: frameId }) as ToolResult
const children = result.children as ChildSummary[]
const summary = expectDefined(children[0], 'stroked child summary').summary
expect(summary).toContain('#021A3B 10.13px stroke')
})
test('reports the first visible stroke in the node visual summary', () => {
const { figma, outlineId } = setupStrokedChild()
const result = getTool('describe').execute(figma, { id: outlineId }) as ToolResult
expect(result.visual).toContain('#021A3B 10.13px stroke')
})
})