7ea463ed08
保留 SpacetimeDB 历史表、迁移白名单与最小兼容读取定义 移除旧创作前后端、worker、业务过程及纯业务 crate 的编译依赖 恢复现役创作、项目、我的入口及桌面移动导航 收紧 Vite、TypeScript、ESLint、Vitest 与静态资源退役边界 补齐开发栈、网关、原生壳和文档退役约束
69 lines
2.6 KiB
TypeScript
69 lines
2.6 KiB
TypeScript
/* @vitest-environment jsdom */
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
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('/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');
|
|
});
|
|
|
|
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');
|
|
});
|
|
});
|