openpencil/tests/engine/render/jsx/builders.test.ts
Danila Poyarkov c3f5189f8f style: tighten import grouping
- Configure oxfmt custom import groups for workspace, app, package, and test aliases
- Keep type imports grouped with their matching source category instead of one global tail group
- Expand the format script to cover formatter config, Vite files, and scripts
2026-05-06 02:22:08 +03:00

52 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'bun:test'
import { Frame, Text, Rectangle, isTreeNode, node } from '@open-pencil/core'
import { expectDefined } from '#tests/helpers/assert'
describe('TreeNode builders', () => {
it('creates Frame tree node', () => {
const tree = Frame({ name: 'Card', w: 320, h: 200, bg: '#FFF' })
expect(isTreeNode(tree)).toBe(true)
expect(tree.type).toBe('frame')
expect(tree.props.name).toBe('Card')
expect(tree.props.w).toBe(320)
expect(tree.children).toEqual([])
})
it('creates Text tree node with string child', () => {
const tree = Text({ name: 'Title', size: 18, children: 'Hello World' })
expect(tree.type).toBe('text')
expect(tree.children).toEqual(['Hello World'])
})
it('creates nested tree', () => {
const tree = Frame({
name: 'Card',
children: [
Rectangle({ name: 'Bg', w: 100, h: 100, bg: '#E5E7EB' }),
Text({ name: 'Label', size: 14, children: 'Click me' })
]
})
expect(tree.children.length).toBe(2)
expect(isTreeNode(expectDefined(tree.children[0], 'first tree child'))).toBe(true)
const bg = tree.children[0] as ReturnType<typeof Rectangle>
expect(bg.type).toBe('rectangle')
expect(bg.props.name).toBe('Bg')
})
it('node() flattens nested arrays', () => {
const tree = node('frame', {
children: [[Text({ children: 'A' }), Text({ children: 'B' })], Text({ children: 'C' })]
})
expect(tree.children.length).toBe(3)
})
it('node() filters null/undefined children', () => {
const tree = node('frame', {
children: [null, Text({ children: 'A' }), undefined]
})
expect(tree.children.length).toBe(1)
})
})