20260903173038

This commit is contained in:
oneao committed 2026-09-03 17:30:39 +08:00
1 parent c8940f6e03
commit 0faf44cffc
55 files changed
+3278 -208

No files matched your search

@@ -3,8 +3,8 @@ import { describe, expect, it, vi, beforeAll, beforeEach } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import { nextTick } from 'vue'
import { registerFeature, useAreaSelection } from 'stk-table-vue'
import ModuleQueryConfigPanel from '@/views/system/module-management/ModuleQueryConfigPanel.vue'
import ModuleI18nPanel from '@/views/system/module-management/ModuleI18nPanel.vue'
import ModuleQueryConfigPanel from '@/views/module/module-management/ModuleQueryConfigPanel.vue'
import ModuleI18nPanel from '@/views/module/module-management/ModuleI18nPanel.vue'
registerFeature(useAreaSelection)
@@ -12,7 +12,7 @@ import {
toggleForm,
toggleList,
toggleQuery,
} from '@/views/system/module-management/composables/fieldParticipation'
} from '@/views/module/module-management/composables/fieldParticipation'
const MODULE_ID = 'm1'
@@ -5,7 +5,7 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it, vi } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import ModuleFormEditPanel from '@/views/system/module-management/components/form-edit/FormEditPanel.vue'
import ModuleFormEditPanel from '@/views/module/module-management/components/form-edit/FormEditPanel.vue'
vi.mock('@/services/api', () => ({
loadDataApi: vi.fn(async () => ({ data: [] })),
@@ -8,7 +8,7 @@
*/
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { ref } from 'vue'
import { useModuleConfig } from '@/views/system/module-management/composables/useModuleConfig'
import { useModuleConfig } from '@/views/module/module-management/composables/useModuleConfig'
vi.mock('@/services/api', () => ({
loadDataApi: vi.fn(),
@@ -9,7 +9,7 @@ import { beforeAll, describe, expect, it, vi } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import { nextTick } from 'vue'
import { registerFeature, useAreaSelection } from 'stk-table-vue'
import ModuleFieldsPanel from '@/views/system/module-management/components/ModuleFieldsPanel.vue'
import ModuleFieldsPanel from '@/views/module/module-management/components/ModuleFieldsPanel.vue'
// 与 main.js 一致:注册 stk-table 的按需 feature
registerFeature(useAreaSelection)
@@ -0,0 +1,28 @@
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it } from 'vitest'
import FmsQueryControl from '@/components/fms-module-list/FmsQueryControl.vue'
import FmsQueryToolbar from '@/components/fms-module-list/FmsQueryToolbar.vue'
describe('fms-module-list components', () => {
beforeEach(() => setActivePinia(createPinia()))
it('mounts a text query control with the new UI kit', () => {
const wrapper = mount(FmsQueryControl, {
props: {
item: {
field: { b_field: 'name', b_type: 'input' },
config: { b_operator: 'like', b_component: 'input' },
},
modelValue: '',
},
})
expect(wrapper.find('input').exists()).toBe(true)
})
it('mounts an empty toolbar without legacy Ant components', () => {
const wrapper = mount(FmsQueryToolbar)
expect(wrapper.find('.fms-query-toolbar').exists()).toBe(true)
expect(wrapper.html()).not.toContain('<a-')
})
})
@@ -1,7 +1,7 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it, vi, beforeEach } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import ModuleListConfigPanel from '@/views/system/module-management/components/ModuleListConfigPanel.vue'
import ModuleListConfigPanel from '@/views/module/module-management/components/ModuleListConfigPanel.vue'
/**
* 列表配置面板与子表设计共用 useStructureEditing / ModuleStructureTree / TablePreview,
@@ -0,0 +1,71 @@
import { describe, expect, it } from 'vitest'
import {
buildQueryCondition,
defaultQueryValue,
formatDateValue,
parseOptions,
} from '@/components/fms-module-list/moduleListUtils'
import { setMessages, translate } from '@/utils/translate'
function item(over = {}) {
return {
field: { b_field: 'amount', b_type: 'money', b_options: '' },
config: { b_operator: 'eq', b_component: 'number' },
...over,
}
}
describe('fms-module-list query utilities', () => {
it('uses a standalone translation catalog and fallback text', () => {
setMessages({ 'common.search': '查询' }, 'zh-CN')
expect(translate('common.search', '搜索')).toBe('查询')
expect(translate('common.reset', '重置')).toBe('重置')
setMessages({})
})
it('builds numeric and escaped text conditions', () => {
expect(buildQueryCondition(item(), 12.5)).toBe('[amount] = 12.5')
expect(
buildQueryCondition(
item({ field: { b_field: 'name', b_type: 'input' }, config: { b_operator: 'like' } }),
"O'Reilly",
),
).toBe("[name] LIKE N'%O''Reilly%'")
})
it('builds range and IN conditions while ignoring empty values', () => {
expect(
buildQueryCondition(
item({ field: { b_field: 'created', b_type: 'date' }, config: { b_operator: 'between' } }),
['2026-01-01', '2026-01-31'],
),
).toBe("[created] BETWEEN N'2026-01-01' AND N'2026-01-31'")
expect(
buildQueryCondition(
item({ field: { b_field: 'status', b_type: 'input' }, config: { b_operator: 'in' } }),
['a', '', 'b'],
),
).toBe("[status] IN (N'a', N'b')")
})
it('parses options and normalizes defaults', () => {
const parsed = parseOptions({ b_options: '{"options":[{"key":"1","name":"启用"},"2"]}' })
expect(parsed.options).toEqual([
{ key: '1', name: '启用', value: '1', label: '启用' },
{ value: '2', label: '2' },
])
expect(
defaultQueryValue(
item({
field: { b_field: 'status', b_type: 'input' },
config: { b_operator: 'in', b_default_value: 'a,b' },
}),
),
).toEqual(['a', 'b'])
})
it('formats ISO dates consistently', () => {
expect(formatDateValue('2026-08-01T12:34:56Z')).toMatch(/^2026-08-01/)
expect(formatDateValue(null)).toBe('')
})
})
@@ -9,7 +9,7 @@
*/
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { ref } from 'vue'
import { useModuleSave } from '@/views/system/module-management/composables/useModuleSave'
import { useModuleSave } from '@/views/module/module-management/composables/useModuleSave'
import { saveObjectApi, nextIdApi } from '@/services/api'
import { Message } from '@/components/ui'
@@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils'
import { nextTick } from 'vue'
import { describe, expect, it, vi, beforeEach } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import ModuleTableEditPanel from '@/views/system/module-management/components/table-edit/TableEditPanel.vue'
import ModuleTableEditPanel from '@/views/module/module-management/components/table-edit/TableEditPanel.vue'
/**
* 专用结构树组件 ModuleStructureTree 的状态驱动拖拽,在结构树内完成全部落点
@@ -35,10 +35,10 @@ function makeStub(label) {
}
vi.mock('@/views/dashboard/index.vue', () => ({ default: makeStub('Dashboard') }))
vi.mock('@/views/system/module-management/index.vue', () => ({
vi.mock('@/views/module/module-management/index.vue', () => ({
default: makeStub('ModuleManagement'),
}))
vi.mock('@/views/system/menu-management/index.vue', () => ({
vi.mock('@/views/module/menu-management/index.vue', () => ({
default: makeStub('MenuManagement'),
}))
vi.mock('@/views/detail/DetailPage.vue', () => ({
@@ -90,7 +90,7 @@ describe('页面 keep-alive 缓存', () => {
expect(counters.Dashboard.mounts).toBe(1)
// 进入模块管理,点两下按钮制造页面状态
await router.push('/system/module-management')
await router.push('/module/module-management')
await flushPromises()
expect(counters.ModuleManagement.mounts).toBe(1)
const inc = () => wrapper.find('[data-page="ModuleManagement"] [data-inc]').trigger('click')
@@ -99,12 +99,12 @@ describe('页面 keep-alive 缓存', () => {
expect(wrapper.find('[data-page="ModuleManagement"]').text()).toContain('#2')
// 切到菜单管理再切回:不重新挂载,clicks 仍为 2
await router.push('/system/menu-management')
await router.push('/module/menu-management')
await flushPromises()
expect(counters.ModuleManagement.unmounted).toBe(0)
expect(counters.ModuleManagement.deactivated).toBe(1)
await router.push('/system/module-management')
await router.push('/module/module-management')
await flushPromises()
expect(counters.ModuleManagement.mounts).toBe(1)
expect(counters.ModuleManagement.unmounted).toBe(0)
@@ -113,19 +113,19 @@ describe('页面 keep-alive 缓存', () => {
// 再绕经工作台切回:缓存依旧(包装组件不得依赖当前路由)
await router.push('/dashboard')
await flushPromises()
await router.push('/system/menu-management')
await router.push('/module/menu-management')
await flushPromises()
await router.push('/system/module-management')
await router.push('/module/module-management')
await flushPromises()
expect(counters.ModuleManagement.mounts).toBe(1)
expect(wrapper.find('[data-page="ModuleManagement"]').text()).toContain('#2')
// 关闭页签后缓存销毁:重新进入应重新挂载
const appStore = useAppStore()
appStore.removeVisitedTab('/system/module-management')
appStore.removeVisitedTab('/module/module-management')
await router.push('/dashboard')
await flushPromises()
await router.push('/system/module-management')
await router.push('/module/module-management')
await flushPromises()
expect(counters.ModuleManagement.mounts).toBe(2)
expect(wrapper.find('[data-page="ModuleManagement"]').text()).toContain('#0')
@@ -160,13 +160,13 @@ describe('页面 keep-alive 缓存', () => {
it('双击页签刷新:页面组件重新挂载、状态归零(缓存槽位不变)', async () => {
const wrapper = await mountApp()
await router.push('/system/module-management')
await router.push('/module/module-management')
await flushPromises()
await wrapper.find('[data-page="ModuleManagement"] [data-inc]').trigger('click')
expect(wrapper.find('[data-page="ModuleManagement"]').text()).toContain('#1')
const appStore = useAppStore()
appStore.refreshRoute('/system/module-management')
appStore.refreshRoute('/module/module-management')
await flushPromises()
expect(counters.ModuleManagement.mounts).toBe(2)
@@ -8,7 +8,7 @@
*/
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { flushPromises } from '@vue/test-utils'
import MenuManagement from '@/views/system/menu-management/index.vue'
import MenuManagement from '@/views/module/menu-management/index.vue'
import { mountPage } from '../helpers/app.js'
vi.mock('@/services/api', () => ({