openpencil/tests/engine/kiwi/serialize-fixes/line/height.test.ts
Danila Poyarkov 1ed7de6056 chore(lint): reject broad unknown type assertions
- Add AST-based lint checks for broad unknown object assertions and local JsonObject aliases
- Centralize JsonObject in core and package-local MCP RPC JSON typing
- Replace baseline Record<string, unknown> assertions with named shared/domain types
2026-05-25 00:26:02 +03:00

76 lines
2 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { exportFigFile, parseFigFile, SceneGraph } from '@open-pencil/core'
import { expectDefined } from '#tests/helpers/assert'
import { pageId, toKiwi } from '../helpers'
describe('Fix 4: text lineHeight serialization', () => {
test('text node with explicit lineHeight uses that value', () => {
const graph = new SceneGraph()
const node = graph.createNode('TEXT', pageId(graph), {
name: 'ExplicitLH',
x: 0,
y: 0,
width: 100,
height: 20,
text: 'Hello',
fontFamily: 'Inter',
fontWeight: 400,
fontSize: 16,
lineHeight: 24
})
const changes = toKiwi(node, graph)
expect(changes[0].lineHeight).toEqual({ value: 24, units: 'PIXELS' })
})
test('text node without lineHeight omits lineHeight', () => {
const graph = new SceneGraph()
const node = graph.createNode('TEXT', pageId(graph), {
name: 'DefaultLH',
x: 0,
y: 0,
width: 100,
height: 20,
text: 'Hello',
fontFamily: 'Inter',
fontWeight: 400,
fontSize: 16
})
const changes = toKiwi(node, graph)
expect(changes[0].lineHeight).toBeUndefined()
})
test('lineHeight survives roundtrip through export/parse', async () => {
const graph = new SceneGraph()
graph.createNode('TEXT', pageId(graph), {
name: 'Roundtrip',
x: 0,
y: 0,
width: 100,
height: 20,
text: 'Hello',
fontFamily: 'Inter',
fontWeight: 400,
fontSize: 16,
lineHeight: 28
})
const exported = await exportFigFile(graph)
const reimported = await parseFigFile(exported.buffer as ArrayBuffer)
const textNode = expectDefined(
[...reimported.nodes.values()].find((n) => n.type === 'TEXT'),
'text node'
)
expect(textNode.lineHeight).toBe(28)
})
})
// ---------------------------------------------------------------------------
// Fix 5 — Font family normalization in derivedTextData
// ---------------------------------------------------------------------------