openpencil/tests/engine/kiwi/instance-overrides/sync-clones.test.ts
Danila Poyarkov 213db6373a refactor(kiwi): group fig format internals
- Move codec, NodeChange conversion, and instance overrides under kiwi/fig
- Flatten the codec entrypoint to kiwi/fig/codec
- Keep schema-runtime as the generic Kiwi parser/compiler boundary
2026-05-21 14:54:13 +03:00

35 lines
1.5 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { SceneGraph } from '@open-pencil/core'
import { syncChildrenDeep } from '#core/kiwi/fig/instance-overrides/sync/clones'
describe('instance override clone sync', () => {
test('reclones nested instance children when the source component changes', () => {
const graph = new SceneGraph()
const page = graph.getPages()[0]
const sourceParent = graph.createNode('FRAME', page.id)
const targetParent = graph.createNode('FRAME', page.id)
const sourceComponent = graph.createNode('COMPONENT', page.id, { name: 'source component' })
const targetComponent = graph.createNode('COMPONENT', page.id, { name: 'target component' })
graph.createNode('TEXT', sourceComponent.id, { name: 'label', text: 'Source' })
graph.createNode('TEXT', targetComponent.id, { name: 'label', text: 'Target' })
const sourceChild = graph.createNode('INSTANCE', sourceParent.id, {
name: 'nested',
componentId: sourceComponent.id
})
graph.populateInstanceChildren(sourceChild.id, sourceComponent.id)
const targetChild = graph.createNode('INSTANCE', targetParent.id, {
name: 'nested',
componentId: targetComponent.id
})
graph.populateInstanceChildren(targetChild.id, targetComponent.id)
syncChildrenDeep(graph, sourceParent.id, targetParent.id, new Set())
const syncedChild = graph.getNode(targetChild.id)
expect(syncedChild?.componentId).toBe(sourceComponent.id)
expect(graph.getChildren(targetChild.id).map((child) => child.text)).toEqual(['Source'])
})
})