openpencil/tests/app/libraries/hash-normalization.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

42 lines
1.8 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { exportFigFile, initCodec, parseFigFile } from '@open-pencil/core'
import { createLibraryRevision, discoverPublishableLibraryChanges } from '@open-pencil/core/library'
import { SceneGraph } from '@open-pencil/scene-graph'
function source() {
const graph = new SceneGraph()
const page = graph.getPages()[0]
const component = graph.createNode('COMPONENT', page.id, {
name: 'Button',
componentKey: 'button',
width: 80,
height: 32
})
graph.createNode('TEXT', component.id, { name: 'Label', text: 'Button', width: 60, height: 20 })
return graph
}
describe('library hash normalization', () => {
test('ignores representation-only FIG round-trip changes', async () => {
initCodec()
const graph = source()
const previous = await createLibraryRevision({ libraryId: 'library', name: 'Library', graph })
const restored = await parseFigFile((await exportFigFile(graph)).buffer as ArrayBuffer)
const discovery = await discoverPublishableLibraryChanges(previous, restored)
expect(discovery.changes).toEqual([])
})
test('still detects semantic changes after a FIG round trip', async () => {
initCodec()
const graph = source()
const previous = await createLibraryRevision({ libraryId: 'library', name: 'Library', graph })
const restored = await parseFigFile((await exportFigFile(graph)).buffer as ArrayBuffer)
const component = [...restored.getAllNodes()].find((node) => node.componentKey === 'button')
if (!component) throw new Error('Component missing')
restored.updateNode(component.id, { width: 144 })
const discovery = await discoverPublishableLibraryChanges(previous, restored)
expect(discovery.changes).toMatchObject([{ kind: 'modified', asset: { key: 'button' } }])
})
})