mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
Unity projects (a folder with Assets and ProjectSettings/ProjectVersion.txt) are detected without a generated solution: Assets / Packages become source roots, ProjectSettings resources, and Unity's cache and build folders are excluded before they exist. A Unity pane in the Project view shows the editor version and hides .meta files, generated C# project files and caches (each can be shown again). Operations on assets under Assets keep their .meta files consistent: rename and move carry the metadata (same GUID), delete removes both, copy generates new GUIDs and updates references inside the copied group, and file-move undo and workspace edits include the metadata. Destination metadata conflicts and links inside the project are rejected before anything changes. Co-authored-by: hacbit <107751081+hacbit@users.noreply.github.com>
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
import type { ProjectInfo } from "@/bindings";
|
|
import { emitLocalIdeEvent } from "@/platform/ipc";
|
|
import { useProject } from "@/platform/project";
|
|
import { activate } from "./index";
|
|
import { useProjectTree } from "./store";
|
|
|
|
const current = vi.hoisted(() => vi.fn());
|
|
vi.mock("@/platform/ipc", async (original) => {
|
|
const real = await original<typeof import("@/platform/ipc")>();
|
|
return {
|
|
...real,
|
|
isTauri: () => true,
|
|
commands: {
|
|
...real.commands,
|
|
projectCurrent: current,
|
|
projectRoots: async () => ({ status: "ok", data: { roots: [], detected: [] } }),
|
|
},
|
|
};
|
|
});
|
|
|
|
const project = (root = "/game"): ProjectInfo => ({
|
|
root,
|
|
name: "Game",
|
|
trusted: false,
|
|
isGit: false,
|
|
settings: {} as ProjectInfo["settings"],
|
|
unity: { editorVersion: "2022.3.62f1", projects: [], solutions: [] },
|
|
});
|
|
let dispose: () => void;
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
current.mockReset();
|
|
useProject.setState({ project: project() });
|
|
dispose = activate();
|
|
});
|
|
afterEach(() => {
|
|
dispose();
|
|
useProject.setState({ project: null });
|
|
vi.useRealTimers();
|
|
});
|
|
const changed = () =>
|
|
emitLocalIdeEvent({ type: "fsChanged", created: ["/game/Assembly-CSharp.csproj"], modified: [], removed: [] });
|
|
|
|
it("refreshes generated C# files through backend events without overwriting a project rename", async () => {
|
|
let resolve!: (value: unknown) => void;
|
|
current.mockReturnValue(
|
|
new Promise((r) => {
|
|
resolve = r;
|
|
}),
|
|
);
|
|
changed();
|
|
await vi.advanceTimersByTimeAsync(160);
|
|
expect(current).toHaveBeenCalledTimes(1);
|
|
useProject.setState({ project: { ...project(), name: "Renamed" } });
|
|
resolve({ ...project(), unity: { ...project().unity, projects: ["Assembly-CSharp.csproj"] } });
|
|
await vi.advanceTimersByTimeAsync(0);
|
|
expect(useProjectTree.getState().unity?.projects).toEqual(["Assembly-CSharp.csproj"]);
|
|
expect(useProject.getState().project?.name).toBe("Renamed");
|
|
});
|
|
|
|
it("discards a late reply after switching to another project", async () => {
|
|
let resolve!: (value: unknown) => void;
|
|
current.mockReturnValue(
|
|
new Promise((r) => {
|
|
resolve = r;
|
|
}),
|
|
);
|
|
changed();
|
|
await vi.advanceTimersByTimeAsync(160);
|
|
useProject.setState({ project: { ...project("/app"), unity: undefined } });
|
|
resolve(project());
|
|
await vi.advanceTimersByTimeAsync(0);
|
|
expect(useProjectTree.getState()).toMatchObject({ root: "/app", unity: null, mode: "project" });
|
|
});
|