2026-05-06 10:36:48 +00:00
|
|
|
import { describe, expect, test } from 'bun:test'
|
|
|
|
|
|
|
|
|
|
import { createAPI } from './helpers'
|
|
|
|
|
|
2026-05-24 21:26:02 +00:00
|
|
|
interface SerializedNodeWithChildren {
|
|
|
|
|
children?: unknown[]
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 10:36:48 +00:00
|
|
|
describe('serialization', () => {
|
|
|
|
|
test('toJSON returns clean object', () => {
|
|
|
|
|
const api = createAPI()
|
|
|
|
|
const frame = api.createFrame()
|
|
|
|
|
frame.name = 'Card'
|
|
|
|
|
frame.resize(300, 200)
|
|
|
|
|
frame.fills = [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, opacity: 1, visible: true }]
|
|
|
|
|
const json = frame.toJSON()
|
|
|
|
|
expect(json.name).toBe('Card')
|
|
|
|
|
expect(json.width).toBe(300)
|
|
|
|
|
expect(json.fills).toBeDefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('toJSON includes children', () => {
|
|
|
|
|
const api = createAPI()
|
|
|
|
|
const frame = api.createFrame()
|
|
|
|
|
const rect = api.createRectangle()
|
|
|
|
|
frame.appendChild(rect)
|
2026-05-24 21:26:02 +00:00
|
|
|
const json = frame.toJSON() as SerializedNodeWithChildren
|
2026-05-06 10:36:48 +00:00
|
|
|
expect(json.children).toBeDefined()
|
|
|
|
|
expect(json.children?.length).toBe(1)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('toString returns readable string', () => {
|
|
|
|
|
const api = createAPI()
|
|
|
|
|
const frame = api.createFrame()
|
|
|
|
|
frame.name = 'Card'
|
|
|
|
|
expect(frame.toString()).toContain('FRAME')
|
|
|
|
|
expect(frame.toString()).toContain('Card')
|
|
|
|
|
})
|
|
|
|
|
})
|