Files
Genarrative/apps/ai-game-creator-shell/tests/unityProjectOpen.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

88 lines
2.8 KiB
TypeScript

// @vitest-environment jsdom
import { act, renderHook } from '@testing-library/react';
import { afterEach, expect, test, vi } from 'vitest';
import { createGameCreationAppManifest } from '../../../packages/shared/src/contracts/gameCreationApp';
import { buildRecentProjectRows } from '../src/features/app-shell/model';
import { useHomeProjectCreation } from '../src/features/app-shell/useHomeProjectCreation';
import { installTauriRuntime, resetTauriRuntime } from './tauriRuntimeFake';
afterEach(() => {
resetTauriRuntime();
});
test.each([false, true])(
'Unity 项目通过现有工作台打开,已有元数据=%s',
async (initialized) => {
const projectPath = 'C:/projects/unity';
const manifest = createGameCreationAppManifest(
'unity-project',
'Unity 项目',
);
const directory = {
projectPath,
exists: true,
isDirectory: true,
isGameCreatorProject: initialized,
isGodotProject: false,
godotProjectRoot: null,
isCocosProject: false,
isUnityProject: true,
unityProjectRoot: '.',
projectName: 'Unity 项目',
recentRunStatus: null,
recentRunStopReason: null,
};
const invoke = vi.fn(async (command: string) => {
if (command === 'inspect_local_project_directory') return directory;
if (command === 'import_local_unity_project')
return { projectPath, manifest };
if (command === 'get_local_game_manifest') return manifest;
if (command === 'get_local_game_project_revision') return { revision: 0 };
if (command === 'get_design_agent_runtime_mode')
return { activeRuntime: 'game' };
throw new Error(`意外调用:${command}`);
});
installTauriRuntime({ core: { invoke } });
const setLauncherView = vi.fn();
const { result } = renderHook(() =>
useHomeProjectCreation({
setStatus: vi.fn(),
showTransientNotice: vi.fn(),
setLauncherView,
rememberRecentWorkspace: vi.fn(),
}),
);
await act(() => result.current.openProject(projectPath, 'open'));
expect(result.current.currentProjectContext).toMatchObject({
projectPath,
projectKind: 'unity',
manifest,
startMode: null,
initialPrompt: '',
});
expect(setLauncherView).toHaveBeenCalledWith('project-development');
expect(
invoke.mock.calls.some(
([command]) => command === 'init_local_game_project',
),
).toBe(false);
expect(
invoke.mock.calls.some(
([command]) => command === 'import_local_unity_project',
),
).toBe(!initialized);
expect(
buildRecentProjectRows(
[projectPath],
{ [projectPath]: directory },
false,
)[0],
).toMatchObject({
projectKind: 'unity',
canOpen: true,
status: initialized ? '本地项目' : '可导入',
});
},
);