Files
Genarrative/src/routing/activeAppPageRoutes.test.ts
T
kdletters 4b529a8952
Project CI / AI game creator shell Rust crates (pull_request) Successful in 2m59s
Project CI / Backend tests (pull_request) Failing after 4m8s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 5m9s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 6m20s
Project CI / Frontend tests (pull_request) Successful in 3m17s
Project CI / AI game creator shell web tests (pull_request) Successful in 2m48s
Project CI / Repository checks (pull_request) Failing after 4m15s
Project CI / Native shell tests (pull_request) Successful in 6m52s
新增支付服务接入与订单收银台
新增支付应用、API Key 与外部产品订单接口

接入微信 Native 下单、二维码收银台与支付结果回调

新增后台支付订单与回调投递页面

补齐 SpacetimeDB 支付表、生成绑定、OpenAPI 与使用说明
2026-10-03 17:18:13 +08:00

99 lines
3.9 KiB
TypeScript

/* @vitest-environment jsdom */
import { describe, expect, it } from 'vitest';
import {
hasAppHistoryBackEntry,
isAppHistoryState,
isKnownMainAppPagePath,
pushAppHistoryPath,
readEditorCanvasProjectIdFromLocationSearch,
replaceAppHistoryPath,
resolvePathForSelectionStage,
resolveSelectionStageFromPath,
shouldRedirectEditorCanvasWithoutProject,
} from './activeAppPageRoutes';
describe('appPageRoutes', () => {
it('resolves the active creation, project, and editor stages', () => {
expect(resolveSelectionStageFromPath('/')).toBe('platform');
expect(resolveSelectionStageFromPath('/creation')).toBe('creation-home');
expect(resolveSelectionStageFromPath('/project')).toBe('project');
expect(resolveSelectionStageFromPath('/PROFILE/')).toBe('profile');
expect(resolveSelectionStageFromPath('/EDITOR/CANVAS/')).toBe(
'image-editor',
);
expect(resolveSelectionStageFromPath('/games')).toBe('games');
expect(resolveSelectionStageFromPath('/games/detail/')).toBe('game-detail');
expect(resolveSelectionStageFromPath('/games/play')).toBe('game-play');
expect(resolveSelectionStageFromPath('/games/mine')).toBe('game-mine');
expect(resolveSelectionStageFromPath('/games/publish')).toBe(
'game-publish',
);
expect(resolveSelectionStageFromPath('/pay/checkout-token')).toBe(
'payment-checkout',
);
expect(resolveSelectionStageFromPath('/creation/rpg')).toBe('platform');
expect(resolveSelectionStageFromPath('/runtime/puzzle')).toBe('platform');
expect(isKnownMainAppPagePath('/creation')).toBe(true);
expect(isKnownMainAppPagePath('/profile')).toBe(true);
expect(isKnownMainAppPagePath('/creation/rpg')).toBe(false);
expect(isKnownMainAppPagePath('/runtime/puzzle')).toBe(false);
expect(resolvePathForSelectionStage('creation-home')).toBe('/creation');
expect(resolvePathForSelectionStage('project')).toBe('/project');
expect(resolvePathForSelectionStage('profile')).toBe('/profile');
expect(resolvePathForSelectionStage('games')).toBe('/games');
expect(resolvePathForSelectionStage('game-mine')).toBe('/games/mine');
expect(resolvePathForSelectionStage('game-publish')).toBe('/games/publish');
expect(resolvePathForSelectionStage('profile-payment')).toBe(
'/profile/payment',
);
expect(resolvePathForSelectionStage('payment-checkout')).toBe('/pay');
});
it('requires a project id for direct editor navigation', () => {
expect(readEditorCanvasProjectIdFromLocationSearch('?projectid=abc')).toBe(
'abc',
);
expect(shouldRedirectEditorCanvasWithoutProject('/editor/canvas', '')).toBe(
true,
);
expect(
shouldRedirectEditorCanvasWithoutProject(
'/editor/canvas',
'?projectid=project-1',
),
).toBe(false);
});
it('preserves host context while navigating public pages', () => {
window.history.replaceState(
null,
'',
'/?clientRuntime=native_app&hostShell=tauri_desktop',
);
pushAppHistoryPath('/editor/canvas?projectid=project-1');
expect(window.location.pathname).toBe('/editor/canvas');
expect(window.location.search).toContain('projectid=project-1');
expect(window.location.search).toContain('clientRuntime=native_app');
expect(isAppHistoryState(window.history.state)).toBe(true);
replaceAppHistoryPath('/project');
expect(window.location.pathname).toBe('/project');
expect(window.location.search).toContain('hostShell=tauri_desktop');
});
it('只有应用内推送过上一页时才算可原生返回', () => {
window.history.replaceState(null, '', '/games/detail?id=game-1');
expect(hasAppHistoryBackEntry()).toBe(false);
window.history.replaceState(null, '', '/games/mine');
pushAppHistoryPath('/games/detail?id=game-1');
expect(hasAppHistoryBackEntry()).toBe(true);
replaceAppHistoryPath('/games/detail?id=game-2');
expect(hasAppHistoryBackEntry()).toBe(true);
});
});