补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。 Co-authored-by: Cursor <cursoragent@cursor.com>
208 行
8.8 KiB
TypeScript
208 行
8.8 KiB
TypeScript
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 pipelinePagePath = path.join(adminRoot, 'src/pages/crm/pipeline/index.tsx');
|
||
const pipelineLocalePath = path.join(
|
||
adminRoot,
|
||
'src/pages/crm/pipeline/locale/index.ts'
|
||
);
|
||
|
||
test('1. crm/pipeline 必须请求 lead/page 与 updateStatus,并用 Arco Grid/Card', () => {
|
||
assert.ok(fs.existsSync(pipelinePagePath), '商机看板页面必须存在');
|
||
const content = fs.readFileSync(pipelinePagePath, 'utf-8');
|
||
|
||
assert.ok(
|
||
content.includes('admin/crm/lead/page'),
|
||
'必须请求 POST /api/admin/crm/lead/page'
|
||
);
|
||
assert.ok(
|
||
content.includes('admin/crm/lead/updateStatus'),
|
||
'必须请求 POST /api/admin/crm/lead/updateStatus'
|
||
);
|
||
assert.ok(content.includes('Grid'), '必须使用 Arco Grid');
|
||
assert.ok(content.includes('Card'), '必须使用 Arco Card');
|
||
assert.ok(content.includes('Select'), '状态流转必须使用 Arco Select');
|
||
assert.ok(
|
||
content.includes("from '@arco-design/web-react'"),
|
||
'必须从 @arco-design/web-react 引入组件'
|
||
);
|
||
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('100'), '必须按 size=100 拉一批');
|
||
assert.ok(
|
||
!content.includes('Mock.js') && !content.includes("from 'mockjs'"),
|
||
'禁止用 Mock.js 假数据冒充成功'
|
||
);
|
||
assert.ok(!/\bany\b/.test(content), '禁止使用 any');
|
||
assert.ok(
|
||
!content.includes('react-beautiful-dnd') &&
|
||
!content.includes('dnd-kit') &&
|
||
!content.includes('react-dnd'),
|
||
'禁止自制或引入拖拽库'
|
||
);
|
||
});
|
||
|
||
test('2. crm/pipeline 必须复用 LeadEntity 并渲染五列状态看板', () => {
|
||
const content = fs.readFileSync(pipelinePagePath, 'utf-8');
|
||
|
||
assert.ok(content.includes('LeadEntity'), '必须使用 LeadEntity 类型');
|
||
assert.ok(content.includes('LeadStatus'), '必须使用 LeadStatus 类型');
|
||
assert.ok(content.includes("from '@/types/omni'"), '必须复用 omni 契约');
|
||
assert.ok(content.includes('lightColors'), '颜色必须引用 lightColors');
|
||
assert.ok(content.includes('Form'), '必须使用 Arco Form');
|
||
assert.ok(content.includes('name'), '卡片必须展示 name');
|
||
assert.ok(content.includes('company'), '卡片必须展示 company');
|
||
assert.ok(content.includes('intentScore'), '卡片必须展示 intentScore');
|
||
assert.ok(content.includes('source'), '卡片必须展示 source');
|
||
assert.ok(content.includes('cardId'), '必须支持 cardId 筛选');
|
||
assert.ok(content.includes('keyWord'), '必须支持 keyWord 筛选');
|
||
assert.ok(content.includes('id') && content.includes('status'), 'updateStatus 必须传 id 与 status');
|
||
|
||
for (const status of ['new', 'contacted', 'hot', 'won', 'archived']) {
|
||
assert.ok(content.includes(`'${status}'`), `必须支持状态列: ${status}`);
|
||
}
|
||
});
|
||
|
||
test('3. crm/pipeline locale 必须包含 menu.crm.pipeline 与看板文案', () => {
|
||
assert.ok(fs.existsSync(pipelineLocalePath), '商机看板语言包必须存在');
|
||
const content = fs.readFileSync(pipelineLocalePath, 'utf-8');
|
||
|
||
assert.ok(content.includes("'menu.crm.pipeline'"), '页面语言包必须包含 menu.crm.pipeline');
|
||
assert.ok(content.includes('crmPipeline.request.fail'), '必须包含失败提示文案');
|
||
assert.ok(content.includes('crmPipeline.form.refresh'), '必须包含刷新主 CTA 文案');
|
||
assert.ok(content.includes('crmPipeline.column.empty'), '必须包含空列文案');
|
||
assert.ok(content.includes('crmPipeline.status.new'), '必须包含状态文案');
|
||
assert.ok(content.includes('crmPipeline.status.archived'), '必须包含归档状态文案');
|
||
assert.ok(!/\bany\b/.test(content), 'locale 禁止使用 any');
|
||
});
|
||
|
||
test('4. crm/pipeline 必须支持泳道快速录入商机 Modal 与对应语言包', () => {
|
||
const content = fs.readFileSync(pipelinePagePath, 'utf-8');
|
||
assert.ok(content.includes('Modal'), '必须使用 Arco Modal 弹窗录入新商机');
|
||
assert.ok(
|
||
content.includes('admin/crm/lead/add') || content.includes('lead/add'),
|
||
'必须支持调用新增商机 API'
|
||
);
|
||
assert.ok(content.includes('crmPipeline.action.quickAdd'), '必须包含快速新增按钮文案绑定');
|
||
|
||
const localeContent = fs.readFileSync(pipelineLocalePath, 'utf-8');
|
||
assert.ok(localeContent.includes('crmPipeline.action.quickAdd'), '语言包必须包含 crmPipeline.action.quickAdd');
|
||
assert.ok(localeContent.includes('crmPipeline.modal.quickAddTitle'), '语言包必须包含 crmPipeline.modal.quickAddTitle');
|
||
});
|
||
|
||
test('5. crm/pipeline 阶段变更必须写回 updateStatus,失败时回滚原列并 Message.error', () => {
|
||
const content = fs.readFileSync(pipelinePagePath, 'utf-8');
|
||
|
||
assert.ok(
|
||
content.includes('/api/admin/crm/lead/updateStatus') ||
|
||
content.includes('admin/crm/lead/updateStatus'),
|
||
'改阶段必须写回 POST /api/admin/crm/lead/updateStatus'
|
||
);
|
||
assert.ok(
|
||
content.includes('handleStatusChange') || content.includes('onChange'),
|
||
'必须通过 Select/点击改阶段触发写回'
|
||
);
|
||
assert.ok(
|
||
/setColumns\s*\(/.test(content),
|
||
'阶段变更必须更新看板列(乐观移列或回滚)'
|
||
);
|
||
assert.ok(
|
||
content.includes('rollback') ||
|
||
content.includes('prevColumns') ||
|
||
content.includes('snapshot') ||
|
||
/setColumns\(\s*(rollback|prev|snapshot|previous)/.test(content) ||
|
||
content.includes('setColumns(rollbackColumns)') ||
|
||
content.includes('setColumns(snapshot)') ||
|
||
content.includes('setColumns(prevColumns)'),
|
||
'请求失败必须把卡片放回原列,禁止只留在新列假装已保存'
|
||
);
|
||
assert.ok(content.includes('Message.error'), '失败必须 Message.error 提示');
|
||
assert.ok(content.includes('crmPipeline.update.fail'), '失败提示必须走 update.fail 文案');
|
||
assert.ok(
|
||
content.includes('axios.post') && content.includes('UPDATE_STATUS_API'),
|
||
'必须 axios.post 调用 UPDATE_STATUS_API,禁止只改本地状态'
|
||
);
|
||
|
||
const localeContent = fs.readFileSync(pipelineLocalePath, 'utf-8');
|
||
assert.ok(
|
||
localeContent.includes('crmPipeline.update.fail'),
|
||
'locale 必须包含阶段写回失败文案'
|
||
);
|
||
});
|
||
|
||
test('6. R22: 金额只读线索 amount/dealValue,无有效数字不得假总额', () => {
|
||
const content = fs.readFileSync(pipelinePagePath, 'utf-8');
|
||
const localeContent = fs.readFileSync(pipelineLocalePath, 'utf-8');
|
||
|
||
assert.ok(
|
||
content.includes('amount') && content.includes('dealValue'),
|
||
'必须从线索 amount / dealValue 读取金额'
|
||
);
|
||
assert.ok(
|
||
content.includes('readLeadAmount') && content.includes('sumStageAmount'),
|
||
'必须有读单条与汇总阶段金额的函数'
|
||
);
|
||
assert.ok(
|
||
content.includes('Number.isFinite'),
|
||
'金额必须经 Number.isFinite 校验,禁止非数字冒充'
|
||
);
|
||
assert.ok(
|
||
content.includes('counted > 0') ||
|
||
content.includes('counted>0') ||
|
||
/return counted\s*>\s*0\s*\?\s*total\s*:\s*undefined/.test(content),
|
||
'无一笔有效金额时必须返回 undefined,禁止汇总成 0'
|
||
);
|
||
assert.ok(
|
||
content.includes('crmPipeline.column.amount.empty') &&
|
||
content.includes('crmPipeline.card.amount.empty'),
|
||
'无有效金额时必须走 locale 空态文案'
|
||
);
|
||
assert.ok(
|
||
localeContent.includes('crmPipeline.column.amount.empty'),
|
||
'locale 必须包含列金额空态'
|
||
);
|
||
assert.ok(
|
||
localeContent.includes('crmPipeline.card.amount') &&
|
||
localeContent.includes('crmPipeline.card.amount.empty'),
|
||
'locale 必须包含卡片金额与空态文案'
|
||
);
|
||
|
||
// 禁止用 0×条数 / 条数×0 冒充商机金额
|
||
assert.ok(
|
||
!/0\s*\*\s*(leads\.length|\.length)/.test(content) &&
|
||
!/(leads\.length|\.length)\s*\*\s*0/.test(content),
|
||
'禁止用 0 乘条数冒充商机金额'
|
||
);
|
||
// 禁止把缺失金额默认成 0 再累加成假总额
|
||
assert.ok(
|
||
!/(amount|dealValue)[^\n]{0,120}\?\?\s*0/.test(content) &&
|
||
!/\?\?\s*0[^\n]{0,120}(amount|dealValue)/.test(content) &&
|
||
!/readLeadAmount\([^)]*\)\s*\?\?\s*0/.test(content) &&
|
||
!/parseFiniteAmount\([^)]*\)\s*\?\?\s*0/.test(content),
|
||
'禁止 amount/dealValue 缺失时 ?? 0 累加'
|
||
);
|
||
assert.ok(
|
||
!content.includes('99999') &&
|
||
!content.includes('100000') &&
|
||
!content.includes('$12,000') &&
|
||
!content.includes('¥0') &&
|
||
!content.includes('$0.00'),
|
||
'禁止写死演示商机总额'
|
||
);
|
||
|
||
// 阶段失败回滚不得被本改动破坏
|
||
assert.ok(
|
||
content.includes('setColumns(snapshot)') ||
|
||
content.includes('setColumns(prevColumns)') ||
|
||
content.includes('setColumns(rollbackColumns)'),
|
||
'阶段流转失败仍须回滚原列'
|
||
);
|
||
});
|