openpencil/tests/engine/kiwi/instance-overrides/sync-clones.test.ts
Danila Poyarkov 96de4e5fdb fix(fig): preserve regenerated override lineage
- Remap descendant clone sources when instance branches are repopulated

- Keep same-name component-property siblings distinct

- Name swapped variants after their component sets
2026-07-21 01:51:27 +03:00

42 lines
1.9 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { SceneGraph } from '@open-pencil/core'
import { syncChildrenDeep } from '@open-pencil/fig/instance-overrides'
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)
const previousTargetLabel = graph.getChildren(targetChild.id)[0]
const downstreamLabel = graph.createNode('TEXT', page.id, {
name: 'downstream label',
text: 'Target',
componentId: previousTargetLabel.id
})
syncChildrenDeep(graph, sourceParent.id, targetParent.id, new Set())
const syncedChild = graph.getNode(targetChild.id)
const syncedLabel = graph.getChildren(targetChild.id)[0]
expect(syncedChild?.componentId).toBe(sourceComponent.id)
expect(syncedLabel.text).toBe('Source')
expect(graph.getNode(downstreamLabel.id)?.componentId).toBe(syncedLabel.id)
})
})