20260917212907
This commit is contained in:
1 parent
6fa3d8535e
commit
5cbf745bbf
115 files changed
+4104
-85
No files matched your search
@@ -0,0 +1,76 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import { createTestPinia, createTestRouter } from '../helpers/app'
|
||||
import AppTopbar from '@/layouts/components/AppTopbar.vue'
|
||||
import { useI18nStore } from '@/stores/i18n'
|
||||
|
||||
vi.mock('@/services/api', () => ({
|
||||
loadDataApi: vi.fn().mockResolvedValue({ data: [] }),
|
||||
}))
|
||||
|
||||
async function mountTopbar() {
|
||||
const pinia = createTestPinia()
|
||||
const router = createTestRouter('/dashboard')
|
||||
await router.isReady()
|
||||
const wrapper = shallowMount(AppTopbar, {
|
||||
global: { plugins: [pinia, router] },
|
||||
})
|
||||
return { wrapper, i18n: useI18nStore() }
|
||||
}
|
||||
|
||||
/** 顶栏语言下拉:组件库 Dropdown 被 shallow 打桩,桩名取文件名推断的 'dropdown' */
|
||||
function languageDropdown(wrapper) {
|
||||
return wrapper
|
||||
.findAllComponents({ name: 'dropdown' })
|
||||
.find((item) => Array.isArray(item.props('items')) && item.props('items').some((i) => i.shortcut))
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
sessionStorage.clear()
|
||||
})
|
||||
|
||||
describe('顶栏语言切换', () => {
|
||||
it('语种来自 s_i18n_type 语言清单,当前语言带勾选标记', async () => {
|
||||
const { wrapper, i18n } = await mountTopbar()
|
||||
i18n.languages = [
|
||||
{ b_id: 'zh-CN', b_name: '简体中文', b_canuse: 1, b_default: 1, b_xh: 10 },
|
||||
{ b_id: 'en-US', b_name: 'English', b_canuse: 1, b_default: 0, b_xh: 20 },
|
||||
]
|
||||
i18n.setLocale('zh-CN')
|
||||
await wrapper.vm.$nextTick()
|
||||
|
||||
const items = languageDropdown(wrapper).props('items')
|
||||
expect(items.map((item) => item.key)).toEqual(['zh-CN', 'en-US'])
|
||||
expect(items.map((item) => item.label)).toEqual(['简体中文', 'English'])
|
||||
expect(items[0].shortcut).toBe('✓')
|
||||
expect(items[1].shortcut).toBe('')
|
||||
})
|
||||
|
||||
it('点击语种即切换(不再硬编码 zh-CN / en-US 互切)', async () => {
|
||||
const { wrapper, i18n } = await mountTopbar()
|
||||
i18n.languages = [
|
||||
{ b_id: 'zh-CN', b_name: '简体中文', b_canuse: 1, b_default: 1, b_xh: 10 },
|
||||
{ b_id: 'en-US', b_name: 'English', b_canuse: 1, b_default: 0, b_xh: 20 },
|
||||
]
|
||||
i18n.setLocale('zh-CN')
|
||||
await wrapper.vm.$nextTick()
|
||||
|
||||
languageDropdown(wrapper).vm.$emit('click', { key: 'en-US' })
|
||||
expect(i18n.locale).toBe('en-US')
|
||||
|
||||
// 重复点当前语种不产生变化(无副作用)
|
||||
languageDropdown(wrapper).vm.$emit('click', { key: 'en-US' })
|
||||
expect(i18n.locale).toBe('en-US')
|
||||
})
|
||||
|
||||
it('语言清单未加载时退化成只显示当前语种', async () => {
|
||||
const { wrapper, i18n } = await mountTopbar()
|
||||
i18n.languages = []
|
||||
i18n.setLocale('zh-CN')
|
||||
await wrapper.vm.$nextTick()
|
||||
|
||||
const items = languageDropdown(wrapper).props('items')
|
||||
expect(items).toEqual([{ key: 'zh-CN', label: 'zh-CN', shortcut: '✓' }])
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,9 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { afterEach, describe, it, expect } from 'vitest'
|
||||
import { h, nextTick, ref } from 'vue'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import Form from '@/components/ui/form/form.vue'
|
||||
import FormItem from '@/components/ui/form/form-item.vue'
|
||||
import { resetUIConfig, setUIConfig, uiConfig } from '@/components/ui/config'
|
||||
|
||||
const model = () =>
|
||||
ref({
|
||||
@@ -72,6 +73,60 @@ describe('Form 多列网格布局', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Form 全局配置(uiConfig)', () => {
|
||||
afterEach(() => resetUIConfig())
|
||||
|
||||
it('未传 layout 时取全局配置', () => {
|
||||
setUIConfig({ form: { layout: 'vertical' } })
|
||||
const wrapper = mountForm()
|
||||
expect(wrapper.classes()).toContain('fms-form-vertical')
|
||||
expect(wrapper.findComponent(FormItem).classes()).toContain('fms-form-item-vertical')
|
||||
})
|
||||
|
||||
it('显式 layout 覆盖全局配置', () => {
|
||||
setUIConfig({ form: { layout: 'vertical' } })
|
||||
const wrapper = mountForm(1, { layout: 'horizontal' })
|
||||
expect(wrapper.classes()).toContain('fms-form-horizontal')
|
||||
expect(wrapper.findComponent(FormItem).classes()).not.toContain('fms-form-item-vertical')
|
||||
})
|
||||
|
||||
it('setUIConfig 局部合并,未提及的键保持原值', () => {
|
||||
setUIConfig({ form: { labelAlign: 'left' } })
|
||||
expect(uiConfig.form.labelAlign).toBe('left')
|
||||
expect(uiConfig.form.layout).toBe('horizontal')
|
||||
setUIConfig({ form: { layout: 'vertical' } })
|
||||
expect(uiConfig.form.labelAlign).toBe('left')
|
||||
})
|
||||
|
||||
it('全局 validateTrigger 生效:change 改为 blur 后值变化不立即报红', async () => {
|
||||
setUIConfig({ form: { validateTrigger: 'blur' } })
|
||||
const model = ref({ code: '' })
|
||||
const wrapper = mount(Form, {
|
||||
props: { model: model.value, rules: { code: [{ required: true, message: '必填' }] } },
|
||||
slots: {
|
||||
default: () => [
|
||||
h(FormItem, { name: 'code', label: '编码' }, { default: () => h('input') }),
|
||||
],
|
||||
},
|
||||
})
|
||||
model.value.code = 'a'
|
||||
await nextTick()
|
||||
model.value.code = ''
|
||||
await nextTick()
|
||||
await flushPromises()
|
||||
expect(wrapper.findComponent(FormItem).classes()).not.toContain('fms-form-item-error')
|
||||
})
|
||||
|
||||
it('独立使用的 FormItem(无 Form 包裹)也读全局 layout', () => {
|
||||
setUIConfig({ form: { layout: 'vertical' } })
|
||||
const wrapper = mount(FormItem, {
|
||||
props: { name: 'code', label: '编码' },
|
||||
slots: { default: () => h('input') },
|
||||
})
|
||||
expect(wrapper.classes()).toContain('fms-form-item-vertical')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Form 必填校验与 FormItem 错误展示', () => {
|
||||
function mountRequiredForm(rules, modelValue = { code: '' }) {
|
||||
const model = ref(modelValue)
|
||||
|
||||
Reference in new issue
Block a user