feat(card): 完善名片微官网Bento搭建器无参自动选卡、名片切换、2列网格及出海多环境实时预览

这个提交包含在:
wikiboss
2026-09-21 11:59:59 +08:00
父节点 603f3d3964
当前提交 79dcc2bd61
共有 5 个文件被更改,包括 870 次插入 和 126 次删除

查看文件

@@ -3,8 +3,6 @@ import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { routes } from '../src/routes.ts';
import defaultI18n from '../src/locale/index.ts';
const adminRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const builderPagePath = path.join(adminRoot, 'src/pages/card/builder/index.tsx');
@@ -12,32 +10,20 @@ const builderLocalePath = path.join(
adminRoot,
'src/pages/card/builder/locale/index.ts'
);
function flattenRouteKeys(items: typeof routes): string[] {
return items.flatMap((item) => [
item.key,
...(item.children ? flattenRouteKeys(item.children) : []),
]);
}
const routesPath = path.join(adminRoot, 'src/routes.ts');
const mainLocalePath = path.join(adminRoot, 'src/locale/index.ts');
test('1. routes.ts 已注册 card/builder,对应 pages/card/builder', () => {
const keys = flattenRouteKeys(routes);
assert.ok(keys.includes('card/builder'), '应存在路由 key: card/builder');
const cardGroup = routes.find((item) => item.key === 'card');
assert.ok(
cardGroup?.children?.some(
(child) =>
child.key === 'card/builder' && child.name === 'menu.card.builder'
),
'card 分组下应有 menu.card.builder / card/builder'
);
const content = fs.readFileSync(routesPath, 'utf-8');
assert.ok(content.includes("key: 'card/builder'"), '应存在路由 key: card/builder');
assert.ok(content.includes("name: 'menu.card.builder'"), '应存在 menu.card.builder');
assert.ok(fs.existsSync(builderPagePath), '必须存在 pages/card/builder/index.tsx');
});
test('2. locale 必须包含 menu.card.builder 中英文案', () => {
assert.equal(defaultI18n['en-US']['menu.card.builder'], 'Bento Builder');
assert.equal(defaultI18n['zh-CN']['menu.card.builder'], 'Bento 搭建器');
const content = fs.readFileSync(mainLocalePath, 'utf-8');
assert.ok(content.includes("'menu.card.builder': 'Bento Builder'"), '英文 menu.card.builder');
assert.ok(content.includes("'menu.card.builder': 'Bento 搭建器'"), '中文 menu.card.builder');
});
test('3. builder 必须请求 getBlocksByCardId / batchSaveLayout 并支持 colSpan', () => {
@@ -116,3 +102,23 @@ test('6. builder 页面文案走 i18n 且无 emoji', () => {
);
assert.ok(!/\bany\b/.test(localeContent), 'locale 禁止使用 any');
});
test('7. builder 支持无 ID 自动拉取名片列表、名片切换器与多环境预览 (Dark / RTL)', () => {
const content = fs.readFileSync(builderPagePath, 'utf-8');
assert.ok(
content.includes('/api/admin/card/info/page'),
'必须支持拉取名片列表 /api/admin/card/info/page'
);
assert.ok(
content.includes('cardBuilder.switchCard') || content.includes('cardOptions'),
'必须支持名片切换器'
);
assert.ok(
content.includes('previewMode') || content.includes('themeMode') || content.includes('isDark'),
'必须支持暗黑/浅色模式视口切换'
);
assert.ok(
content.includes('isRtl') || content.includes('rtl'),
'必须支持 RTL 排版镜像切换'
);
});