import { describe, expect, test } from 'bun:test' import { sceneNodesToTailwindJSX } from '#dom-css/index' import { makeGraph, pageId, tw } from './helpers' describe('Tailwind JSX structure', () => { test('layer names cannot add attributes', () => { const graph = makeGraph() const node = graph.createNode('RECTANGLE', pageId(graph), { name: 'a" onClick={alert(1)} x="', width: 100, height: 48 }) expect(tw(graph, node.id)).toStartWith( '
{ const graph = makeGraph() const backslash = graph.createNode('RECTANGLE', pageId(graph), { name: 'a\\b', width: 8, height: 8 }) const lines = graph.createNode('RECTANGLE', pageId(graph), { name: 'two\nlines', width: 8, height: 8 }) expect(tw(graph, backslash.id)).toStartWith('
{ const graph = makeGraph() const node = graph.createNode('RECTANGLE', pageId(graph), { name: 'Box', width: 100, height: 48 }) const jsx = tw(graph, node.id) expect(jsx).toContain(' with text classes', () => { const graph = makeGraph() const node = graph.createNode('TEXT', pageId(graph), { name: 'Title', width: 200, height: 24, text: 'Hello World', fontSize: 18, fontWeight: 700, fills: [{ type: 'SOLID', color: { r: 0, g: 0, b: 0, a: 1 }, opacity: 1, visible: true }] }) const jsx = tw(graph, node.id) expect(jsx).toContain('Hello World

') expect(jsx).not.toContain(' tag', () => { const graph = makeGraph() const node = graph.createNode('SECTION', pageId(graph), { width: 800, height: 600 }) const jsx = tw(graph, node.id) expect(jsx).toContain(' { const graph = makeGraph() const frame = graph.createNode('FRAME', pageId(graph), { name: 'Card', width: 320, height: 200, layoutMode: 'VERTICAL', itemSpacing: 8, primaryAxisSizing: 'HUG', counterAxisSizing: 'FIXED', fills: [ { type: 'SOLID', color: { r: 0.95, g: 0.95, b: 0.95, a: 1 }, opacity: 1, visible: true } ], cornerRadius: 12 }) graph.createNode('TEXT', frame.id, { name: 'Title', width: 200, height: 20, text: 'Card Title', fontSize: 16, fontWeight: 700, fills: [{ type: 'SOLID', color: { r: 0, g: 0, b: 0, a: 1 }, opacity: 1, visible: true }] }) const jsx = tw(graph, frame.id) expect(jsx).toContain('Card Title

') expect(jsx).toContain('
') }) test('selections are separated by blank lines', () => { const graph = makeGraph() const a = graph.createNode('RECTANGLE', pageId(graph), { name: 'A', width: 40, height: 40 }) const b = graph.createNode('ELLIPSE', pageId(graph), { name: 'B', width: 80, height: 80 }) const jsx = sceneNodesToTailwindJSX(graph, [a.id, b.id]) expect(jsx).toContain(' { const graph = makeGraph() const node = graph.createNode('RECTANGLE', pageId(graph), { width: 100, height: 100, opacity: 1, rotation: 0, cornerRadius: 0 }) const jsx = tw(graph, node.id) expect(jsx).not.toContain('opacity') expect(jsx).not.toContain('rotate') expect(jsx).not.toContain('rounded') }) })