Files
workspace/code/fms/fms-vue/tests/unit/form-edit-panel-mount.spec.js
2026-09-27 21:59:13 +08:00

101 lines
2.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 表单设计面板(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: 2,
children: [
{
type: 'group',
id: 'group1',
title: '基本信息',
children: [
{ type: 'row', children: [{ field: 'name', span: 24, required: true }] },
{ type: 'row', children: [{ 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()
})
})