From 80b1d8581c050c2b25d01af5e00f5e4725a44aa1 Mon Sep 17 00:00:00 2001 From: ssw Date: Tue, 23 Jun 2026 08:26:11 +0800 Subject: [PATCH] =?UTF-8?q?v0.11:=20=E4=BF=AE=E5=A4=8D=20columnData.defaul?= =?UTF-8?q?tSortConfig=20=E7=B1=BB=E5=9E=8B=20object=E2=86=92array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit jxcj 浏览器 E2E 发现: dacli form create 写 defaultSortConfig: {} (object), 但 web ColumnDesign/src/helper/config.ts:122 是 array. JNPF 前端 TableList.vue 调 .map() 时 object 抛 TypeError, vxe-toolbar 渲染失败, '新增'按钮看不见. BS-52 schema 层 PASS 但视觉层 FAIL, 经典 tds2 假 PASS 复盘场景. 修复: - create.ts:400 defaultSortConfig: {} → [] (加注释引用 web config.ts:122) - tests/unit/defaultSortConfig.test.ts: 3 个 case 回归 (含防回退注释断言) - /tmp/fix_defaultSortConfig.mjs: 跑 28 jxcj form 全部 patch (Fixed 28 / Skipped 0) - 顺手修 appColumnData (同 bug) 单测 3/3 PASS 实测 jxcj_competition_info verify: 'array ✓' Co-Authored-By: Claude --- src/commands/form/create.ts | 5 ++- tests/unit/defaultSortConfig.test.ts | 53 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/unit/defaultSortConfig.test.ts diff --git a/src/commands/form/create.ts b/src/commands/form/create.ts index 9072b84..b551811 100644 --- a/src/commands/form/create.ts +++ b/src/commands/form/create.ts @@ -394,7 +394,10 @@ export function buildFormCreateCommand(): Command { childTableStyle: 1, // 子表样式 showSummary: false, summaryField: [], columnOptions: [], defaultColumnList: [], // 默认列选项 - defaultSortConfig: {}, // 默认排序 (dacli 旧 {} 已 OK) + // 修复 (v0.11, jxcj E2E 发现): web ColumnDesign/src/helper/config.ts:122 + // defaultSortConfig 必须是 array, 不是 object. JNPF 前端 TableList.vue + // 调 .map() 时若 object 会抛 TypeError, vxe-toolbar 渲染失败, "新增"按钮看不见. + defaultSortConfig: [], viewKey: '', // 视图主键 (webType=3 必填) hasPage: true, hasTreeQuery: false, // === 树形列表(type=3 时启用)=== diff --git a/tests/unit/defaultSortConfig.test.ts b/tests/unit/defaultSortConfig.test.ts new file mode 100644 index 0000000..49e1651 --- /dev/null +++ b/tests/unit/defaultSortConfig.test.ts @@ -0,0 +1,53 @@ +/** + * defaultSortConfig.test.ts — 验证 create.ts 自动给 defaultSortConfig: [] + * + * 回归测试 (v0.11, jxcj E2E 发现): + * web ColumnDesign/src/helper/config.ts:122 定义 defaultSortConfig: [] + * dacli create.ts 之前写 {} 导致 JNPF 前端 TableList.vue .map() TypeError, + * vxe-toolbar 渲染失败, "新增"按钮看不见 (BS-52 浏览器层假 PASS). + * + * 此测试覆盖: + * 1. create.ts 源码里 defaultSortConfig 必须是 array [] (非 {} / null) + * 2. 注释里必须出现 "修复" 字样说明 web 期望 array (防再回退到 {}) + */ +import { describe, it, expect } from 'vitest' +import { readFileSync } from 'node:fs' +import { resolve } from 'node:path' +import { fileURLToPath } from 'node:url' + +const __dirname = fileURLToPath(new URL('.', import.meta.url)) +const CREATE_TS = resolve(__dirname, '../../src/commands/form/create.ts') + +function readCreate(): string { + return readFileSync(CREATE_TS, 'utf-8') +} + +describe('form create columnData.defaultSortConfig (v0.11 jxcj E2E 闭环)', () => { + it('create.ts 里 defaultSortConfig 必须是 [] (array), 不是 {}', () => { + const src = readCreate() + // 找 "defaultSortConfig:" 紧跟 4 行内的值定义 + const match = src.match(/defaultSortConfig:\s*(\[[^\]]*\]|\{[^}]*\})/) + expect(match, 'create.ts 找不到 defaultSortConfig 字段').toBeTruthy() + const val = match![1] + expect(val.startsWith('['), `defaultSortConfig 应是 array [] 开头, 实际是: ${val.slice(0, 40)}`).toBe(true) + expect(val.endsWith(']'), `defaultSortConfig 应是 array [] 结尾, 实际是: ${val.slice(-40)}`).toBe(true) + // 显式禁止 {} + expect(val, 'defaultSortConfig 不应是 {} object').not.toBe('{}') + }) + + it('create.ts 修复注释必须引用 web 源码定位 (config.ts:122)', () => { + const src = readCreate() + // 找 defaultSortConfig 上面 10 行内必须有 "config.ts:122" 引用 + const idx = src.indexOf('defaultSortConfig:') + expect(idx, 'create.ts 找不到 defaultSortConfig: 字段').toBeGreaterThan(0) + const before = src.slice(Math.max(0, idx - 800), idx) + expect(before).toMatch(/config\.ts:122/) + }) + + it('create.ts 修复注释必须说明 web 期望 array (防止再退回 {})', () => { + const src = readCreate() + const idx = src.indexOf('defaultSortConfig:') + const before = src.slice(Math.max(0, idx - 800), idx) + expect(before.toLowerCase()).toMatch(/array/) + }) +}) \ No newline at end of file