Skip to content

AI-native design editor. Open-source Figma alternative.

1.1 KB
Raw Blame
import { describe, expect, test } from 'bun:test'

import { exportFigFile, parseFigFile } from '@open-pencil/core/io/formats/fig'
import { SceneGraph } from '@open-pencil/scene-graph'

import { pageId } from './helpers'

describe('Directionality plugin fallback', () => {
  test('text and layout direction roundtrip through export/parse', async () => {
    const graph = new SceneGraph()
    const frame = graph.createNode('FRAME', pageId(graph), {
      name: 'RTL Row',
      layoutMode: 'HORIZONTAL',
      layoutDirection: 'RTL',
      width: 240,
      height: 80
    })
    graph.createNode('TEXT', frame.id, {
      text: 'مرحبا',
      textDirection: 'RTL',
      width: 120,
      height: 24
    })

    const bytes = await exportFigFile(graph)
    const parsed = await parseFigFile(bytes.buffer as ArrayBuffer)

    const parsedFrame = [...parsed.getAllNodes()].find((node) => node.name === 'RTL Row')
    const parsedText = [...parsed.getAllNodes()].find((node) => node.type === 'TEXT')
    expect(parsedFrame?.layoutDirection).toBe('RTL')
    expect(parsedText?.textDirection).toBe('RTL')
  })
})