import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const adminRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const leadsPagePath = path.join(adminRoot, 'src/pages/crm/leads/index.tsx'); const leadsLocalePath = path.join(adminRoot, 'src/pages/crm/leads/locale/index.ts'); test('1. crm/leads 页面必须请求 admin/crm/lead/page 并使用 Arco Table', () => { assert.ok(fs.existsSync(leadsPagePath), '潜客线索页面必须存在'); const content = fs.readFileSync(leadsPagePath, 'utf-8'); assert.ok( content.includes('admin/crm/lead/page'), '必须请求 POST /api/admin/crm/lead/page' ); assert.ok(content.includes('Table'), '必须使用 Arco Table'); assert.ok( content.includes("from '@arco-design/web-react'"), '必须从 @arco-design/web-react 引入组件' ); assert.ok(content.includes('LeadStatus'), '必须使用 LeadStatus 类型'); assert.ok( content.includes('code === 1000') || content.includes('code ===1000'), '必须按 Cool-Admin code === 1000 判断成功' ); assert.ok(content.includes('Message.error'), '失败必须使用 Arco Message.error'); assert.ok(!content.includes('Mock.js') && !content.includes("from 'mockjs'"), '禁止用 Mock.js 假数据冒充成功'); assert.ok(!/\bany\b/.test(content), '禁止使用 any'); }); test('2. crm/leads 必须复用 LeadEntity 契约与状态/来源筛选', () => { const content = fs.readFileSync(leadsPagePath, 'utf-8'); assert.ok(content.includes('LeadEntity'), '必须使用 LeadEntity 类型'); assert.ok(content.includes('LeadSource'), '必须使用 LeadSource 类型'); assert.ok(content.includes('Form'), '必须使用 Arco Form'); assert.ok(content.includes('Select'), '必须使用 Arco Select'); assert.ok(content.includes('Tag'), '状态必须使用 Arco Tag'); assert.ok(content.includes('intentScore'), '必须展示 intentScore'); assert.ok(content.includes('notes'), '必须展示 notes 摘要'); for (const status of ['new', 'contacted', 'hot', 'won', 'archived']) { assert.ok(content.includes(`'${status}'`), `必须支持状态: ${status}`); } for (const source of ['nfc', 'qr', 'link', 'ai_chat']) { assert.ok(content.includes(`'${source}'`), `必须支持来源: ${source}`); } }); test('3. crm/leads locale 必须包含中英文案', () => { assert.ok(fs.existsSync(leadsLocalePath), '潜客线索语言包必须存在'); const content = fs.readFileSync(leadsLocalePath, 'utf-8'); assert.ok(content.includes("'menu.crm.leads'"), '页面语言包必须包含 menu.crm.leads'); assert.ok(content.includes('crmLeads.request.fail'), '必须包含失败提示文案'); assert.ok(content.includes('crmLeads.status.new'), '必须包含状态文案'); assert.ok(content.includes('crmLeads.source.ai_chat'), '必须包含来源文案'); });