fix(tools): require sibling variant components
- Reject combine_as_variants inputs that span different parents\n- Preserve all source components when validation fails\n- Cover the tool-level error path
This commit is contained in:
parent
1db92c4603
commit
c05a5596aa
|
|
@ -52,6 +52,9 @@ export const combineAsVariants = defineTool({
|
|||
return { error: 'combineAsVariants requires COMPONENT nodes' }
|
||||
}
|
||||
const parent = nodes[0].parent ?? figma.currentPage
|
||||
if (!nodes.every((node) => node.parent?.id === parent.id)) {
|
||||
return { error: 'combineAsVariants requires components to share a parent' }
|
||||
}
|
||||
try {
|
||||
const componentSet = figma.combineAsVariants(nodes, parent)
|
||||
return nodeSummary(componentSet)
|
||||
|
|
|
|||
|
|
@ -64,6 +64,26 @@ describe('create_shape', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('combine_as_variants', () => {
|
||||
test('rejects components from different parents', () => {
|
||||
const { figma } = setupToolTest()
|
||||
const firstParent = figma.createFrame()
|
||||
const secondParent = figma.createFrame()
|
||||
const first = figma.createComponent()
|
||||
const second = figma.createComponent()
|
||||
firstParent.appendChild(first)
|
||||
secondParent.appendChild(second)
|
||||
|
||||
const result = getTool('combine_as_variants').execute(figma, {
|
||||
ids: [first.id, second.id]
|
||||
}) as ToolResult
|
||||
|
||||
expect(result.error).toBe('combineAsVariants requires components to share a parent')
|
||||
expect(first.parent?.id).toBe(firstParent.id)
|
||||
expect(second.parent?.id).toBe(secondParent.id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('render', () => {
|
||||
test('renders JSX string', async () => {
|
||||
const { figma } = setupToolTest()
|
||||
|
|
|
|||
Loading…
Reference in a new issue