дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
Run/Debug Configurations opened their own local file dialog and hid every Browse button in a remote window, so .env files, the working directory and Tomcat paths on the remote host could only be typed. The run configuration form and the Tomcat settings now use the project-host chooser, which browses the remote host in a remote window and opens the system dialog locally. Fixes #7715
115 рядки
5.1 KiB
TypeScript
115 рядки
5.1 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
|
|
const open = vi.hoisted(() => vi.fn());
|
|
vi.mock("@tauri-apps/plugin-dialog", () => ({ open }));
|
|
vi.mock("@/platform/ipc", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("@/platform/ipc")>()),
|
|
isTauri: () => true,
|
|
}));
|
|
|
|
import { registerHostPathChooser } from "@/platform/choosePath";
|
|
import type { RunConfig } from "@/platform/ipc";
|
|
import { useProject } from "@/platform/project";
|
|
import { useRemote } from "@/platform/remote";
|
|
import { ConfigForm } from "./ConfigForm";
|
|
import { tomcatType } from "./tomcat";
|
|
import { newConfigOfType } from "./types";
|
|
|
|
const config: RunConfig = {
|
|
id: "app",
|
|
name: "app",
|
|
kind: "shell",
|
|
command: "python3",
|
|
args: [],
|
|
cwd: null,
|
|
env: {},
|
|
detected: false,
|
|
isTest: false,
|
|
debugAdapter: null,
|
|
envFiles: [".env"],
|
|
};
|
|
|
|
afterEach(cleanup);
|
|
|
|
describe("Environment variables", () => {
|
|
it("adds the .env files chosen in the file dialog, relative to the project root", async () => {
|
|
useProject.setState({ project: { root: "/work/app" } as never });
|
|
open.mockResolvedValue(["/work/app/.env", "/work/app/config/dev.env", "/elsewhere/shared.env"]);
|
|
const onChange = vi.fn();
|
|
render(<ConfigForm config={config} all={[]} type={undefined} errors={{}} onChange={onChange} modifyRequest={0} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Browse for .env Files" }));
|
|
await waitFor(() =>
|
|
expect(onChange).toHaveBeenCalledWith(
|
|
expect.objectContaining({ envFiles: [".env", "config/dev.env", "/elsewhere/shared.env"] }),
|
|
),
|
|
);
|
|
expect(open).toHaveBeenCalledWith(expect.objectContaining({ multiple: true, defaultPath: "/work/app" }));
|
|
});
|
|
});
|
|
|
|
describe("path fields", () => {
|
|
it("pick the working directory relative to the project root", async () => {
|
|
useProject.setState({ project: { root: "/work/app" } as never });
|
|
open.mockResolvedValue("/work/app/server");
|
|
const onChange = vi.fn();
|
|
render(<ConfigForm config={config} all={[]} type={undefined} errors={{}} onChange={onChange} modifyRequest={0} />);
|
|
fireEvent.click(screen.getAllByRole("button", { name: "Browse…" })[0]!);
|
|
await waitFor(() => expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ cwd: "server" })));
|
|
expect(open).toHaveBeenLastCalledWith(expect.objectContaining({ directory: true, multiple: false }));
|
|
});
|
|
|
|
it("pick a file or a directory for a configuration type's path fields", async () => {
|
|
useProject.setState({ project: { root: "/work/app" } as never });
|
|
const tomcat = { ...newConfigOfType(tomcatType, []), kind: "tomcat-fields", params: { deployment: "war" } };
|
|
const onChange = vi.fn();
|
|
render(<ConfigForm config={tomcat} all={[]} type={tomcatType} errors={{}} onChange={onChange} modifyRequest={0} />);
|
|
const home = screen.getByRole("textbox", { name: "Tomcat installation directory" });
|
|
open.mockResolvedValue("/opt/tomcat");
|
|
fireEvent.click(home.parentElement!.querySelector("button")!);
|
|
await waitFor(() =>
|
|
expect(onChange).toHaveBeenCalledWith(
|
|
expect.objectContaining({ params: expect.objectContaining({ tomcatHome: "/opt/tomcat" }) }),
|
|
),
|
|
);
|
|
expect(open).toHaveBeenLastCalledWith(expect.objectContaining({ directory: true }));
|
|
const war = screen.getByRole("textbox", { name: "Deployment path" });
|
|
open.mockResolvedValue("/work/app/build/app.war");
|
|
fireEvent.click(war.parentElement!.querySelector("button")!);
|
|
await waitFor(() => expect(open).toHaveBeenLastCalledWith(expect.objectContaining({ directory: false })));
|
|
});
|
|
});
|
|
|
|
describe("in a remote window", () => {
|
|
it("browses the remote host for .env files and paths", async () => {
|
|
const choose = vi
|
|
.fn()
|
|
.mockResolvedValueOnce(["/srv/app/.env.remote", "/srv/app/config/dev.env"])
|
|
.mockResolvedValueOnce(["/srv/app/server"]);
|
|
const unregister = registerHostPathChooser(choose);
|
|
useRemote.setState({ session: { root: "/srv/app", os: "linux", commands: [] } as never });
|
|
useProject.setState({ project: { root: "/srv/app" } as never });
|
|
open.mockClear();
|
|
try {
|
|
const onChange = vi.fn();
|
|
render(
|
|
<ConfigForm config={config} all={[]} type={undefined} errors={{}} onChange={onChange} modifyRequest={0} />,
|
|
);
|
|
fireEvent.click(screen.getByRole("button", { name: "Browse for .env Files" }));
|
|
await waitFor(() =>
|
|
expect(onChange).toHaveBeenCalledWith(
|
|
expect.objectContaining({ envFiles: [".env", ".env.remote", "config/dev.env"] }),
|
|
),
|
|
);
|
|
expect(choose).toHaveBeenLastCalledWith(expect.objectContaining({ multiple: true, defaultPath: "/srv/app" }));
|
|
fireEvent.click(screen.getAllByRole("button", { name: "Browse…" })[0]!);
|
|
await waitFor(() => expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ cwd: "server" })));
|
|
expect(choose).toHaveBeenLastCalledWith(expect.objectContaining({ directory: true }));
|
|
expect(open).not.toHaveBeenCalled();
|
|
} finally {
|
|
unregister();
|
|
useRemote.setState({ session: null });
|
|
}
|
|
});
|
|
});
|