openpencil/tests/app/libraries/metadata.test.ts
Danila Poyarkov f7a013191b
refactor(fig): export the symbol readers and move the library tests home (#929)
The Kiwi codec types only symbolID, so every test reading symbolOverrides
or uniformScaleFactor repeated the same cast against a type the package
exported without the readers that go with it. symbolDataOf and
symbolOverridesOf are now exported and five call sites use them.

tests/engine/library exercises @/app/libraries, so it belongs under
tests/app by the placement rules; the shard list and the engine baseline
follow it.
2026-10-06 10:44:22 +00:00

39 lines
1.2 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { SceneGraph } from '@open-pencil/scene-graph'
import { deserializeSceneGraph, serializeSceneGraph } from '#core/kiwi/fig/parse/transfer'
describe('library graph metadata', () => {
test('serializes enabled library bindings and node source identity', () => {
const graph = new SceneGraph()
graph.enabledLibraries.set('design-system', {
libraryId: 'design-system',
revisionId: 'revision-1',
enabled: true
})
const page = graph.getPages()[0]
if (!page) throw new Error('Expected page')
const component = graph.createNode('COMPONENT', page.id, {
name: 'Button',
librarySource: {
identity: {
libraryId: 'design-system',
assetKey: 'button',
revisionId: 'revision-1'
},
sourceNodeId: 'source-button',
readOnly: true
}
})
const restored = deserializeSceneGraph(serializeSceneGraph(graph))
expect(restored.enabledLibraries.get('design-system')).toEqual({
libraryId: 'design-system',
revisionId: 'revision-1',
enabled: true
})
expect(restored.getNode(component.id)?.librarySource).toEqual(component.librarySource)
})
})