ray-template/__test__/layout/layout-picker.spec.ts
XiaoDaiGua-Ray 22dfe441e0
feat(layout): add a composable workspace designer
Add layout registration, visual editing, and source generation.

Preserve embedded pages and wait for asynchronous layout renderers.

Add workspace lint and formatting commands.
2026-12-01 17:34:27 +08:00

89 lines
2.4 KiB
TypeScript

import {
LayoutSettings,
type LayoutConfig,
type LayoutPreview,
} from '@ray-template/admin-shell'
import { mount } from '@vue/test-utils'
const layout: LayoutConfig = {
mode: 'side',
contentWidth: 'fluid',
contentMaxWidth: 1200,
contentPadding: 16,
fixedHeader: true,
fixedFooter: true,
}
const props = {
layout,
defaults: layout,
translate: (key: string) => key,
}
it('draws the registered rows, sidebar and bottom blocks in reading order', async () => {
const preview: LayoutPreview = {
rows: [['actions', 'breadcrumb']],
bottomRows: [['tabs', 'navigation']],
sidebar: 'right',
}
const onSelect = vi.fn()
const wrapper = mount(LayoutSettings, {
props: {
...props,
update: vi.fn(),
onSelect,
selectedId: 'workspace',
choices: [{ id: 'workspace', label: 'Workspace', preview }],
},
})
try {
const choice = wrapper.get('button[aria-label="Workspace"]')
const diagram = choice.get('.r-layout-preview__main')
const rows = diagram.findAll('.r-layout-preview__row')
expect(choice.attributes('aria-pressed')).toBe('true')
expect(diagram.element.nextElementSibling?.className).toBe(
'r-layout-preview__aside',
)
expect(rows[0].element.firstElementChild?.className).toBe(
'r-layout-preview__actions',
)
expect(rows[1].element.previousElementSibling?.className).toBe(
'r-layout-preview__body',
)
expect(rows[1].element.lastElementChild?.className).toBe(
'r-layout-preview__navigation',
)
expect(diagram.find('.r-layout-preview__footer').exists()).toBe(false)
await choice.trigger('click')
expect(onSelect).toHaveBeenCalledWith('workspace')
} finally {
wrapper.unmount()
}
})
it('retains the built-in mode selector when no registry choices are supplied', async () => {
const update = vi.fn()
const wrapper = mount(LayoutSettings, { props: { ...props, update } })
try {
const button = wrapper.get('button[aria-label="split"]')
expect(
button.findAll('.r-layout-preview > .r-layout-preview__row'),
).toHaveLength(2)
expect(
button
.get('.r-layout-preview__main')
.find('.r-layout-preview__tabs')
.exists(),
).toBe(true)
expect(button.find('.r-layout-preview__footer').exists()).toBe(true)
await button.trigger('click')
expect(update).toHaveBeenCalledWith({ mode: 'split' })
} finally {
wrapper.unmount()
}
})