openpencil/packages/scene-graph/tests/source-metadata.test.ts
Danila Poyarkov 7b9f506f4a
test: migrate Scene Graph tests into the package and gate new tests/engine files (#790)
Scene Graph unit tests move to packages/scene-graph/tests with a package-local assert helper and test type-checking; five Core- and fig-owned tests move to their owners' engine homes. check:test-homes rejects any new test under tests/engine against a reviewed baseline so the migration debt only shrinks.
2026-09-30 04:53:28 +04:00

43 lines
1.4 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { SceneGraph } from '@open-pencil/scene-graph'
function firstPageId(graph: SceneGraph): string {
return graph.getPages()[0].id
}
describe('SceneGraph source dirty tracking', () => {
test('records normalized edited fields once in update order', () => {
const graph = new SceneGraph()
const node = graph.createNode('RECTANGLE', firstPageId(graph))
graph.updateNode(node.id, { width: 200, fills: [] })
graph.updateNode(node.id, { width: 240, opacity: 0.5 })
expect(node.source.editedFields).toEqual(['width', 'fills', 'opacity'])
})
test('preservation scope suppresses import-time dirty tracking', () => {
const graph = new SceneGraph()
const node = graph.createNode('RECTANGLE', firstPageId(graph))
graph.preserveSourceMetadataDuring(() => graph.updateNode(node.id, { width: 200 }))
expect(node.source.editedFields).toEqual([])
})
test('cloned source dirty fields are independent', () => {
const graph = new SceneGraph()
const node = graph.createNode('RECTANGLE', firstPageId(graph))
graph.updateNode(node.id, { width: 200 })
const clone = graph.cloneTree(node.id, firstPageId(graph))
expect(clone).not.toBeNull()
if (!clone) return
graph.updateNode(clone.id, { height: 300 })
expect(node.source.editedFields).toEqual(['width'])
expect(clone.source.editedFields).toEqual(['width', 'height'])
})
})