47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
|
|
import { createEditor } from '@open-pencil/core/editor'
|
|
import { computeAllLayouts } from '@open-pencil/core/layout'
|
|
|
|
import { getNodeOrThrow } from '#tests/helpers/assert'
|
|
import { rect } from '#tests/helpers/layout'
|
|
|
|
describe('structure state actions', () => {
|
|
test('toggleNodeVisibility reflows HUG auto-layout instance slots', async () => {
|
|
const editor = createEditor()
|
|
const page = editor.state.currentPageId
|
|
const component = editor.graph.createNode('COMPONENT', page, {
|
|
layoutMode: 'VERTICAL',
|
|
primaryAxisSizing: 'HUG',
|
|
counterAxisSizing: 'FIXED',
|
|
width: 300,
|
|
height: 1,
|
|
itemSpacing: 0
|
|
})
|
|
rect(editor.graph, component.id, 300, 40, { name: 'Slot / Pinned at Top' })
|
|
rect(editor.graph, component.id, 300, 74, { name: 'Slot / Content' })
|
|
rect(editor.graph, component.id, 300, 40, { name: 'Slot / Pinned at Bottom' })
|
|
const instance = editor.graph.createInstance(component.id, page)
|
|
if (!instance) throw new Error('Expected instance')
|
|
computeAllLayouts(editor.graph, page)
|
|
|
|
const content = editor.graph
|
|
.getChildren(instance.id)
|
|
.find((child) => child.name === 'Slot / Content')
|
|
const bottom = editor.graph
|
|
.getChildren(instance.id)
|
|
.find((child) => child.name === 'Slot / Pinned at Bottom')
|
|
if (!content || !bottom) throw new Error('Expected instance slot children')
|
|
|
|
editor.toggleNodeVisibility(content.id)
|
|
|
|
expect(getNodeOrThrow(editor.graph, instance.id).height).toBe(80)
|
|
expect(getNodeOrThrow(editor.graph, bottom.id).y).toBe(40)
|
|
|
|
await Promise.resolve()
|
|
|
|
expect(getNodeOrThrow(editor.graph, instance.id).height).toBe(80)
|
|
expect(getNodeOrThrow(editor.graph, bottom.id).y).toBe(40)
|
|
})
|
|
})
|