diff --git a/__test__/layout/layout-designer.spec.ts b/__test__/layout/layout-designer.spec.ts index 0d023e09..d89f4942 100644 --- a/__test__/layout/layout-designer.spec.ts +++ b/__test__/layout/layout-designer.spec.ts @@ -2,7 +2,10 @@ import { generateLayoutSource, layoutWriteEndpoint } from '@/layout/designer' import { flushPromises, mount } from '@vue/test-utils' vi.mock('@/hooks/template/useI18n', () => ({ - useI18n: () => ({ t: (key: string) => key }), + useI18n: () => ({ + t: (key: string, params?: { row?: number }) => + typeof params?.row === 'number' ? `${key} ${params.row}` : key, + }), })) vi.mock('@/layout/useLayout', () => ({ useLayout: () => ({ layouts: { value: [{ id: 'side' }] } }), @@ -14,7 +17,7 @@ async function mountDesigner(writer: boolean) { const { default: Designer } = await import('@/views/demo/layout-lab/LayoutDesigner') - return mount(Designer) + return mount(Designer, { global: { stubs: { teleport: true } } }) } afterEach(() => { @@ -49,8 +52,17 @@ it('posts the edited visual design on the local development server and blocks du return control } - const selectRow = (value: string) => - wrapper.get('select[aria-label="position"]').setValue(value) + const selectRow = async (label: string) => { + const select = wrapper.getComponent({ name: 'Select' }) + + await select.get('.n-base-selection').trigger('click') + const option = select + .findAll('.n-base-select-option') + .find((item) => item.text() === label) + + expect.assert(option) + await option.trigger('click') + } expect(wrapper.find('[data-tile]').exists()).toBe(false) expect(wrapper.find('.layout-designer__outlet').exists()).toBe(true) @@ -63,8 +75,9 @@ it('posts the edited visual design on the local development server and blocks du .map((item) => item.text()), ).toEqual(['tabs', 'actions']) await tile('actions').trigger('click') - await selectRow('rows:0') + await selectRow('topRow 1') await action('left').trigger('click') + await selectRow('topRow 1') await action('rowDown').trigger('click') expect( wrapper diff --git a/apps/admin/src/views/demo/layout-lab/LayoutCanvas.tsx b/apps/admin/src/views/demo/layout-lab/LayoutCanvas.tsx index d8d89688..c13e538d 100644 --- a/apps/admin/src/views/demo/layout-lab/LayoutCanvas.tsx +++ b/apps/admin/src/views/demo/layout-lab/LayoutCanvas.tsx @@ -1,7 +1,8 @@ import { useI18n } from '@/hooks/template/useI18n' import { layoutBlocks } from '@/layout/designer' import type { LayoutBlock, LayoutDesign } from '@/layout/designer' -import { NButton } from 'naive-ui' +import { NButton, NSelect } from 'naive-ui' +import type { SelectGroupOption } from 'naive-ui' import type { PropType } from 'vue' import { useLayoutDraftPreview } from './useLayoutDraftPreview' @@ -44,6 +45,7 @@ export default defineComponent({ const dropAfter = ref(false) const announcement = ref('') const editor = useTemplateRef('editor') + const positionLabelId = useId() const rowsOf = (region: Region) => design[region] ?? [] const positionOf = (brick: LayoutBlock) => { for (const region of regions) { @@ -355,40 +357,49 @@ export default defineComponent({ if (!pos) return const rows = rowsOf(pos.region) + const currentRow = `${pos.region}:${pos.row}` + const options: SelectGroupOption[] = regions.map((region) => { + const regionRows = rowsOf(region) + + return { + type: 'group', + key: region, + label: t(region === 'rows' ? 'aboveContent' : 'belowContent'), + children: [ + ...regionRows.map((_, index) => ({ + label: rowName(region, index), + value: `${region}:${index}`, + })), + { + label: t(region === 'rows' ? 'newTop' : 'newBottom'), + value: `${region}:${regionRows.length}`, + }, + ], + } + }) return ( <> - + /> +