- 模块一: 出海案例作品集、博客动态发布、人名发音语音条、RTL阿语多语言切换 - 模块二: AI顾问人设配置、行业术语库润色、RAG切片沙盒调试、流式会话与意向留资卡片 - 模块三: 全球访客雷达大屏、多维加权意向算分、外部CRM对接推送、团队公海池流转 - 模块四: 移动端NFC安全挂失、NFC动态路由规则配置、动态防伪验签、展会制卡Zip批量导出 - 模块五: 组织架构与名片分配、移动端个人中心设置、离职交接与历史线索迁移、安全审计日志 - 模块六: Stripe国际信用卡订阅Webhook、独立二级域名与SSL检测、坐席配额预警、多币种发票 - 模块七: 纸质名片OCR解析入库、国际商务日程RFC 5545 ICS日历、微官网离线SWR预加载、展会实时排行榜大屏 - 模块八: 全球出海SEO OpenGraph元标签注入与社交爬虫探测、30点端到端全链路业务流集成测试套件
274 行
8.5 KiB
TypeScript
274 行
8.5 KiB
TypeScript
/**
|
|
* OmniCard AI (CRMmp) - 名片主移动潜客列表测试套件 (TDD Red -> Green)
|
|
*
|
|
* 严格按照 AGENTS.md 3.3、4.3、5.1 规范与 pages/owner/leads 设计编写
|
|
*/
|
|
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
const LEADS_PAGE = path.resolve(
|
|
__dirname,
|
|
'../../../mpuniapp/pages/owner/leads.uvue'
|
|
);
|
|
const LEADS_UTS = path.resolve(
|
|
__dirname,
|
|
'../../../mpuniapp/pages/owner/useLeads.uts'
|
|
);
|
|
|
|
type LeadStatus = 'new' | 'contacted' | 'hot' | 'won' | 'archived';
|
|
|
|
type LeadEntity = {
|
|
id: string | number;
|
|
cardId: string | number;
|
|
name: string;
|
|
company?: string;
|
|
status: LeadStatus;
|
|
intentScore: number;
|
|
source: 'nfc' | 'qr' | 'link' | 'ai_chat';
|
|
};
|
|
|
|
type OwnerPageQuery = {
|
|
page: number;
|
|
size: number;
|
|
keyWord?: string;
|
|
status?: LeadStatus;
|
|
};
|
|
|
|
type OwnerPageData<T> = {
|
|
list: T[];
|
|
pagination: {
|
|
page: number;
|
|
size: number;
|
|
total: number;
|
|
};
|
|
};
|
|
|
|
type LoadLeadsQuery = {
|
|
page: number;
|
|
size: number;
|
|
status?: string;
|
|
keyWord?: string;
|
|
};
|
|
|
|
type LoadLeadsApi = {
|
|
fetchOwnerLeadPage: (
|
|
query: OwnerPageQuery
|
|
) => Promise<OwnerPageData<LeadEntity>>;
|
|
};
|
|
|
|
type LoadLeadsResult = {
|
|
list: LeadEntity[];
|
|
pagination: {
|
|
page: number;
|
|
size: number;
|
|
total: number;
|
|
};
|
|
empty: boolean;
|
|
errorMessage: string;
|
|
};
|
|
|
|
type UseLeadsModule = {
|
|
parseLeadStatus: (raw: string | null | undefined) => LeadStatus | null;
|
|
loadLeads: (
|
|
query: LoadLeadsQuery,
|
|
api?: LoadLeadsApi
|
|
) => Promise<LoadLeadsResult>;
|
|
};
|
|
|
|
const EMOJI_RE = /[\u2600-\u27BF\uFE0F]|[\uD83C-\uDBFF][\uDC00-\uDFFF]/;
|
|
|
|
function buildLead(overrides?: Partial<LeadEntity>): LeadEntity {
|
|
return {
|
|
id: 21,
|
|
cardId: 8,
|
|
name: 'Alex Vance',
|
|
company: 'Nexus Tech',
|
|
status: 'new',
|
|
intentScore: 72,
|
|
source: 'nfc',
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function emptyPage(page: number, size: number): OwnerPageData<LeadEntity> {
|
|
return {
|
|
list: [],
|
|
pagination: { page, size, total: 0 },
|
|
};
|
|
}
|
|
|
|
function loadUseLeads(): UseLeadsModule {
|
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
return require(LEADS_UTS) as UseLeadsModule;
|
|
}
|
|
|
|
describe('OmniCard AI 名片主移动潜客列表 (useLeads.uts)', () => {
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
(global as { uni?: Record<string, unknown> }).uni = {
|
|
getLocale: () => 'zh-CN',
|
|
showToast: jest.fn(),
|
|
navigateTo: jest.fn(),
|
|
};
|
|
});
|
|
|
|
afterEach(() => {
|
|
delete (global as { uni?: Record<string, unknown> }).uni;
|
|
});
|
|
|
|
describe('1. loadLeads 调用 page API', () => {
|
|
it('1.1 将 page / size / status / keyWord 交给 fetchOwnerLeadPage', async () => {
|
|
const { loadLeads } = loadUseLeads();
|
|
const lead = buildLead({ status: 'hot', intentScore: 91 });
|
|
const fetchOwnerLeadPage = jest.fn(
|
|
async (query: OwnerPageQuery): Promise<OwnerPageData<LeadEntity>> => {
|
|
expect(query.page).toBe(2);
|
|
expect(query.size).toBe(20);
|
|
expect(query.status).toBe('hot');
|
|
expect(query.keyWord).toBe('Vance');
|
|
return {
|
|
list: [lead],
|
|
pagination: { page: 2, size: 20, total: 1 },
|
|
};
|
|
}
|
|
);
|
|
|
|
const result = await loadLeads(
|
|
{ page: 2, size: 20, status: 'hot', keyWord: 'Vance' },
|
|
{ fetchOwnerLeadPage }
|
|
);
|
|
|
|
expect(fetchOwnerLeadPage).toHaveBeenCalledTimes(1);
|
|
expect(result.list).toHaveLength(1);
|
|
expect(result.list[0].name).toBe('Alex Vance');
|
|
expect(result.list[0].intentScore).toBe(91);
|
|
expect(result.empty).toBe(false);
|
|
expect(result.errorMessage).toBe('');
|
|
expect(result.pagination.total).toBe(1);
|
|
});
|
|
|
|
it('1.2 空列表标记空态,不写错误', async () => {
|
|
const { loadLeads } = loadUseLeads();
|
|
const fetchOwnerLeadPage = jest.fn(
|
|
async (): Promise<OwnerPageData<LeadEntity>> => emptyPage(1, 10)
|
|
);
|
|
|
|
const result = await loadLeads(
|
|
{ page: 1, size: 10 },
|
|
{ fetchOwnerLeadPage }
|
|
);
|
|
|
|
expect(fetchOwnerLeadPage).toHaveBeenCalledTimes(1);
|
|
expect(result.list).toEqual([]);
|
|
expect(result.empty).toBe(true);
|
|
expect(result.errorMessage).toBe('');
|
|
});
|
|
|
|
it('1.3 接口失败写入错误,不伪装空态成功', async () => {
|
|
const { loadLeads } = loadUseLeads();
|
|
const fetchOwnerLeadPage = jest.fn(async (): Promise<OwnerPageData<LeadEntity>> => {
|
|
throw new Error('lead page unavailable');
|
|
});
|
|
|
|
const result = await loadLeads(
|
|
{ page: 1, size: 10, status: 'new' },
|
|
{ fetchOwnerLeadPage }
|
|
);
|
|
|
|
expect(fetchOwnerLeadPage).toHaveBeenCalledTimes(1);
|
|
expect(result.list).toEqual([]);
|
|
expect(result.empty).toBe(false);
|
|
expect(result.errorMessage).toBe('lead page unavailable');
|
|
});
|
|
});
|
|
|
|
describe('2. 非法 status 丢弃', () => {
|
|
it('2.1 parseLeadStatus 只放行契约枚举', () => {
|
|
const { parseLeadStatus } = loadUseLeads();
|
|
|
|
expect(parseLeadStatus('new')).toBe('new');
|
|
expect(parseLeadStatus('contacted')).toBe('contacted');
|
|
expect(parseLeadStatus('hot')).toBe('hot');
|
|
expect(parseLeadStatus('won')).toBe('won');
|
|
expect(parseLeadStatus('archived')).toBe('archived');
|
|
expect(parseLeadStatus('pending')).toBeNull();
|
|
expect(parseLeadStatus('NEW')).toBeNull();
|
|
expect(parseLeadStatus('')).toBeNull();
|
|
expect(parseLeadStatus(null)).toBeNull();
|
|
expect(parseLeadStatus(undefined)).toBeNull();
|
|
});
|
|
|
|
it('2.2 loadLeads 不把非法 status 传给 page API', async () => {
|
|
const { loadLeads } = loadUseLeads();
|
|
const fetchOwnerLeadPage = jest.fn(
|
|
async (query: OwnerPageQuery): Promise<OwnerPageData<LeadEntity>> => {
|
|
expect(query.status).toBeUndefined();
|
|
return emptyPage(query.page, query.size);
|
|
}
|
|
);
|
|
|
|
await loadLeads(
|
|
{ page: 1, size: 10, status: 'pending', keyWord: ' ' },
|
|
{ fetchOwnerLeadPage }
|
|
);
|
|
|
|
expect(fetchOwnerLeadPage).toHaveBeenCalledTimes(1);
|
|
const sent = fetchOwnerLeadPage.mock.calls[0][0] as OwnerPageQuery;
|
|
expect(sent.page).toBe(1);
|
|
expect(sent.size).toBe(10);
|
|
expect(sent.status).toBeUndefined();
|
|
expect(sent.keyWord).toBeUndefined();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('OmniCard AI 名片主潜客列表页契约 (leads.uvue)', () => {
|
|
it('页面含 list-view,并引用 fetchOwnerLeadPage 或 loadLeads', () => {
|
|
expect(fs.existsSync(LEADS_PAGE)).toBe(true);
|
|
expect(fs.existsSync(LEADS_UTS)).toBe(true);
|
|
|
|
const pageSource = fs.readFileSync(LEADS_PAGE, 'utf8');
|
|
const logicSource = fs.readFileSync(LEADS_UTS, 'utf8');
|
|
const combined = `${pageSource}\n${logicSource}`;
|
|
|
|
expect(pageSource.includes('<list-view')).toBe(true);
|
|
expect(pageSource.includes('<list-item')).toBe(true);
|
|
expect(pageSource.includes('v-for')).toBe(true);
|
|
expect(
|
|
combined.includes('fetchOwnerLeadPage') || combined.includes('loadLeads')
|
|
).toBe(true);
|
|
expect(pageSource.includes('script setup lang="uts"')).toBe(true);
|
|
expect(pageSource.includes('getOmniText')).toBe(true);
|
|
expect(combined.includes('crm.leads')).toBe(true);
|
|
expect(combined.includes('crm.follow_up')).toBe(true);
|
|
expect(pageSource.includes('leads-detail')).toBe(true);
|
|
expect(pageSource.includes('navigateTo') || logicSource.includes('navigateTo')).toBe(
|
|
true
|
|
);
|
|
expect(pageSource.includes('#0B5CFF')).toBe(true);
|
|
expect(pageSource.includes('#F7F8FA')).toBe(true);
|
|
expect(pageSource.includes('#101828')).toBe(true);
|
|
expect(pageSource.includes('#667085')).toBe(true);
|
|
expect(pageSource.includes('#E3E7ED')).toBe(true);
|
|
expect(pageSource.includes('primary-cta-btn')).toBe(true);
|
|
expect(pageSource.includes('status-chip')).toBe(true);
|
|
});
|
|
|
|
it('无 emoji、无 any,模板无硬编码中文主文案,长列表不用 view v-for', () => {
|
|
const pageSource = fs.readFileSync(LEADS_PAGE, 'utf8');
|
|
const logicSource = fs.readFileSync(LEADS_UTS, 'utf8');
|
|
const testSource = fs.readFileSync(__filename, 'utf8');
|
|
const template = pageSource.split('<script')[0];
|
|
|
|
expect(EMOJI_RE.test(pageSource)).toBe(false);
|
|
expect(EMOJI_RE.test(logicSource)).toBe(false);
|
|
expect(EMOJI_RE.test(testSource)).toBe(false);
|
|
expect(pageSource.includes(': any') || pageSource.includes(' as any')).toBe(false);
|
|
expect(logicSource.includes(': any') || logicSource.includes(' as any')).toBe(false);
|
|
expect(/[\u4e00-\u9fff]/.test(template)).toBe(false);
|
|
expect(/<view[^>]*v-for/.test(template)).toBe(false);
|
|
expect(template.includes('<list-item')).toBe(true);
|
|
});
|
|
});
|