67 行
2.5 KiB
TypeScript
67 行
2.5 KiB
TypeScript
/**
|
|
* OmniCard AI (CRMmp) - 移动端 Universal Link / DeepLink 路由分发解析器单元测试
|
|
* 严格遵循 TDD 测试驱动规范
|
|
*/
|
|
|
|
describe('Point 56: 移动端 App / H5 智能数字名片 Universal Link 深度链接路由分发解析器', () => {
|
|
let router: any;
|
|
|
|
beforeEach(() => {
|
|
// @ts-ignore
|
|
router = require('../../../mpuniapp/common/deeplink-router.uts');
|
|
});
|
|
|
|
describe('1. parseDeepLink (Universal Link 与 Scheme 统一解析)', () => {
|
|
it('应成功解析 Universal Link 网页链接格式', () => {
|
|
const url = 'https://omnicard.ai/p/alex-zheng?scene=exhibition&lang=ar&tab=cases&from=nfc';
|
|
const parsed = router.parseDeepLink(url);
|
|
|
|
expect(parsed.isValid).toBe(true);
|
|
expect(parsed.cardSlug).toBe('alex-zheng');
|
|
expect(parsed.sceneMode).toBe('exhibition');
|
|
expect(parsed.locale).toBe('ar');
|
|
expect(parsed.focusTab).toBe('cases');
|
|
expect(parsed.source).toBe('nfc');
|
|
});
|
|
|
|
it('应成功解析 App Custom Scheme 格式 (omnicard://card/view)', () => {
|
|
const scheme = 'omnicard://card/view?id=108&scene=social&lang=es';
|
|
const parsed = router.parseDeepLink(scheme);
|
|
|
|
expect(parsed.isValid).toBe(true);
|
|
expect(parsed.cardId).toBe(108);
|
|
expect(parsed.sceneMode).toBe('social');
|
|
expect(parsed.locale).toBe('es');
|
|
expect(parsed.source).toBe('direct');
|
|
});
|
|
|
|
it('无效或非 OmniCard 链接应安全拦截并标识无效', () => {
|
|
const invalid = router.parseDeepLink('https://google.com/search?q=test');
|
|
expect(invalid.isValid).toBe(false);
|
|
|
|
const empty = router.parseDeepLink('');
|
|
expect(empty.isValid).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('2. buildAppPageRoute (目标页面路由与参数拼接)', () => {
|
|
it('应生成符合 uni-app 规范的标准应用内跳转路由', () => {
|
|
const parsed = router.parseDeepLink(
|
|
'https://omnicard.ai/p/alex?scene=exhibition&lang=ar&tab=chat'
|
|
);
|
|
const targetRoute = router.buildAppPageRoute(parsed);
|
|
|
|
expect(targetRoute).toContain('/pages/portal/index');
|
|
expect(targetRoute).toContain('slug=alex');
|
|
expect(targetRoute).toContain('scene=exhibition');
|
|
expect(targetRoute).toContain('lang=ar');
|
|
expect(targetRoute).toContain('tab=chat');
|
|
});
|
|
|
|
it('无效解析对象应安全回退至名片主页', () => {
|
|
const fallback = router.buildAppPageRoute({ isValid: false });
|
|
expect(fallback).toBe('/pages/owner/hall/index');
|
|
});
|
|
});
|
|
});
|