openpencil/tests/engine/io/fig/import/boolean-operation.test.ts
Danila Poyarkov 2bd2304bcb refactor(fig): own instance interpretation
- Move component properties, symbol overrides, derived symbol data, and clone synchronization into @open-pencil/fig\n- Add the public instance-overrides subpath with package tests and packed smoke coverage\n- Remove cross-package forwarding modules and enforce direct owner imports in architecture checks
2026-07-18 02:06:34 +03:00

100 lines
2.9 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { nodeChangeToProps } from '@open-pencil/fig/node-change'
import type { NodeChange } from '@open-pencil/kiwi/fig/codec'
import { importNodeChanges } from '#core/kiwi/fig/import'
describe('Figma boolean operation import', () => {
test('preserves boolean operation nodes', () => {
const props = nodeChangeToProps(
{
type: 'BOOLEAN_OPERATION',
name: 'Imported boolean',
booleanOperation: 'SUBTRACT'
} as NodeChange,
[]
)
expect(props.nodeType).toBe('BOOLEAN_OPERATION')
expect(props.booleanOperation).toBe('SUBTRACT')
})
test('imports boolean operation nodes with children', () => {
const graph = importNodeChanges([
{
guid: { sessionID: 0, localID: 0 },
type: 'DOCUMENT',
name: 'Document',
phase: 'CREATED'
},
{
guid: { sessionID: 0, localID: 1 },
parentIndex: { guid: { sessionID: 0, localID: 0 }, position: '!' },
type: 'CANVAS',
name: 'Page',
phase: 'CREATED'
},
{
guid: { sessionID: 2, localID: 1 },
parentIndex: { guid: { sessionID: 0, localID: 1 }, position: '!' },
type: 'BOOLEAN_OPERATION',
name: 'Imported boolean',
booleanOperation: 'INTERSECT',
phase: 'CREATED',
size: { x: 120, y: 80 }
},
{
guid: { sessionID: 2, localID: 2 },
parentIndex: { guid: { sessionID: 2, localID: 1 }, position: '!' },
type: 'RECTANGLE',
name: 'Left operand',
phase: 'CREATED',
size: { x: 80, y: 80 }
},
{
guid: { sessionID: 2, localID: 3 },
parentIndex: { guid: { sessionID: 2, localID: 1 }, position: '"' },
type: 'ELLIPSE',
name: 'Right operand',
phase: 'CREATED',
size: { x: 80, y: 80 }
}
] as NodeChange[])
const booleanNode = graph.getChildren(graph.getPages()[0].id)[0]
const children = graph.getChildren(booleanNode.id)
expect(booleanNode.type).toBe('BOOLEAN_OPERATION')
expect(booleanNode.booleanOperation).toBe('INTERSECT')
expect(children.map((child) => child.type)).toEqual(['RECTANGLE', 'ELLIPSE'])
})
test('maps Kiwi XOR boolean operations to scene graph exclude', () => {
const props = nodeChangeToProps(
{
type: 'BOOLEAN_OPERATION',
name: 'Imported boolean',
booleanOperation: 'XOR'
} as NodeChange,
[]
)
expect(props.nodeType).toBe('BOOLEAN_OPERATION')
expect(props.booleanOperation).toBe('EXCLUDE')
})
test('defaults missing boolean operations to union', () => {
const props = nodeChangeToProps(
{
type: 'BOOLEAN_OPERATION',
name: 'Imported boolean'
} as NodeChange,
[]
)
expect(props.nodeType).toBe('BOOLEAN_OPERATION')
expect(props.booleanOperation).toBe('UNION')
})
})