Files
Genarrative/apps/mobile-shell/src/shell/loadFailure.test.ts
T
kdletters 8bd8363ffa 修正原生壳公开主站配置
将原生壳公开主站统一为 www.genarrative.world

调整 Tauri release 直接加载线上主站并移除 frontendDist 打包

补齐创作入口配置开发代理与回归测试

同步原生壳方案文档和共享记忆
2026-06-22 15:07:02 +08:00

136 lines
3.5 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import { normalizeMobileShellLoadFailure } from './loadFailure';
const allowedOrigin = 'https://www.genarrative.world';
describe('loadFailure', () => {
test('归一化同源 HTTP 加载失败', () => {
expect(
normalizeMobileShellLoadFailure(
{
type: 'http',
url: 'https://www.genarrative.world/creation/puzzle?sessionId=private#recover',
statusCode: 503,
description: 'Service Unavailable',
},
allowedOrigin,
),
).toEqual({
type: 'http',
url: 'https://www.genarrative.world/creation/puzzle',
title: '加载失败 503',
detail: '服务器暂时没有返回可用页面',
retryLabel: '重试',
});
});
test('归一化同源原生加载失败并隐藏系统错误描述', () => {
expect(
normalizeMobileShellLoadFailure(
{
type: 'native',
url: '/works/detail?work=WF-1&token=private#runtime',
code: -1009,
description: ' The Internet connection appears to be offline. ',
},
allowedOrigin,
),
).toEqual({
type: 'native',
url: 'https://www.genarrative.world/works/detail',
title: '网络不可用',
detail: '当前页面没有加载成功',
retryLabel: '重试',
});
});
test('忽略外域和非页面加载失败', () => {
expect(
normalizeMobileShellLoadFailure(
{
type: 'http',
url: 'https://example.com/',
statusCode: 500,
},
allowedOrigin,
),
).toBeNull();
expect(
normalizeMobileShellLoadFailure(
{
type: 'native',
url: 'about:blank',
code: -1,
},
allowedOrigin,
),
).toBeNull();
expect(
normalizeMobileShellLoadFailure(
{
type: 'native',
url: 'javascript:alert(1)',
code: -1,
},
allowedOrigin,
),
).toBeNull();
expect(
normalizeMobileShellLoadFailure(
{
type: 'http',
url: '/favicon.ico',
statusCode: 404,
},
allowedOrigin,
),
).toBeNull();
});
test('只展示当前主页面失败', () => {
expect(
normalizeMobileShellLoadFailure(
{
type: 'http',
url: 'https://www.genarrative.world/assets/main.js',
statusCode: 404,
},
allowedOrigin,
'https://www.genarrative.world/creation/puzzle',
),
).toBeNull();
expect(
normalizeMobileShellLoadFailure(
{
type: 'http',
url: 'https://www.genarrative.world/creation/puzzle',
statusCode: 503,
},
allowedOrigin,
'https://www.genarrative.world/creation/puzzle',
)?.title,
).toBe('加载失败 503');
});
test('连续 WebView 进程恢复失败时展示同源页面兜底', () => {
expect(
normalizeMobileShellLoadFailure(
{
type: 'process',
url: 'https://www.genarrative.world/works/detail?work=WF-1&token=private#runtime',
description: 'WebView renderer terminated repeatedly',
},
allowedOrigin,
'https://www.genarrative.world/works/detail?work=WF-1&token=private#runtime',
),
).toEqual({
type: 'process',
url: 'https://www.genarrative.world/works/detail',
title: '页面已停止',
detail: '当前页面连续恢复失败',
retryLabel: '重试',
});
});
});