文件
OmniCard/backend/test/mpuniapp/tabbar-config.test.ts
wikiboss 62e0ae4435 feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-23 18:01:47 +08:00

46 行
1.9 KiB
TypeScript

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

import * as fs from 'fs';
import * as path from 'path';
describe('uni-app 框架自带原生 tabBar 规范测试 (TDD Red -> Green)', () => {
const rootDir = path.resolve(__dirname, '../../../mpuniapp');
const pagesJsonPath = path.join(rootDir, 'pages.json');
it('1. pages.json 中必须配置合法且符合 uni-app 原生规范的 tabBar', () => {
expect(fs.existsSync(pagesJsonPath)).toBe(true);
const content = fs.readFileSync(pagesJsonPath, 'utf-8');
// 去除 json 中的注释
const cleanJson = content.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm, '$1');
const config = JSON.parse(cleanJson);
expect(config.tabBar).toBeDefined();
expect(Array.isArray(config.tabBar.list)).toBe(true);
expect(config.tabBar.list.length).toBeGreaterThanOrEqual(2);
expect(config.tabBar.list.length).toBeLessThanOrEqual(5);
// 关键规范:tabBar.list[0].pagePath 必须与 pages[0].path 一致,原生 tabBar 才能在首屏正常加载
expect(config.tabBar.list[0].pagePath).toBe(config.pages[0].path);
expect(['工作台', '名片']).toContain(config.tabBar.list[0].text);
// 校验颜色 Token
expect(config.tabBar.color.toLowerCase()).toBe('#667085');
expect(config.tabBar.selectedColor.toLowerCase()).toBe('#0b5cff');
});
it('2. tabBar 中声明的所有图标资源文件必须真实存在', () => {
const content = fs.readFileSync(pagesJsonPath, 'utf-8');
const cleanJson = content.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm, '$1');
const config = JSON.parse(cleanJson);
for (const item of config.tabBar.list) {
if (item.iconPath) {
const iconFile = path.join(rootDir, item.iconPath);
expect(fs.existsSync(iconFile)).toBe(true);
}
if (item.selectedIconPath) {
const selIconFile = path.join(rootDir, item.selectedIconPath);
expect(fs.existsSync(selIconFile)).toBe(true);
}
}
});
});