20260923165454
This commit is contained in:
1 parent
0abe3706c8
commit
e6935b8fa4
173 files changed
+14975
-2295
No files matched your search
@@ -1,13 +1,12 @@
|
||||
/**
|
||||
* 界面配置 JSON → 运行时渲染配置 适配层测试(fms-module-common/schemaRender)。
|
||||
* 覆盖 view→列表列、edit→分组/编辑行、query→查询条件,以及栏位设置回写 JSON。
|
||||
* 覆盖 view→列表列、edit→分组/编辑行、query→查询入口,以及栏位设置回写 JSON。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
buildListConfig,
|
||||
buildEditRender,
|
||||
buildQueryRender,
|
||||
orderQueryConditions,
|
||||
applyColumnSettings,
|
||||
} from '@/components/fms-module-common/schemaRender'
|
||||
import { parseOptions } from '@/components/fms-module-common/fieldUtils'
|
||||
@@ -75,32 +74,78 @@ describe('buildEditRender(edit JSON → 分组 + 编辑行)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildQueryRender / orderQueryConditions(query JSON → 查询条件)', () => {
|
||||
describe('buildQueryRender(query JSON → 查询入口)', () => {
|
||||
const fields = [
|
||||
{ b_field: 'b_no', b_name: '单号', b_type: 'input' },
|
||||
{ b_field: 'b_status', b_name: '状态', b_type: 'select' },
|
||||
{ b_field: 'b_created', b_name: '创建时间', b_type: 'datetime' },
|
||||
{ b_field: 'b_denied', b_name: '无权限字段', b_type: 'input' },
|
||||
]
|
||||
const query = {
|
||||
schemaVersion: 1,
|
||||
quick: ['b_status'],
|
||||
groups: [
|
||||
{
|
||||
logic: 'and',
|
||||
conditions: [
|
||||
{ field: 'b_no', operator: 'like' },
|
||||
{ field: 'b_status', operator: 'eq', component: 'select', defaultValue: '1' },
|
||||
],
|
||||
},
|
||||
schemaVersion: 2,
|
||||
defaultViewCode: 'pending',
|
||||
views: [
|
||||
{ code: 'all', label: '全部', order: 20 },
|
||||
{ code: 'pending', label: '待处理', order: 10, showCount: true,
|
||||
conditions: [{ field: 'b_status', operator: 'eq', value: '1' }] },
|
||||
{ code: 'ghost', label: '幽灵页签', order: 30,
|
||||
conditions: [{ field: 'b_denied', operator: 'eq', value: 'x' }] },
|
||||
],
|
||||
keywordSearch: { placeholder: '搜索', trigger: 'enter_or_debounce', fields: ['b_no', 'b_denied'] },
|
||||
quickFilters: [
|
||||
{ field: 'b_created', order: 20 },
|
||||
{ field: 'b_status', order: 10 },
|
||||
{ field: 'b_denied', order: 30 },
|
||||
],
|
||||
filterGroups: [
|
||||
{ code: 'basic', label: '基础', order: 10, fields: ['b_no', 'b_status', 'b_denied'] },
|
||||
{ code: 'time', label: '时间', order: 20, fields: ['b_created'] },
|
||||
],
|
||||
queryFields: {
|
||||
b_status: { component: 'select', operator: 'eq' },
|
||||
b_created: { component: 'datetime', operator: 'between' },
|
||||
},
|
||||
}
|
||||
|
||||
it('展开条件并透出 quick', () => {
|
||||
const { quick, conditions } = buildQueryRender(query)
|
||||
expect(quick).toEqual(['b_status'])
|
||||
expect(conditions.map((c) => c.field)).toEqual(['b_no', 'b_status'])
|
||||
expect(conditions[1]).toMatchObject({ operator: 'eq', component: 'select', defaultValue: '1' })
|
||||
it('产出页签 / 关键词 / 快捷筛选 / 分组,条目按 order 排序', () => {
|
||||
const render = buildQueryRender(query, fields)
|
||||
expect(render.views.map((v) => [v.code, v.showCount])).toEqual([
|
||||
['pending', true],
|
||||
['all', false],
|
||||
['ghost', false],
|
||||
])
|
||||
expect(render.defaultViewCode).toBe('pending')
|
||||
expect(render.quickFilters.map((item) => item.field.b_field)).toEqual(['b_status', 'b_created'])
|
||||
expect(render.filterGroups.map((g) => g.code)).toEqual(['basic', 'time'])
|
||||
expect(render.keywordSearch.items.map((item) => item.field.b_field)).toEqual(['b_no'])
|
||||
})
|
||||
|
||||
it('quick 字段优先排序', () => {
|
||||
const { quick, conditions } = buildQueryRender(query)
|
||||
const ordered = orderQueryConditions(conditions, quick)
|
||||
expect(ordered.map((c) => c.field)).toEqual(['b_status', 'b_no'])
|
||||
it('字段项统一为 FmsQueryControl 消费的形状,算子缺省按字段类型推导', () => {
|
||||
const render = buildQueryRender(query, fields)
|
||||
const statusItem = render.quickFilters[0]
|
||||
expect(statusItem.config).toMatchObject({ b_field: 'b_status', b_component: 'select', b_operator: 'eq' })
|
||||
const createdItem = render.filterGroups[1].items[0]
|
||||
expect(createdItem.config.b_operator).toBe('between')
|
||||
// queryFields 未登记的字段按 b_type 推导:input → like
|
||||
const noItem = render.filterGroups[0].items[0]
|
||||
expect(noItem.config.b_operator).toBe('like')
|
||||
})
|
||||
|
||||
it('无权限字段不进任何入口;引用它的页签整条丢弃', () => {
|
||||
const render = buildQueryRender(query, fields, new Set(['b_no', 'b_status', 'b_created']))
|
||||
expect(render.views.map((v) => v.code)).toEqual(['pending', 'all'])
|
||||
expect(render.quickFilters.map((item) => item.field.b_field)).toEqual(['b_status', 'b_created'])
|
||||
expect(render.keywordSearch).toBeNull()
|
||||
expect(render.filterGroups[0].items.map((item) => item.field.b_field)).toEqual(['b_no', 'b_status'])
|
||||
})
|
||||
|
||||
it('未配置查询时返回空结构', () => {
|
||||
const render = buildQueryRender(null, fields)
|
||||
expect(render.views).toEqual([])
|
||||
expect(render.defaultViewCode).toBe('')
|
||||
expect(render.keywordSearch).toBeNull()
|
||||
expect(render.quickFilters).toEqual([])
|
||||
expect(render.filterGroups).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user