openpencil/tests/engine/app/shell/menu/schema.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

58 lines
2.1 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import type { AppMenuEntry } from '@/app/shell/menu/schema'
import { APP_MENU_SCHEMA } from '@/app/shell/menu/schema'
function actionItems(entries: readonly AppMenuEntry[]): AppMenuEntry[] {
const result: AppMenuEntry[] = []
for (const entry of entries) {
if ('type' in entry && entry.type === 'separator') continue
result.push(entry)
if (entry.sub) result.push(...actionItems(entry.sub))
}
return result
}
describe('APP_MENU_SCHEMA', () => {
test('does not duplicate shortcuts for command-backed entries', () => {
const duplicated = APP_MENU_SCHEMA.flatMap((group) =>
actionItems(group.items).filter(
(entry) => !('type' in entry) && entry.command && entry.shortcut
)
)
expect(duplicated).toEqual([])
})
test('exposes every menu-backed editor command to shared dispatch', () => {
const commandIds = actionItems(APP_MENU_SCHEMA.flatMap((group) => group.items)).flatMap(
(entry) => {
if ('type' in entry || !entry.command) return []
return [entry.command]
}
)
expect(commandIds).toContain('selection.frameSelection')
expect(commandIds).toContain('selection.toggleMask')
expect(commandIds).toContain('selection.toggleVisibility')
expect(commandIds).toContain('selection.toggleLock')
expect(commandIds).toContain('selection.flipHorizontal')
expect(commandIds).toContain('selection.flipVertical')
expect(commandIds).toContain('selection.createInstance')
expect(commandIds).toContain('selection.goToMainComponent')
expect(commandIds).toContain('selection.moveToPage')
})
test('keeps move-to-page destination selection in the browser menu', () => {
const objectMenu = APP_MENU_SCHEMA.find((group) => group.label === 'Object')
const entries = objectMenu ? actionItems(objectMenu.items) : []
const moveEntries = entries.filter(
(entry) => !('type' in entry) && entry.id.startsWith('selection.moveToPage')
)
expect(moveEntries).toEqual([
expect.objectContaining({ id: 'selection.moveToPage', target: 'browser' })
])
})
})