跨 tab 的「字段参与了哪些界面」在字段定义一行内表达并可就地切换, tab 结构不变。「参与是选择不是缺失」——不引入任何完整性提示。 - 语义沿用 fieldAreaDefaults 既有约定:行存在=已配置,行内开关=是否参与 (表单/列表 b_visible、查询 b_canuse);关=置 0 不删行,保留画布布局与既有查询配置 - fieldParticipation.js(纯逻辑):判定与切换;行不存在时按默认工厂生成且强制参与 (显式意愿覆盖大文本默认 参与=0),表单新行 b_colspan=24 追加到末尾序号 - fieldAreaDefaults 增加列表/查询默认行工厂,useModuleConfig.buildMissingDefaultConfigs 改用工厂——「同步字段自动补全」与「手动打开开关」生成的行结构同源 - ParticipationCell(h 渲染 ui Switch)接 FmsTable customCell;表单列仅 data 模块展示 - 新 spec field-participation 9 用例:判定/两路切换/大文本强制参与/不变性
113 lines
4.5 KiB
JavaScript
113 lines
4.5 KiB
JavaScript
/**
|
|
* 字段参与开关(fieldParticipation)测试:
|
|
* - 判定:行存在 + 行内开关(表单/列表 b_visible、查询 b_canuse),b_field_id 与 b_id 类型不一致按字符串比较
|
|
* - 切换:行为空/存在两路;关 = 置行内开关 0(不删行,保留布局/配置);开 = 行不存在时按默认生成且强制参与
|
|
* - 不变性:toggle 返回新数组、非目标行保持原引用
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import {
|
|
isFormOn,
|
|
isListOn,
|
|
isQueryOn,
|
|
toggleForm,
|
|
toggleList,
|
|
toggleQuery,
|
|
} from '@/views/system/module-management/fieldParticipation'
|
|
|
|
const MODULE_ID = 'm1'
|
|
|
|
function makeField(over = {}) {
|
|
return { b_id: '10', b_field: 'amount', b_name: '金额', b_type: 'money', b_canuse: 1, ...over }
|
|
}
|
|
|
|
describe('参与判定', () => {
|
|
const field = makeField()
|
|
|
|
it('行存在且开关为 1 即参与;行不存在不参与', () => {
|
|
expect(isFormOn([{ b_field_id: '10', b_visible: 1 }], field)).toBe(true)
|
|
expect(isFormOn([{ b_field_id: '10', b_visible: 0 }], field)).toBe(false)
|
|
expect(isFormOn([], field)).toBe(false)
|
|
expect(isListOn([{ b_field_id: 10, b_visible: 1 }], field)).toBe(true) // 类型不一致按字符串比较
|
|
expect(isQueryOn([{ b_field_id: '10', b_canuse: 1 }], field)).toBe(true)
|
|
expect(isQueryOn([{ b_field_id: '10', b_canuse: 0 }], field)).toBe(false)
|
|
})
|
|
|
|
it('空配置安全', () => {
|
|
expect(isFormOn(undefined, field)).toBe(false)
|
|
expect(isListOn(null, field)).toBe(false)
|
|
expect(isQueryOn([], field)).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('表单参与切换', () => {
|
|
it('行存在:切换 b_visible,不删行(保留布局)', () => {
|
|
const rows = [{ b_id: 'e1', b_field_id: '10', b_visible: 1, b_colspan: 12, b_group_id: 'g1' }]
|
|
const off = toggleForm(rows, makeField(), MODULE_ID)
|
|
expect(off).toHaveLength(1)
|
|
expect(off[0].b_visible).toBe(0)
|
|
expect(off[0].b_colspan).toBe(12) // 布局属性保留
|
|
expect(off[0].b_group_id).toBe('g1')
|
|
const on = toggleForm(off, makeField(), MODULE_ID)
|
|
expect(on[0].b_visible).toBe(1)
|
|
})
|
|
|
|
it('行不存在:生成默认行追加到末尾(b_visible=1、b_colspan=24、b_xh 为末尾序号)', () => {
|
|
const rows = [{ b_id: 'e1', b_field_id: '9', b_visible: 1, b_xh: 30 }]
|
|
const next = toggleForm(rows, makeField(), MODULE_ID)
|
|
expect(next).toHaveLength(2)
|
|
const created = next[1]
|
|
expect(created.b_field_id).toBe('10')
|
|
expect(created.b_visible).toBe(1)
|
|
expect(created.b_colspan).toBe(24)
|
|
expect(created.b_module_id).toBe('m1')
|
|
expect(created.b_xh).toBe(40) // 末尾追加,不排到表单最前
|
|
expect(next[0]).toBe(rows[0]) // 非目标行保持原引用
|
|
})
|
|
})
|
|
|
|
describe('列表参与切换', () => {
|
|
it('行存在:切换 b_visible(与「删除列=隐藏」语义一致)', () => {
|
|
const rows = [{ b_id: 'v1', b_field_id: '10', b_visible: 1, b_width: 110 }]
|
|
const off = toggleList(rows, makeField(), MODULE_ID)
|
|
expect(off[0].b_visible).toBe(0)
|
|
expect(off[0].b_width).toBe(110)
|
|
expect(toggleList(off, makeField(), MODULE_ID)[0].b_visible).toBe(1)
|
|
})
|
|
|
|
it('行不存在:按默认生成且强制显示(含大文本)', () => {
|
|
const textarea = makeField({ b_type: 'textarea' })
|
|
const next = toggleList([], textarea, MODULE_ID)
|
|
expect(next).toHaveLength(1)
|
|
expect(next[0].b_visible).toBe(1) // 显式意愿覆盖大文本默认不参与
|
|
expect(next[0].b_xh).toBe(10)
|
|
})
|
|
})
|
|
|
|
describe('查询参与切换', () => {
|
|
it('行存在:切换 b_canuse', () => {
|
|
const rows = [{ b_id: 'q1', b_field_id: '10', b_canuse: 0, b_operator: 'eq' }]
|
|
const on = toggleQuery(rows, makeField(), MODULE_ID)
|
|
expect(on[0].b_canuse).toBe(1)
|
|
expect(on[0].b_operator).toBe('eq') // 既有查询配置保留
|
|
expect(toggleQuery(on, makeField(), MODULE_ID)[0].b_canuse).toBe(0)
|
|
})
|
|
|
|
it('行不存在:按默认生成(money → number/eq)且强制参与', () => {
|
|
const next = toggleQuery([], makeField(), MODULE_ID)
|
|
expect(next).toHaveLength(1)
|
|
expect(next[0].b_canuse).toBe(1)
|
|
expect(next[0].b_component).toBe('number')
|
|
expect(next[0].b_operator).toBe('eq')
|
|
expect(next[0].b_field_module_id).toBe('m1')
|
|
})
|
|
})
|
|
|
|
describe('切换的不变性', () => {
|
|
it('返回新数组,不修改原数组', () => {
|
|
const rows = [{ b_id: 'e1', b_field_id: '10', b_visible: 1 }]
|
|
const next = toggleForm(rows, makeField(), MODULE_ID)
|
|
expect(next).not.toBe(rows)
|
|
expect(rows[0].b_visible).toBe(1) // 原行未被修改
|
|
})
|
|
})
|