openpencil/tests/engine/io/fig/heavy/component-metadata.test.ts
Danila Poyarkov c7b944d103 fix(kiwi): harden FIG containers and DOM imports
- Decode zstd FIG data and reject invalid compressed payloads

- Compose caller CSS with Tailwind defaults during DOM import

- Slice pooled fixture buffers to their exact byte range

Co-authored-by: Joseph Cumines <joeycumines@gmail.com>
2026-08-13 20:33:10 +03:00

63 lines
2.3 KiB
TypeScript

import { expect, setDefaultTimeout, test } from 'bun:test'
import { parseFigBuffer } from '@open-pencil/fig'
import { importNodeChanges } from '#core/kiwi'
import { expectDefined } from '#tests/helpers/assert'
import { readFixtureArrayBuffer } from '#tests/helpers/fig-fixtures'
import { heavy } from '#tests/helpers/test-utils'
function importFixture(name: string) {
const { nodeChanges, blobs, images } = parseFigBuffer(readFixtureArrayBuffer(name))
return importNodeChanges(nodeChanges, blobs, new Map(images))
}
setDefaultTimeout(30_000)
heavy('fig component metadata import', () => {
test('preserves remote library component identity fields', () => {
const graph = importFixture('gold-preview.fig')
const component = expectDefined(
graph
.getAllNodes()
.find((node) => node.componentKey === '26164e029c485511adfa634522024c7c23e7bb81'),
'remote component'
)
expect(component.sourceLibraryKey).toStartWith('lk-')
expect(component.publishId).toBe('4132:5801')
expect(component.overrideKey).toBe('4132:5801')
expect(component.sharedSymbolVersion).toBe('4152:1913')
expect(component.isSymbolPublishable).toBe(false)
}, 10_000)
test('imports component set docs and variant property specs', () => {
const graph = importFixture('material3.fig')
const buttonSet = expectDefined(
graph.getAllNodes().find((node) => node.type === 'COMPONENT_SET' && node.name === 'Button'),
'Button component set'
)
expect(buttonSet.isPublishable).toBe(true)
expect(buttonSet.symbolDescription).toContain('Buttons communicate actions')
expect(buttonSet.symbolLinks.map((link) => link.uri)).toContain(
'http://m3.material.io/components/buttons/overview'
)
expect(buttonSet.componentPropertyDefinitions.map((def) => def.name)).toContain('State')
const variant = expectDefined(
graph
.getChildren(buttonSet.id)
.find((node) => node.type === 'COMPONENT' && node.name.includes('State=Disabled')),
'disabled Button variant'
)
expect(variant.variantPropSpecs.length).toBeGreaterThan(0)
expect(variant.componentPropertyValues.State).toBe('Disabled')
expect(variant.componentPropertyValues.Style).toBe('Tonal')
expect(Object.keys(variant.componentPropertyValues).some((key) => key.includes(':'))).toBe(
false
)
})
})