Files
Genarrative/apps/ai-game-creator-shell/tests/designProjectRestore.test.tsx
T
k88936 25c5ecdf6e
Project CI / AI game creator shell Rust crates (pull_request) Successful in 2m58s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 6m34s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 5m29s
Project CI / Backend tests (pull_request) Failing after 4m38s
Project CI / Frontend tests (pull_request) Successful in 3m33s
Project CI / Repository checks (pull_request) Failing after 4m4s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m13s
Project CI / Native shell tests (pull_request) Successful in 6m35s
测试:全仓测试统一 Tauri 运行时替身安装点
- 78 处内联 window.__TAURI__ 赋值改为 installTauriRuntime,覆盖 appSurface 之外的 37 个测试文件
- 31 处 delete window.__TAURI__ / window.__TAURI__ = undefined 复位改为 resetTauriRuntime
- 删除 recentProjectsHook、projectCreationDirectory、projectResourceLiveIntegration、useProjectResourceCardPreviews、resourceVersionReplacementModel、unityProjectOpen 里的本地 asTauriInvoke / asTauriListen 适配器与相关类型别名
- designProjectRestore 的 setup 参数由 ReturnType<typeof vi.fn> 收窄为具体 invoke 签名
- 迁移后仅 tests/tauriRuntimeFake.ts 直接读写 window.__TAURI__
2026-10-03 20:19:45 +08:00

86 lines
3.0 KiB
TypeScript

// @vitest-environment jsdom
import { act, cleanup, renderHook } from '@testing-library/react';
import { afterEach, expect, it, vi } from 'vitest';
import { createGameCreationAppManifest } from '../../../packages/shared/src/contracts/gameCreationApp';
import { useHomeProjectCreation } from '../src/features/app-shell/useHomeProjectCreation';
import { installTauriRuntime, resetTauriRuntime } from './tauriRuntimeFake';
afterEach(() => {
cleanup();
resetTauriRuntime();
});
const projectPath = 'C:/test/design-project';
const manifest = createGameCreationAppManifest('test-project', '策划项目');
function setup(
invoke: (command: string, args?: Record<string, unknown>) => Promise<unknown>,
) {
installTauriRuntime({ core: { invoke } });
return renderHook(() =>
useHomeProjectCreation({
setStatus: vi.fn(),
showTransientNotice: vi.fn(),
setLauncherView: vi.fn(),
rememberRecentWorkspace: vi.fn(),
}),
);
}
it.each(['design', 'game', null] as const)(
'restores %s before publishing the project context',
async (mode) => {
let resolveMode!: (value: { activeRuntime: string } | null) => void;
const modePromise = new Promise<{ activeRuntime: string } | null>(
(resolve) => {
resolveMode = resolve;
},
);
const invoke = vi.fn(async (command: string) => {
if (command === 'inspect_local_project_directory')
return { exists: true, isDirectory: true, isGameCreatorProject: true };
if (command === 'get_local_game_manifest') return manifest;
if (command === 'get_local_game_project_revision') return { revision: 1 };
if (command === 'get_design_agent_runtime_mode') return modePromise;
throw new Error(command);
});
const { result } = setup(invoke);
let opening!: Promise<void>;
await act(async () => {
opening = result.current.openProject(projectPath, 'open');
});
expect(result.current.currentProjectContext).toBeNull();
await act(async () => {
resolveMode(mode ? { activeRuntime: mode } : null);
await opening;
});
expect(result.current.currentProjectContext?.startMode).toBe(
mode === 'design' ? 'planning' : null,
);
},
);
it('persists design mode before entering a newly created planning project', async () => {
const invoke = vi.fn(async (command: string) => {
if (command === 'create_automatic_local_game_project')
return { projectPath, manifest };
if (command === 'set_design_agent_runtime_mode')
return { activeRuntime: 'design' };
if (command === 'get_local_game_project_revision') return { revision: 1 };
throw new Error(command);
});
const { result } = setup(invoke);
await act(async () => {
await result.current.createHomeDraftAutomatically(
{ creationType: 'game', prompt: '测试', attachments: [] },
'planning',
);
});
expect(invoke).toHaveBeenCalledWith('set_design_agent_runtime_mode', {
projectPath,
activeRuntime: 'design',
});
expect(result.current.currentProjectContext?.startMode).toBe('planning');
});