import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; /** * 系统配置页「智能分配」开关(仅管理员)回归。 * * 背景:原「手动分配」页 /orders/allocation 删除后,该开关曾三次尝试都以「看不见」告终: * 1) 只补保存逻辑,未处理缺配置行; * 2) 做成配置行渲染,但落在 showPlatformConfigSections(= 超管 && 平台范围)块内, * 分公司管理员恒为 false,整个分组块不执行; * 3) 配置行按分公司存储,分公司管理员读不到行、作用域过滤再收窄。 * * 现方案:独立面板 + 专用接口(按分公司 upsert),完全不依赖 configs 表与作用域逻辑。 * 本测试锁住该结构,避免退回「依赖 configs 表」的实现。 */ describe('smart allocation switch contract', () => { const src = readFileSync(new URL('./SystemConfig.tsx', import.meta.url), 'utf8'); it('走专用接口读写,不经 configs 表', () => { expect(src).toMatch(/fetchSmartAllocationConfigApi\(\)/); expect(src).toMatch(/saveSmartAllocationConfigApi\(smartAllocationEnabled\)/); }); it('用独立本地状态,不从 configs/drafts 取开关值', () => { expect(src).toMatch(/const \[smartAllocationEnabled, setSmartAllocationEnabled\] = useState/); expect(src).toMatch(/const \[smartAllocationSaving, setSmartAllocationSaving\] = useState/); }); it('仅管理员可见,且不依赖超管专属的 showPlatformConfigSections', () => { expect(src).toMatch(/\{showBranchSkuAiImageSection && renderSmartAllocationPanel\(\)\}/); expect(src).not.toMatch(/showPlatformConfigSections \|\| showSmartAllocation/); }); it('渲染面板含勾选框与保存按钮', () => { expect(src).toMatch(/renderSmartAllocationPanel/); expect(src).toMatch(/system\.config\.smartAlloc\.section/); expect(src).toMatch(/saveSmartAllocationSwitch/); }); });