Skip to content

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

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

import { computeLayout } from '@open-pencil/core/layout'
import { SceneGraph } from '@open-pencil/scene-graph'

import { autoFrame, pageId, rect } from '#tests/helpers/layout'

describe('alignment - counter axis', () => {
  test('center cross-axis alignment (horizontal)', () => {
    const graph = new SceneGraph()
    const frame = autoFrame(graph, pageId(graph), {
      width: 400,
      height: 200,
      counterAxisAlign: 'CENTER'
    })
    rect(graph, frame.id, 50, 50)

    computeLayout(graph, frame.id)

    const child = graph.getChildren(frame.id)[0]
    expect(child.y).toBe(75)
  })

  test('max cross-axis alignment (horizontal)', () => {
    const graph = new SceneGraph()
    const frame = autoFrame(graph, pageId(graph), {
      width: 400,
      height: 200,
      counterAxisAlign: 'MAX'
    })
    rect(graph, frame.id, 50, 50)

    computeLayout(graph, frame.id)

    const child = graph.getChildren(frame.id)[0]
    expect(child.y).toBe(150)
  })

  test('center cross-axis alignment (vertical)', () => {
    const graph = new SceneGraph()
    const frame = autoFrame(graph, pageId(graph), {
      layoutMode: 'VERTICAL',
      width: 200,
      height: 400,
      counterAxisAlign: 'CENTER'
    })
    rect(graph, frame.id, 50, 50)

    computeLayout(graph, frame.id)

    const child = graph.getChildren(frame.id)[0]
    expect(child.x).toBe(75)
  })

  test('stretch cross-axis alignment (horizontal)', () => {
    const graph = new SceneGraph()
    const frame = autoFrame(graph, pageId(graph), {
      width: 400,
      height: 200,
      counterAxisAlign: 'STRETCH'
    })
    rect(graph, frame.id, 50, 50)

    computeLayout(graph, frame.id)

    const child = graph.getChildren(frame.id)[0]
    expect(child.height).toBe(200)
  })

  test('stretch cross-axis alignment (vertical)', () => {
    const graph = new SceneGraph()
    const frame = autoFrame(graph, pageId(graph), {
      layoutMode: 'VERTICAL',
      width: 200,
      height: 400,
      counterAxisAlign: 'STRETCH'
    })
    rect(graph, frame.id, 50, 50)

    computeLayout(graph, frame.id)

    const child = graph.getChildren(frame.id)[0]
    expect(child.width).toBe(200)
  })
})