fix(webui): polish remote setup and simplify connection dialogs
This commit is contained in:
1 parent
5aa91b66cc
commit
0ffdf86619
28 files changed
+972
-149
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { HostCompatibilityDialog } from "@/components/remote/HostCompatibilityDialog";
|
||||
import i18n from "@/i18n";
|
||||
import type { RemoteProfile } from "@/lib/remote-instances";
|
||||
|
||||
afterEach(async () => {
|
||||
cleanup();
|
||||
vi.restoreAllMocks();
|
||||
await i18n.changeLanguage("en");
|
||||
});
|
||||
|
||||
describe("host compatibility facts", () => {
|
||||
it.each(["en", "zh-CN", "zh-TW", "es", "fr", "pt-BR", "id", "ja", "ko", "vi"])(
|
||||
"distinguishes update precautions from the external guide (%s)", async (language) => {
|
||||
await i18n.changeLanguage(language);
|
||||
const profile: RemoteProfile = {
|
||||
id: "host", name: "Team server", host: "ubuntu@example.test", port: 22,
|
||||
config_path: "", ssh_config: "", identity_file: "", runtime_user: "", connected: false,
|
||||
compatibility: { status: "update_host", client_version: "0.3.5", host_version: "0.3.4" },
|
||||
};
|
||||
render(<HostCompatibilityDialog profile={profile} onClose={vi.fn()} />);
|
||||
const dialog = screen.getByRole("dialog");
|
||||
const guide = i18n.t("remote.compatibility.guide");
|
||||
const preparation = i18n.t("remote.compatibility.preparation");
|
||||
expect(preparation).not.toBe("remote.compatibility.preparation");
|
||||
expect(preparation).not.toBe(guide);
|
||||
expect(within(dialog).getAllByText(guide)).toHaveLength(1);
|
||||
expect(within(dialog).getByRole("link", { name: guide })).toBeVisible();
|
||||
expect(dialog.querySelector("summary")).toHaveTextContent(preparation);
|
||||
expect(dialog.querySelector("details")).toHaveTextContent(i18n.t("remote.compatibility.serverUpdateHint"));
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps the last host report during exit, but never reuses it for a new host", async () => {
|
||||
const getStyle = window.getComputedStyle.bind(window);
|
||||
vi.spyOn(window, "getComputedStyle").mockImplementation((node) => {
|
||||
const style = getStyle(node);
|
||||
if (node.getAttribute("role") !== "dialog") return style;
|
||||
return new Proxy(style, { get(target, property) {
|
||||
if (property === "animationName") return node.getAttribute("data-state") === "closed" ? "exit" : "enter";
|
||||
const value = Reflect.get(target, property, target);
|
||||
return typeof value === "function" ? value.bind(target) : value;
|
||||
} });
|
||||
});
|
||||
const profile: RemoteProfile = {
|
||||
id: "host", name: "Team server", host: "ubuntu@example.test", port: 22,
|
||||
config_path: "", ssh_config: "", identity_file: "", runtime_user: "", connected: true,
|
||||
compatibility: { status: "compatible", client_version: "0.3.5", host_version: "0.3.5" },
|
||||
};
|
||||
const onClose = vi.fn();
|
||||
const { rerender } = render(<HostCompatibilityDialog profile={profile} onClose={onClose} />);
|
||||
const dialog = screen.getByRole("dialog");
|
||||
rerender(<HostCompatibilityDialog profile={undefined} onClose={onClose} />);
|
||||
expect(dialog).toHaveAttribute("data-state", "closed");
|
||||
expect(dialog).toHaveTextContent("Team server");
|
||||
expect(dialog).toHaveTextContent("No update needed to connect.");
|
||||
expect(dialog).not.toHaveTextContent("Not checked yet");
|
||||
const exit = new Event("animationend", { bubbles: true });
|
||||
Object.defineProperty(exit, "animationName", { value: "exit" });
|
||||
fireEvent(dialog, exit);
|
||||
await waitFor(() => expect(dialog).not.toBeInTheDocument());
|
||||
rerender(<HostCompatibilityDialog profile={{ ...profile, id: "another", name: "Another server", compatibility: undefined }} onClose={onClose} />);
|
||||
expect(screen.getByRole("dialog")).toHaveTextContent("Another server");
|
||||
expect(screen.getByRole("status")).toHaveTextContent("Not checked yet");
|
||||
});
|
||||
it.each(["en", "zh-CN", "zh-TW", "es", "fr", "pt-BR", "id", "ja", "ko", "vi"])(
|
||||
"keeps full version values and their labels in a compact read-only group (%s)",
|
||||
async (language) => {
|
||||
await i18n.changeLanguage(language);
|
||||
const version = "0.3.5-dev+long-build-identifier-0123456789abcdef";
|
||||
const profile: RemoteProfile = {
|
||||
id: "host", name: "Team server", host: "ubuntu@example.test",
|
||||
port: 22, config_path: "", ssh_config: "", identity_file: "", runtime_user: "",
|
||||
connected: true,
|
||||
compatibility: { status: "compatible", client_version: version, host_version: version },
|
||||
};
|
||||
render(<HostCompatibilityDialog profile={profile} onClose={vi.fn()} />);
|
||||
const dialog = screen.getByRole("dialog");
|
||||
const terms = within(dialog).getAllByRole("term");
|
||||
expect(terms.map((term) => term.textContent)).toEqual([
|
||||
i18n.t("remote.compatibility.client"), i18n.t("remote.compatibility.host"),
|
||||
]);
|
||||
const values = within(dialog).getAllByRole("definition");
|
||||
expect(values.map((value) => value.textContent)).toEqual([version, version]);
|
||||
// Read-only facts must not inherit the settings controls' 60px row floor.
|
||||
expect(dialog.querySelector(".settings-list-row")).toBeNull();
|
||||
expect(dialog.querySelector(".break-all, .truncate")).toBeNull();
|
||||
expect(within(dialog).getByRole("status")).toHaveTextContent(i18n.t("remote.compatibility.compatibleHint"));
|
||||
expect(within(dialog).queryByRole("link")).not.toBeInTheDocument();
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -32,6 +32,24 @@ beforeEach(() => window.localStorage.clear());
|
||||
afterEach(() => { cleanup(); vi.restoreAllMocks(); });
|
||||
|
||||
describe("host switcher", () => {
|
||||
it("announces the host only once when its display name is the hostname", () => {
|
||||
const value = { ...picker(1), name: "team-host", hostname: "team-host" };
|
||||
render(<HostNavigationContext.Provider value={value}><HostSwitcher /></HostNavigationContext.Provider>);
|
||||
expect(screen.getByRole("status").textContent).toBe("team-host · Connected");
|
||||
expect(screen.getByRole("button", { name: "Switch host" })).toHaveAttribute("title", "team-host · Connected");
|
||||
});
|
||||
|
||||
it("does not borrow the local socket's Connected status while restoring a remote", () => {
|
||||
const value = picker(1);
|
||||
value.currentId = value.profiles[0].id;
|
||||
value.name = value.profiles[0].name;
|
||||
value.profiles[0].state = "connecting";
|
||||
value.pending = value.profiles[0];
|
||||
render(<HostNavigationContext.Provider value={value}><HostSwitcher /></HostNavigationContext.Provider>);
|
||||
expect(screen.getByRole("status")).not.toHaveTextContent("Connected");
|
||||
expect(screen.getByRole("status")).toHaveTextContent("Connecting");
|
||||
});
|
||||
|
||||
it("keeps the current host identity visible until a pending switch is ready", async () => {
|
||||
const value = picker(2);
|
||||
value.pending = value.profiles[0];
|
||||
|
||||
@@ -27,6 +27,7 @@ describe("paired network route", () => {
|
||||
it("shows direct only when no saved route is configured", () => {
|
||||
render(<PairRouteSettings id="paired" />);
|
||||
expect(screen.getByRole("combobox")).toHaveTextContent("Direct connection");
|
||||
expect(screen.getByText(i18n.t("remote.pair.routeHint"))).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Save changes" })).toBeDisabled();
|
||||
});
|
||||
it("shows saving, then confirms the saved route without connecting", async () => {
|
||||
|
||||
@@ -65,6 +65,76 @@ async function reviewed() {
|
||||
}
|
||||
|
||||
describe("quick pairing", () => {
|
||||
it("keeps retry available if saving finishes as the invitation expires", async () => {
|
||||
const timer = vi.spyOn(window, "setTimeout");
|
||||
view(); await reviewed();
|
||||
const expiry = timer.mock.calls.find(([, delay]) => typeof delay === "number" && delay > 599_000)?.[0];
|
||||
expect(typeof expiry).toBe("function");
|
||||
let finish!: (value: { id: string }) => void;
|
||||
mocks.action.mockImplementation(() => new Promise((resolve) => { finish = resolve; }));
|
||||
mocks.connect.mockRejectedValueOnce(new Error("ssh_connection_closed"));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect", exact: true }));
|
||||
act(() => { if (typeof expiry === "function") expiry(); });
|
||||
await act(async () => finish({ id: "paired-server" }));
|
||||
expect(await screen.findByRole("button", { name: "Retry", exact: true })).toBeEnabled();
|
||||
expect(screen.getByRole("heading", { name: "Open this nanobot?" })).toBeVisible();
|
||||
expect(screen.queryByRole("button", { name: "Get a new command" })).not.toBeInTheDocument();
|
||||
});
|
||||
it("replaces an expired confirmation with a new-command action", async () => {
|
||||
const timer = vi.spyOn(window, "setTimeout");
|
||||
view(); await reviewed();
|
||||
const expiry = timer.mock.calls.find(([, delay]) => typeof delay === "number" && delay > 599_000)?.[0];
|
||||
expect(typeof expiry).toBe("function");
|
||||
act(() => { if (typeof expiry === "function") expiry(); });
|
||||
expect(screen.getByRole("button", { name: "Get a new command" })).toBeEnabled();
|
||||
expect(screen.queryByRole("heading", { name: "Open this nanobot?" })).not.toBeInTheDocument();
|
||||
expect(mocks.connect).not.toHaveBeenCalled();
|
||||
});
|
||||
it.each(["pair_expired", "pair_used"])("offers a new command when manual review reports %s", async (code) => {
|
||||
mocks.action.mockImplementation(async (action: string) => {
|
||||
if (action === "remote.pair_start") return request();
|
||||
if (action === "remote.pair_preview") throw new Error(code);
|
||||
return {};
|
||||
});
|
||||
view();
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Copy command" })).toBeEnabled());
|
||||
chooseOtherWay("Use a connection code instead");
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "Connection code" }), { target: { value: "nbpc1.expired" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Review connection" }));
|
||||
const restart = await screen.findByRole("button", { name: "Get a new command" });
|
||||
expect(screen.queryByRole("textbox", { name: "Connection code" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Back" })).not.toBeInTheDocument();
|
||||
fireEvent.click(restart);
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Copy command" })).toBeEnabled());
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||
expect(mocks.action.mock.calls.filter(([action]) => action === "remote.pair_start")).toHaveLength(2);
|
||||
expect(mocks.connect).not.toHaveBeenCalled();
|
||||
});
|
||||
it("does not start work when mounted only for the closing animation", () => {
|
||||
render(<Dialog open><DialogContent><QuickPairSetup active={false} onSSH={vi.fn()} onClose={vi.fn()} /></DialogContent></Dialog>);
|
||||
expect(mocks.action).not.toHaveBeenCalled();
|
||||
});
|
||||
it("ignores a preview arriving during the closing animation", async () => {
|
||||
let resolve!: (value: typeof preview) => void;
|
||||
mocks.action.mockImplementation(() => new Promise((done) => { resolve = done; }));
|
||||
const returned = { id: "request-1", code: "nbpc1.encrypted" };
|
||||
const content = (active: boolean) => <Dialog open><DialogContent><QuickPairSetup active={active} returned={returned} onSSH={vi.fn()} onClose={vi.fn()} /></DialogContent></Dialog>;
|
||||
const result = render(content(true));
|
||||
result.rerender(content(false));
|
||||
await act(async () => resolve(preview));
|
||||
expect(screen.queryByRole("heading", { name: "Open this nanobot?" })).not.toBeInTheDocument();
|
||||
expect(mocks.connect).not.toHaveBeenCalled();
|
||||
expect(mocks.action).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
it("cleans up an invitation arriving during the closing animation", async () => {
|
||||
let resolve!: (value: ReturnType<typeof request>) => void;
|
||||
mocks.action.mockImplementation((action: string) => action === "remote.pair_start" ? new Promise((done) => { resolve = done; }) : Promise.resolve({}));
|
||||
const content = (active: boolean) => <Dialog open><DialogContent><QuickPairSetup active={active} onSSH={vi.fn()} onClose={vi.fn()} /></DialogContent></Dialog>;
|
||||
const result = render(content(true));
|
||||
result.rerender(content(false));
|
||||
await act(async () => resolve(request()));
|
||||
expect(mocks.action).toHaveBeenCalledWith("remote.pair_cancel", { id: "request-1" }, 65000);
|
||||
});
|
||||
it("uses the same copyable revocation code block in pairing details", async () => {
|
||||
returnedView();
|
||||
await screen.findByRole("heading", { name: "Open this nanobot?" });
|
||||
|
||||
@@ -92,6 +92,63 @@ function chooseExistingSSH() {
|
||||
}
|
||||
|
||||
describe("remote instance UX", () => {
|
||||
it.each([
|
||||
["webui_compatibility_unknown", "unknown"],
|
||||
["host_update_required", "update_host"],
|
||||
["client_update_required", "update_client"],
|
||||
])("a restored host with %s offers version guidance, not a network diagnosis", async (code, status) => {
|
||||
rememberSelectedRemote(connection);
|
||||
mocks.read.mockResolvedValue({ available: true, client_version: "1.0.0", profiles: [{ ...profile,
|
||||
compatibility: { status, client_version: "1.0.0", host_version: "2.0.0" } }] });
|
||||
mocks.request.mockRejectedValue(new Error(code));
|
||||
view();
|
||||
await screen.findByText(i18n.t(`remote.compatibility.${status}`));
|
||||
expect(screen.queryByText("Server connection lost", { exact: true })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Version & compatibility" }));
|
||||
expect(within(await screen.findByRole("dialog")).getByRole("status")).toHaveTextContent(i18n.t(`remote.compatibility.${status}`));
|
||||
expect(screen.queryByRole("textbox", { name: "SSH address" })).not.toBeInTheDocument();
|
||||
expect(readSelectedRemote()?.id).toBe(profile.id);
|
||||
});
|
||||
|
||||
it.each(["compatible", "unknown", "update_host", "update_client"] as const)("explains %s compatibility without updating either machine", async (status) => {
|
||||
mocks.read.mockResolvedValue({ available: true, client_version: "1.0.0", profiles: [{ ...profile,
|
||||
compatibility: { status, client_version: "1.0.0", host_version: "2.0.0" } }] });
|
||||
view(); await openDirectory();
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Version & compatibility" }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
expect(within(dialog).getByText("1.0.0")).toBeVisible();
|
||||
expect(within(dialog).getByText("2.0.0")).toBeVisible();
|
||||
expect(within(dialog).getByRole("status")).toHaveTextContent(i18n.t(`remote.compatibility.${status}`));
|
||||
if (status === "compatible") expect(within(dialog).queryByRole("link")).not.toBeInTheDocument();
|
||||
else expect(within(dialog).getByRole("link", { name: "Update guide" })).toHaveAttribute("rel", "noopener noreferrer");
|
||||
expect(mocks.request).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps an unchecked host distinct from an incompatible host", async () => {
|
||||
view(); await openDirectory();
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Version & compatibility" }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
expect(within(dialog).getByRole("status")).toHaveTextContent("Not checked yet");
|
||||
expect(within(dialog).queryByRole("link")).not.toBeInTheDocument();
|
||||
expect(mocks.request).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("opens version guidance after an incompatible connection without opening SSH configuration", async () => {
|
||||
mocks.read.mockResolvedValue({ available: true, profiles: [{ ...profile, compatibility: {
|
||||
status: "update_client", client_version: "1.0.0", host_version: "2.0.0",
|
||||
} }] });
|
||||
mocks.request.mockRejectedValueOnce(new Error("client_update_required"));
|
||||
view(false, true);
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Team server ubuntu@example.test" }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
expect(within(dialog).getByRole("status")).toHaveTextContent("Update this computer");
|
||||
expect(within(dialog).queryByRole("textbox", { name: "SSH address" })).not.toBeInTheDocument();
|
||||
expect(readSelectedRemote()).toBeNull();
|
||||
expect(mocks.request).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it.each([false, true])("renames an open server without reloading its view (paired: %s)", async (paired) => {
|
||||
let saved = { ...profile, paired, connected: true };
|
||||
mocks.read.mockImplementation(async () => ({ available: true, profiles: [saved] }));
|
||||
@@ -112,6 +169,8 @@ describe("remote instance UX", () => {
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Rename", exact: true }));
|
||||
const input = await screen.findByRole("textbox", { name: "Name", exact: true });
|
||||
expect(input).toHaveValue("Team server");
|
||||
expect(input).toHaveAccessibleName("Name");
|
||||
expect(within(screen.getByRole("dialog")).queryByText("Name", { exact: true })).not.toBeInTheDocument();
|
||||
expect(input).toHaveFocus();
|
||||
expect(input).toHaveAttribute("maxlength", "64");
|
||||
expect(screen.getByRole("button", { name: "Save changes" })).toBeDisabled();
|
||||
@@ -125,11 +184,24 @@ describe("remote instance UX", () => {
|
||||
expect(document.title).toBe("腾讯云 nanobot · nanobot");
|
||||
expect(source.postMessage).toHaveBeenLastCalledWith(expect.objectContaining({ type: "init", name: "腾讯云 nanobot" }), "http://127.0.0.1:23456");
|
||||
expect(mocks.request.mock.calls.map(([action]) => action)).toEqual(["remote.connect", "remote.rename"]);
|
||||
await chooseHost("腾讯云 nanobot ubuntu@example.test");
|
||||
fireEvent.click(screen.getByRole("button", { name: "腾讯云 nanobot ubuntu@example.test" }));
|
||||
expect(screen.getByTitle("nanobot on 腾讯云 nanobot")).toBe(frame);
|
||||
expect(mocks.request).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("explains a paired route once while preserving its credentials boundary", async () => {
|
||||
mocks.read.mockResolvedValue({ available: true, profiles: [{ ...profile, paired: true }] });
|
||||
view(); await openDirectory();
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: i18n.t("remote.pair.route") }));
|
||||
const dialog = await screen.findByRole("dialog", { name: i18n.t("remote.pair.route") });
|
||||
expect(within(dialog).getAllByText(i18n.t("remote.pair.routeHint"))).toHaveLength(1);
|
||||
expect(dialog).toHaveAccessibleDescription(i18n.t("remote.pair.routeHint"));
|
||||
expect(within(dialog).queryByText(i18n.t("remote.pair.routeDescription"))).not.toBeInTheDocument();
|
||||
expect(within(dialog).getByRole("combobox", { name: i18n.t("remote.pair.route") })).toBeEnabled();
|
||||
expect(mocks.request).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects a blank name, preserves input on failure and lets the user retry or cancel", async () => {
|
||||
view(); await openDirectory();
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
|
||||
@@ -143,6 +215,7 @@ describe("remote instance UX", () => {
|
||||
fireEvent.change(input, { target: { value: "Cloud" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save changes" }));
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent(i18n.t("remote.errors.local_io_error"));
|
||||
expect(input).toHaveAccessibleDescription(i18n.t("remote.errors.local_io_error"));
|
||||
expect(input).toHaveValue("Cloud");
|
||||
expect(screen.getByRole("button", { name: "Save changes" })).toBeEnabled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
@@ -311,15 +384,15 @@ describe("remote instance UX", () => {
|
||||
expect(readSelectedRemote()?.id).toBe(profile.id);
|
||||
});
|
||||
|
||||
it("treats local sidebar navigation as an explicit host choice without disconnecting the server", async () => {
|
||||
it("does not expose local sidebar actions while managing a remote", async () => {
|
||||
view();
|
||||
await chooseHost("Team server ubuntu@example.test");
|
||||
const frame = await readyRemote();
|
||||
await openDirectory();
|
||||
fireEvent.click(screen.getByRole("button", { name: "New topic" }));
|
||||
expect(screen.queryByRole("region", { name: "Remote connections" })).not.toBeInTheDocument();
|
||||
expect(screen.getByText("Local conversations")).toBeVisible();
|
||||
expect(readSelectedRemote()).toBeNull();
|
||||
expect(screen.queryByRole("button", { name: "New topic" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("region", { name: "Remote connections" })).toBeVisible();
|
||||
expect(screen.getByText("Local conversations")).not.toBeVisible();
|
||||
expect(readSelectedRemote()?.id).toBe(profile.id);
|
||||
expect(frame).toBeInTheDocument();
|
||||
expect(mocks.request.mock.calls.some(([action]) => action === "remote.disconnect")).toBe(false);
|
||||
});
|
||||
@@ -665,6 +738,46 @@ describe("remote instance UX", () => {
|
||||
expect(mocks.request.mock.calls.some(([action]) => action === "remote.disconnect")).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps the remote sidebar and scopes management layout messages to its verified frame", async () => {
|
||||
view();
|
||||
await chooseHost("Team server ubuntu@example.test");
|
||||
const frame = await readyRemote();
|
||||
const source = { postMessage: vi.fn() };
|
||||
Object.defineProperty(frame, "contentWindow", { value: source });
|
||||
act(() => fireEvent.load(frame));
|
||||
const nonce = source.postMessage.mock.calls[0][0].nonce;
|
||||
const message = (data: Record<string, unknown>, origin = "http://127.0.0.1:23456") => act(() => {
|
||||
window.dispatchEvent(new MessageEvent("message", { source: source as unknown as Window,
|
||||
origin, data: { channel: HOST_BRIDGE, nonce, ...data } }));
|
||||
});
|
||||
message({ type: "ready" });
|
||||
document.documentElement.classList.remove("dark");
|
||||
message({ type: "surface", theme: "dark", rect: { left: 272, top: 0, width: 900, height: 800 } });
|
||||
expect(document.documentElement).not.toHaveClass("dark");
|
||||
message({ type: "open", anchor: { left: 40, top: 500, width: 150, height: 32 } });
|
||||
fireEvent.click(await screen.findByRole("menuitem", { name: "Manage connections…" }));
|
||||
const panel = screen.getByTestId("remote-management-surface");
|
||||
expect(panel).toHaveStyle({ left: "272px" });
|
||||
expect(document.documentElement).toHaveClass("dark");
|
||||
expect(frame).toBeVisible();
|
||||
expect(screen.getByText("Local conversations")).not.toBeVisible();
|
||||
expect(source.postMessage).toHaveBeenLastCalledWith(expect.objectContaining({ managing: true }), "http://127.0.0.1:23456");
|
||||
message({ type: "surface", rect: { left: 500, top: 0, width: 900, height: 800 } }, "https://untrusted.example");
|
||||
message({ type: "surface", nonce: "wrong", rect: { left: 500, top: 0, width: 900, height: 800 } });
|
||||
message({ type: "surface", rect: { left: -20, top: 0, width: 900, height: 800 } });
|
||||
expect(panel).toHaveStyle({ left: "272px" });
|
||||
message({ type: "surface", theme: "dark", rect: { left: 64, top: 0, width: 1100, height: 800 } });
|
||||
expect(panel).toHaveStyle({ left: "64px" });
|
||||
message({ type: "leave-management", nonce: "wrong" });
|
||||
expect(panel).toBeInTheDocument();
|
||||
message({ type: "leave-management" });
|
||||
expect(panel).not.toBeInTheDocument();
|
||||
expect(document.documentElement).not.toHaveClass("dark");
|
||||
expect(frame).toBeVisible();
|
||||
expect(readSelectedRemote()?.id).toBe(profile.id);
|
||||
expect(mocks.request.mock.calls.map(([action]) => action)).toEqual(["remote.connect"]);
|
||||
});
|
||||
|
||||
it("uses clear Chinese navigation and returns from the connection form without saving", async () => {
|
||||
await i18n.changeLanguage("zh-CN");
|
||||
view();
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { SettingsTextEditor } from "@/components/settings/shared/SettingsTextEditor";
|
||||
import i18n from "@/i18n";
|
||||
|
||||
beforeEach(async () => { await i18n.changeLanguage("en"); });
|
||||
afterEach(() => { cleanup(); vi.restoreAllMocks(); });
|
||||
|
||||
describe("settings text editor copy", () => {
|
||||
it.each([undefined, "", " ", "Headers", " Headers "])(
|
||||
"does not repeat its title as a description (%s)", async (description) => {
|
||||
const warning = vi.spyOn(console, "warn");
|
||||
render(<SettingsTextEditor title="Headers" description={description} value="{}" onSave={vi.fn()} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Headers" }));
|
||||
const dialog = await screen.findByRole("dialog", { name: "Headers" });
|
||||
expect(within(dialog).getAllByText("Headers")).toHaveLength(1);
|
||||
expect(dialog).not.toHaveAttribute("aria-describedby");
|
||||
expect(dialog).toHaveAccessibleDescription("");
|
||||
expect(within(dialog).getByRole("textbox", { name: "Headers" })).toHaveValue("{}");
|
||||
expect(within(dialog).getByRole("textbox", { name: "Headers" })).toHaveFocus();
|
||||
expect(warning).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps meaningful help associated with the dialog and saves edited values", async () => {
|
||||
const warning = vi.spyOn(console, "warn");
|
||||
const save = vi.fn();
|
||||
const help = "Use a JSON object for additional request headers.";
|
||||
render(<SettingsTextEditor title="Headers" description={help} value="{}" onSave={save} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Headers" }));
|
||||
const dialog = await screen.findByRole("dialog", { name: "Headers" });
|
||||
expect(dialog).toHaveAccessibleDescription(help);
|
||||
expect(within(dialog).getAllByText(help)).toHaveLength(1);
|
||||
fireEvent.change(within(dialog).getByRole("textbox", { name: "Headers" }), { target: { value: '{"Accept":"application/json"}' } });
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: i18n.t("settings.actions.save"), exact: true }));
|
||||
expect(save).toHaveBeenCalledWith('{"Accept":"application/json"}');
|
||||
await waitFor(() => expect(dialog).not.toBeInTheDocument());
|
||||
expect(warning).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user