文件
OmniCard/mpuniapp/tests/card-cases.test.ts

50 行
2.7 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
const MP_ROOT = path.resolve('m:/2026项目/CRMmp/mpuniapp');
const casesUtsPath = path.join(MP_ROOT, 'pages/owner/card/useCardCases.uts');
test('1. useCardCases.uts 文件必须存在且格式完整', () => {
assert.ok(fs.existsSync(casesUtsPath), '必须存在 useCardCases.uts');
const content = fs.readFileSync(casesUtsPath, 'utf-8');
assert.ok(content.includes('export function createCasesState'), '必须导出 createCasesState');
assert.ok(content.includes('export function validateCaseForm'), '必须导出 validateCaseForm');
assert.ok(content.includes('export async function loadCases'), '必须导出 loadCases');
assert.ok(content.includes('export async function saveCase'), '必须导出 saveCase');
assert.ok(content.includes('export async function deleteCase'), '必须导出 deleteCase');
assert.ok(content.includes('export const PRESET_CASE_METRICS'), '必须导出 PRESET_CASE_METRICS');
});
test('2. 预设指标标签完备且包含出海核心量化成效', () => {
const content = fs.readFileSync(casesUtsPath, 'utf-8');
assert.ok(content.includes('+320% ROI'), '必须包含 +320% ROI');
assert.ok(content.includes('+150% 留资率'), '必须包含 +150% 留资率');
assert.ok(content.includes('45k+ 海外线索'), '必须包含 45k+ 海外线索');
assert.ok(content.includes('2M+ 全球曝光'), '必须包含 2M+ 全球曝光');
assert.ok(content.includes('Top 1 细分类目'), '必须包含 Top 1 细分类目');
});
test('3. 案例表单校验逻辑实现规范', () => {
const content = fs.readFileSync(casesUtsPath, 'utf-8');
// 必须对标题非空和超长进行拦截
assert.ok(content.includes("title === ''"), '必须拦截空标题');
assert.ok(content.includes('title.length > 150'), '必须拦截超过 150 字符的标题');
});
test('4. 必须通过 Cool-Admin 标准 CRUD 契约对接后端接口', () => {
const content = fs.readFileSync(casesUtsPath, 'utf-8');
assert.ok(content.includes('fetchCardCasesPage'), '必须调用 fetchCardCasesPage');
assert.ok(content.includes('addCardCase'), '必须调用 addCardCase');
assert.ok(content.includes('updateCardCase'), '必须调用 updateCardCase');
assert.ok(content.includes('deleteCardCase'), '必须调用 deleteCardCase');
});
test('5. 国际化与文案键完整覆盖', () => {
const content = fs.readFileSync(casesUtsPath, 'utf-8');
assert.ok(content.includes('resolveCasesText'), '必须实现文案解析');
assert.ok(content.includes('Portfolio & Case Studies'), '必须支持英文标题');
assert.ok(content.includes('产品相册与标杆案例'), '必须支持中文标题');
});