Файли
openidea/e2e/dotnetSolutionEdit.spec.ts
T
LU XIANGRUIтаwildcatDownstairs 4e5ae49aa9 feat(dotnet): edit solutions and project references from the Project view (#7426)
Add Existing Project, Add/Remove Project Reference and Remove from Solution on .NET solution and project nodes, running dotnet sln/reference one at a time.

Queued edits are cancelled when the workspace changes, the tree refreshes after a partially failed CLI edit, and solution paths are normalized before comparing them.

Co-authored-by: wildcatDownstairs <[email protected]>
2026-12-02 18:05:25 +08:00

116 рядки
5.3 KiB
TypeScript

/**
* Solution and project-reference edits from the Project view (#7421). The host is stubbed at the IPC
* layer (no `dotnet` runs; `src/features/dotnet/edit.test.ts` runs the real CLI): the spec checks
* the menus and the exact `dotnet` commands they start.
*/
import type { Page } from "@playwright/test";
import { expect, stubDesktop, test } from "./fixtures";
const SHOTS = process.env.E2E_SHOTS;
/** Stubs the process host: records the `dotnet` argument lists and answers `sln list` with `listed`. */
async function stubHost(page: Page, listed: string[]) {
await stubDesktop(page);
await page.evaluate(
async ({ listed }) => {
const h = window.__ipc.handlers;
const runs: string[][] = [];
(window as unknown as { __runs: string[][] }).__runs = runs;
let id = 100;
h.run_start = (args) => {
const config = args.config as { args: string[] };
runs.push(config.args);
const run = ++id;
setTimeout(() => {
const text = config.args[2] === "list" ? `Project(s)\n----------\n${listed.join("\n")}\n` : "ok\n";
window.__ipc.send(args.onOutput, { kind: "stdout", text });
window.__ipc.emit({ type: "runExited", run, code: 0 });
}, 20);
return { id: run, configId: "x", name: "dotnet", pid: 1, running: true, pty: false };
};
h["plugin:dialog|open"] = () => ["/dev/acme-api/Lib/Lib.csproj"];
const storeModule = "/src/features/dotnet/store.ts";
const { useDotnet } = await import(/* @vite-ignore */ storeModule);
const project = (path: string, name: string, references: string[] = []) => ({
path,
name,
frameworks: ["net9.0"],
configurations: ["Debug"],
references,
packages: [],
test: false,
runner: "vstest",
adapter: "mstest",
trx: false,
});
useDotnet.setState({
model: {
projects: [
project("/dev/acme-api/App/App.csproj", "App", ["/dev/acme-api/Core/Core.csproj"]),
project("/dev/acme-api/Core/Core.csproj", "Core"),
],
solutions: [
{
path: "/dev/acme-api/Acme.sln",
projects: ["/dev/acme-api/App/App.csproj", "/dev/acme-api/Core/Core.csproj"],
},
],
},
});
},
{ listed },
);
}
const runs = (page: Page) => page.evaluate(() => (window as unknown as { __runs: string[][] }).__runs);
test("the solution node adds an existing project with dotnet sln add", async ({ workbench: page }) => {
await stubHost(page, ["Lib/Lib.csproj"]);
const solution = page.getByRole("treeitem", { name: /Solution 'Acme'/ });
await solution.click({ button: "right" });
await expect(page.getByRole("menuitem", { name: "Build .NET Project" })).toBeVisible();
if (SHOTS) await page.screenshot({ path: `${SHOTS}/b1-solution-menu.png`, animations: "disabled" });
await page.getByRole("menuitem", { name: "Add Existing Project…" }).click();
await expect
.poll(() => runs(page))
.toContainEqual(["sln", "/dev/acme-api/Acme.sln", "add", "/dev/acme-api/Lib/Lib.csproj"]);
// The project is listed afterwards, so no warning balloon.
await expect(page.getByText("was not added")).toHaveCount(0);
});
test("a same-named project the CLI skipped gets a warning", async ({ workbench: page }) => {
await stubHost(page, ["Other/Lib.csproj"]);
await page.getByRole("treeitem", { name: /Solution 'Acme'/ }).click({ button: "right" });
await page.getByRole("menuitem", { name: "Add Existing Project…" }).click();
await expect(page.getByText("The project was not added to the solution")).toBeVisible();
if (SHOTS) await page.screenshot({ path: `${SHOTS}/b1-same-name-warning.png`, animations: "disabled" });
});
test("a project node offers reference and solution edits", async ({ workbench: page }) => {
await stubHost(page, []);
await page.getByRole("treeitem", { name: /Solution 'Acme'/ }).click();
await page.keyboard.press("ArrowRight");
const app = page.getByRole("treeitem", { name: "App", exact: true });
await app.click({ button: "right" });
await expect(page.getByRole("menuitem", { name: "Add Project Reference…" })).toBeVisible();
await expect(page.getByRole("menuitem", { name: "Remove Project Reference" })).toBeVisible();
if (SHOTS) await page.screenshot({ path: `${SHOTS}/b1-project-menu.png`, animations: "disabled" });
await page.getByRole("menuitem", { name: "Remove from Solution" }).click();
await expect
.poll(() => runs(page))
.toContainEqual(["sln", "/dev/acme-api/Acme.sln", "remove", "/dev/acme-api/App/App.csproj"]);
});
// The model reloads after each edit (the stubbed workspace has no solution), so each edit gets a test.
test("Remove Project Reference removes the chosen reference", async ({ workbench: page }) => {
await stubHost(page, []);
await page.getByRole("treeitem", { name: /Solution 'Acme'/ }).click();
await page.keyboard.press("ArrowRight");
await page.getByRole("treeitem", { name: "App", exact: true }).click({ button: "right" });
await page.getByRole("menuitem", { name: "Remove Project Reference" }).hover();
await page.getByRole("menuitem", { name: "Core.csproj" }).click();
await expect
.poll(() => runs(page))
.toContainEqual(["remove", "/dev/acme-api/App/App.csproj", "reference", "/dev/acme-api/Core/Core.csproj"]);
});