100 lines
2.7 KiB
JavaScript
100 lines
2.7 KiB
JavaScript
/**
|
||
* 表单设计面板(ModuleEditPanel → FormDesignEditor)挂载回归(V2:edit JSON 节点模型)。
|
||
* 覆盖:空配置挂载、已有配置切换为空草稿(新建模块序列)均不触发递归更新。
|
||
*/
|
||
import { mount } from '@vue/test-utils'
|
||
import { beforeAll, describe, expect, it, vi } from 'vitest'
|
||
import { createPinia, setActivePinia } from 'pinia'
|
||
import { registerFeature, useAreaSelection } from 'stk-table-vue'
|
||
import ModuleEditPanel from '@/views/module/module-management/ModuleEditPanel.vue'
|
||
|
||
registerFeature(useAreaSelection)
|
||
|
||
beforeAll(() => {
|
||
Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
|
||
configurable: true,
|
||
get() {
|
||
return 5000
|
||
},
|
||
})
|
||
})
|
||
|
||
vi.mock('@/services/api', () => ({
|
||
loadDataApi: vi.fn(async () => ({ data: [] })),
|
||
saveObjectApi: vi.fn(),
|
||
nextIdApi: vi.fn(),
|
||
describeApi: vi.fn(async () => ({ data: [] })),
|
||
}))
|
||
|
||
const StubDraggable = {
|
||
name: 'draggable',
|
||
props: {
|
||
list: { type: Array, default: () => [] },
|
||
itemKey: { type: String, default: undefined },
|
||
},
|
||
emits: ['start', 'end'],
|
||
template: `
|
||
<div class="stub-draggable">
|
||
<template v-for="el in list" :key="el[itemKey || 'key']">
|
||
<slot name="item" :element="el" />
|
||
</template>
|
||
<slot name="footer" />
|
||
</div>
|
||
`,
|
||
}
|
||
|
||
const fields = [
|
||
{ b_field: 'name', b_name: '姓名', b_type: 'input' },
|
||
{ b_field: 'age', b_name: '年龄', b_type: 'number' },
|
||
]
|
||
|
||
const filledSchema = {
|
||
schemaVersion: 1,
|
||
children: [
|
||
{
|
||
type: 'group',
|
||
title: '基本信息',
|
||
children: [
|
||
{ field: 'name', span: 24, required: true },
|
||
{ field: 'age', span: 24 },
|
||
],
|
||
},
|
||
],
|
||
}
|
||
|
||
function mountPanel(modelValue) {
|
||
return mount(ModuleEditPanel, {
|
||
props: {
|
||
moduleId: 'm1',
|
||
modelValue,
|
||
fields,
|
||
active: true,
|
||
loading: false,
|
||
},
|
||
global: { stubs: { draggable: StubDraggable } },
|
||
})
|
||
}
|
||
|
||
describe('ModuleEditPanel 挂载', () => {
|
||
it('空配置挂载不触发递归更新', async () => {
|
||
setActivePinia(createPinia())
|
||
const wrapper = mountPanel({ schemaVersion: 1, children: [] })
|
||
await wrapper.vm.$nextTick()
|
||
await wrapper.vm.$nextTick()
|
||
expect(wrapper.exists()).toBe(true)
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('已有配置切换为空草稿(新建模块序列)不触发递归更新', async () => {
|
||
setActivePinia(createPinia())
|
||
const wrapper = mountPanel(filledSchema)
|
||
await wrapper.vm.$nextTick()
|
||
await wrapper.vm.$nextTick()
|
||
await wrapper.setProps({ modelValue: { schemaVersion: 1, children: [] }, fields: [] })
|
||
await wrapper.vm.$nextTick()
|
||
await new Promise((r) => setTimeout(r, 30))
|
||
expect(wrapper.exists()).toBe(true)
|
||
wrapper.unmount()
|
||
})
|
||
})
|