Files
Genarrative/apps/mobile-shell/src/shell/loadFailure.test.ts
T
kdletters c5d899480f 补齐移动壳进程崩溃恢复边界
移动壳 WebView 进程失败增加防循环恢复

加载失败面板承接连续进程恢复失败

配置检查和文档同步崩溃恢复约束
2026-06-20 19:07:12 +08:00

136 lines
3.4 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import { normalizeMobileShellLoadFailure } from './loadFailure';
const allowedOrigin = 'https://app.genarrative.world';
describe('loadFailure', () => {
test('归一化同源 HTTP 加载失败', () => {
expect(
normalizeMobileShellLoadFailure(
{
type: 'http',
url: 'https://app.genarrative.world/creation/puzzle',
statusCode: 503,
description: 'Service Unavailable',
},
allowedOrigin,
),
).toEqual({
type: 'http',
url: 'https://app.genarrative.world/creation/puzzle',
title: '加载失败 503',
detail: 'Service Unavailable',
retryLabel: '重试',
});
});
test('归一化同源原生加载失败并折叠错误描述', () => {
expect(
normalizeMobileShellLoadFailure(
{
type: 'native',
url: '/works/detail?work=WF-1',
code: -1009,
description: ' The Internet connection appears to be offline. ',
},
allowedOrigin,
),
).toEqual({
type: 'native',
url: 'https://app.genarrative.world/works/detail?work=WF-1',
title: '网络不可用',
detail: 'The Internet connection appears to be offline.',
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://app.genarrative.world/assets/main.js',
statusCode: 404,
},
allowedOrigin,
'https://app.genarrative.world/creation/puzzle',
),
).toBeNull();
expect(
normalizeMobileShellLoadFailure(
{
type: 'http',
url: 'https://app.genarrative.world/creation/puzzle',
statusCode: 503,
},
allowedOrigin,
'https://app.genarrative.world/creation/puzzle',
)?.title,
).toBe('加载失败 503');
});
test('连续 WebView 进程恢复失败时展示同源页面兜底', () => {
expect(
normalizeMobileShellLoadFailure(
{
type: 'process',
url: 'https://app.genarrative.world/works/detail?work=WF-1',
description: 'WebView renderer terminated repeatedly',
},
allowedOrigin,
'https://app.genarrative.world/works/detail?work=WF-1',
),
).toEqual({
type: 'process',
url: 'https://app.genarrative.world/works/detail?work=WF-1',
title: '页面已停止',
detail: 'WebView renderer terminated repeatedly',
retryLabel: '重试',
});
});
});