Files
dacli/tests/unit/codegen_snake_to_pascal.test.ts
T
sswandClaude ff5ec01184 feat(dacli): P0a-P3 全套完善 (auto-alias 默认 + 绝对路径 + DM 去前缀 + 命名小写)
P0a: --auto-alias 默认开 + --no-auto-alias 显式关闭
  原因: 不写别名 → JNPF 类名 = Jxcj_xxx_xxxMapper (历史包袱, 验证过 28 form)
  写别名 → JNPF PascalCase 类名 (AnnouncementMapper), 0 post-fix
  推荐保留默认 ON, --no-auto-alias 显式关闭

P0b: web/uniapp 路径绝对化
  读 $CCWORKDIR env (默认 /home/ubuntu/ccWorkDir) 拼绝对路径
  不再相对 cwd 写, 用户在哪个目录跑都安全
  用户可显式 --web-base=... --uniapp-base=... 覆盖

P1a: dm create 去 appCode 前缀 (CLAUDE.md §3)
  jxcj_announcement → announcement (无前缀)
  字段同步去前缀 (jxcj_xxx → xxx, f_xxx 不动)
  已有老表带前缀也允许 (向后兼容); 新建推荐无前缀

P1b: snakeToPascalCase 单测
  tests/unit/codegen_snake_to_pascal.test.ts: 23 case (含 jxcj 28 form 实际 enCode 回归)
  tests/unit/alias_field.test.ts: 5 case (字段级 alias 透传)
  全 28/28 PASS

P2a: web 命名大写 → 小写
  Detail.vue / Form.vue → detail.vue / form.vue
  对齐现有 jxcj/TeamInfo 约定 (lowercase Vue 3 社区规范)
  同步改内容里 import 引用 (./Detail.vue → ./detail.vue)
  例外: .ts .js 不改 (columnList.ts 等 PascalCase 也常见)

P2b: 字段级 alias
  formTables.fields 含 aliasName 时透传到 Alias/Save
  (实现已在, 单测固化; 实际数据来自 JNPF form design)

P3: xml/vue Velocity 占位符修复
  实测 jxcj 28 form: vue + xml 0 残留, 仅 .java 触发
  加 debug log 监测 xml/vue (防未来模板变动)
  .xml 中 ${} 是 MyBatis SQL 参数, .vue 模板用 {{ }}, 不自动改

测试: 28/28 PASS
- snakeToPascalCase: 23/23 PASS
- alias_field: 5/5 PASS
- 端到端 28 form codegen: 28/28 PASS
- 后端 280 java 编译 SUCCESS
- 运行时 3/3 jxcj visualdev API → HTTP 200

Co-Authored-By: Claude <[email protected]>
2026-06-24 10:16:50 +08:00

85 lines
3.1 KiB
TypeScript

// dacli/tests/unit/codegen_snake_to_pascal.test.ts
/**
* snakeToPascalCase 单元测试 (P1b 2026-06-24 固化)
*
* 覆盖:
* - 丢 appCode 前缀 (jxcj_xxx → Xxx)
* - PascalCase 输入原样保留
* - 单段输入 (jxcj → Jxcj)
* - 极端 case (空 / 纯下划线)
*
* 防止 v0.10+ 命名规则回归
*/
import { describe, it, expect } from 'vitest'
import { snakeToPascalCase } from '../../src/commands/form/codegen'
describe('snakeToPascalCase (P1b)', () => {
describe('丢 appCode 前缀 (主要场景)', () => {
it('jxcj_announcement + jxcj → Announcement', () => {
expect(snakeToPascalCase('jxcj_announcement', 'jxcj')).toBe('Announcement')
})
it('jxcj_develop_project + jxcj → DevelopProject', () => {
expect(snakeToPascalCase('jxcj_develop_project', 'jxcj')).toBe('DevelopProject')
})
it('jxcj_notification_record + jxcj → NotificationRecord', () => {
expect(snakeToPascalCase('jxcj_notification_record', 'jxcj')).toBe('NotificationRecord')
})
it('tds_billing + tds → Billing', () => {
expect(snakeToPascalCase('tds_billing', 'tds')).toBe('Billing')
})
it('tds_sandbox_config + tds → SandboxConfig', () => {
expect(snakeToPascalCase('tds_sandbox_config', 'tds')).toBe('SandboxConfig')
})
it('大小写不敏感匹配: Jxcj_xxx + jxcj → Xxx', () => {
expect(snakeToPascalCase('Jxcj_announcement', 'jxcj')).toBe('Announcement')
})
})
describe('PascalCase 输入原样保留', () => {
it('JxcjAnnouncement (无 _) → 原样', () => {
expect(snakeToPascalCase('JxcjAnnouncement', 'jxcj')).toBe('JxcjAnnouncement')
})
it('TdsBilling → 原样', () => {
expect(snakeToPascalCase('TdsBilling', undefined)).toBe('TdsBilling')
})
it('不传 appCode 不破坏 PascalCase', () => {
expect(snakeToPascalCase('TdsBilling', 'jxcj')).toBe('TdsBilling')
})
})
describe('边缘 case', () => {
it('单段 + appCode 匹配: jxcj + jxcj → Jxcj', () => {
expect(snakeToPascalCase('jxcj', 'jxcj')).toBe('Jxcj')
})
it('单段无 appCode: hello → Hello', () => {
expect(snakeToPascalCase('hello', undefined)).toBe('Hello')
})
it('空字符串 → 空字符串', () => {
expect(snakeToPascalCase('', undefined)).toBe('')
})
it('a_b_c (多段无 appCode) → ABC', () => {
expect(snakeToPascalCase('a_b_c', undefined)).toBe('ABC')
})
})
describe('jxcj 28 form 实际 enCode 回归', () => {
const cases: [string, string][] = [
['jxcj_enroll_record', 'EnrollRecord'],
['jxcj_competition_info', 'CompetitionInfo'],
['jxcj_data_resource', 'DataResource'],
['jxcj_topic_direction', 'TopicDirection'],
['jxcj_announcement', 'Announcement'],
['jxcj_final_ranking', 'FinalRanking'],
['jxcj_review_score', 'ReviewScore'],
['jxcj_sandbox_config', 'SandboxConfig'],
['jxcj_code_audit_record', 'CodeAuditRecord'],
['jxcj_team_member', 'TeamMember'],
]
for (const [enCode, expected] of cases) {
it(`${enCode} + jxcj → ${expected}`, () => {
expect(snakeToPascalCase(enCode, 'jxcj')).toBe(expected)
})
}
})
})