20260927215912
This commit is contained in:
1 parent
27e49e2e45
commit
f22e67fc85
294 files changed
+29247
-3576
No files matched your search
@@ -60,23 +60,58 @@ describe('schemaModel:view/edit 配置 ↔ 编辑器草稿', () => {
|
||||
expect(back.columns.find((n) => n.field === 'name').width).toBe(120)
|
||||
})
|
||||
|
||||
it('edit:span/required/readonly 与行属性互转,默认值不额外写出', () => {
|
||||
it('edit:行节点 ↔ b_line 草稿互转,span/required 保留、默认值不额外写出', () => {
|
||||
const schema = {
|
||||
schemaVersion: 1,
|
||||
schemaVersion: 2,
|
||||
children: [
|
||||
{ field: 'name', span: 12, required: true },
|
||||
{ field: 'age' },
|
||||
{
|
||||
type: 'row',
|
||||
children: [
|
||||
{ field: 'name', span: 12, required: true },
|
||||
{ field: 'age', span: 12 },
|
||||
],
|
||||
},
|
||||
{ type: 'row', children: [{ field: 'remark' }] },
|
||||
],
|
||||
}
|
||||
const { rows } = schemaToEditor('edit', schema, 'm1')
|
||||
expect(rows.map((r) => r.b_field)).toEqual(['name', 'age', 'remark'])
|
||||
expect(rows[0].b_colspan).toBe(12)
|
||||
expect(rows[0].b_required).toBe(1)
|
||||
expect(rows[1].b_colspan).toBe(24)
|
||||
expect(rows[2].b_colspan).toBe(24)
|
||||
// 同一行共用一个行 id,不同行必须不同(行是硬边界)
|
||||
expect(rows[0].b_line).toBe(rows[1].b_line)
|
||||
expect(rows[2].b_line).not.toBe(rows[0].b_line)
|
||||
|
||||
const back = editorToSchema('edit', rows, [], schema)
|
||||
expect(back.children[0]).toMatchObject({ field: 'name', span: 12, required: true })
|
||||
expect(back.schemaVersion).toBe(2)
|
||||
expect(back.children[0].type).toBe('row')
|
||||
expect(back.children[0].children[0]).toMatchObject({ field: 'name', span: 12, required: true })
|
||||
// span=24 且原节点未显式给出 → 不写出 span
|
||||
expect(back.children[1].span).toBeUndefined()
|
||||
expect(back.children[1].children[0].span).toBeUndefined()
|
||||
})
|
||||
|
||||
it('edit:老结构(平铺 + newline)加载时折成临时行,不写回 newline', () => {
|
||||
const schema = {
|
||||
schemaVersion: 1,
|
||||
children: [
|
||||
{ field: 'a', span: 8 },
|
||||
{ field: 'b', span: 8 },
|
||||
{ field: 'c', span: 8, newline: true },
|
||||
{ field: 'd', span: 24 },
|
||||
],
|
||||
}
|
||||
const { rows } = schemaToEditor('edit', schema, 'm1')
|
||||
// a b 同行(8+8=16);c 显式断行;d 放不下再折行
|
||||
expect(rows[0].b_line).toBe(rows[1].b_line)
|
||||
expect(rows[2].b_line).not.toBe(rows[1].b_line)
|
||||
expect(rows[3].b_line).not.toBe(rows[2].b_line)
|
||||
|
||||
const back = editorToSchema('edit', rows, [], schema)
|
||||
expect(back.children.map((n) => n.type)).toEqual(['row', 'row', 'row'])
|
||||
expect(back.children[0].children.map((n) => n.field)).toEqual(['a', 'b'])
|
||||
expect(back.children[1].children.map((n) => n.field)).toEqual(['c'])
|
||||
expect(JSON.stringify(back)).not.toContain('newline')
|
||||
})
|
||||
|
||||
it('未知节点扩展属性在往返中保留', () => {
|
||||
@@ -123,13 +158,19 @@ describe('schemaModel:字段参与节点操作', () => {
|
||||
expect(hasSchemaField('view', schema, 'name')).toBe(false)
|
||||
})
|
||||
|
||||
it('edit:切换 visible 保留节点', () => {
|
||||
let schema = { schemaVersion: 1, children: [{ field: 'name', span: 24 }] }
|
||||
it('edit:切换 visible 保留行节点与节点属性', () => {
|
||||
let schema = {
|
||||
schemaVersion: 2,
|
||||
children: [{ type: 'row', children: [{ field: 'name', span: 24 }] }],
|
||||
}
|
||||
expect(hasSchemaField('edit', schema, 'name', { requireVisible: true })).toBe(true)
|
||||
schema = setSchemaFieldVisible('edit', schema, 'name', false)
|
||||
expect(schema.children[0].visible).toBe(false)
|
||||
expect(schema.children[0].type).toBe('row')
|
||||
expect(schema.children[0].children[0].visible).toBe(false)
|
||||
expect(hasSchemaField('edit', schema, 'name')).toBe(true)
|
||||
expect(hasSchemaField('edit', schema, 'name', { requireVisible: true })).toBe(false)
|
||||
// 删除字段后空行节点一并消失
|
||||
expect(removeSchemaField('edit', schema, 'name').children).toEqual([])
|
||||
})
|
||||
|
||||
it('query:条件增删与默认组件', () => {
|
||||
|
||||
Reference in new issue
Block a user