openpencil/tests/engine/editor/structure/z-order.test.ts
Danila Poyarkov de8578c435
feat(app): expand Figma menu and selection parity (#459)
- Add Figma-style object, component, selection, view, settings, and browser Move to Page actions
- Add undoable z-order, transformed distribution, inverse selection, and single/bulk rename behavior
- Keep browser and native menus, shortcuts, generated schema, localization, and documentation aligned
2026-08-03 00:23:05 +03:00

55 lines
1.7 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { createEditor } from '@open-pencil/core/editor'
function setupEditor() {
const editor = createEditor()
const pageId = editor.state.currentPageId
const nodes = ['A', 'B', 'C', 'D'].map((name) =>
editor.graph.createNode('RECTANGLE', pageId, { name, width: 10, height: 10 })
)
return { editor, pageId, nodes }
}
function childNames(editor: ReturnType<typeof createEditor>, pageId: string) {
return editor.graph.getChildren(pageId).map((node) => node.name)
}
describe('z-order actions', () => {
test('moves a contiguous selection forward and backward by one layer', () => {
const { editor, pageId, nodes } = setupEditor()
editor.select([nodes[1]?.id ?? '', nodes[2]?.id ?? ''])
editor.bringForward()
expect(childNames(editor, pageId)).toEqual(['A', 'D', 'B', 'C'])
editor.sendBackward()
expect(childNames(editor, pageId)).toEqual(['A', 'B', 'C', 'D'])
})
test('preserves selected relative order when moving to front or back', () => {
const { editor, pageId, nodes } = setupEditor()
editor.select([nodes[0]?.id ?? '', nodes[2]?.id ?? ''])
editor.bringToFront()
expect(childNames(editor, pageId)).toEqual(['B', 'D', 'A', 'C'])
editor.sendToBack()
expect(childNames(editor, pageId)).toEqual(['A', 'C', 'B', 'D'])
})
test('records z-order changes in undo history', () => {
const { editor, pageId, nodes } = setupEditor()
editor.select([nodes[1]?.id ?? ''])
editor.bringForward()
expect(childNames(editor, pageId)).toEqual(['A', 'C', 'B', 'D'])
editor.undoAction()
expect(childNames(editor, pageId)).toEqual(['A', 'B', 'C', 'D'])
editor.redoAction()
expect(childNames(editor, pageId)).toEqual(['A', 'C', 'B', 'D'])
})
})