Files
fusion/packages/dashboard/app/components/__tests__/ShellConnectionStatus.test.tsx
Fusion 30d0553c64 feat(FN-3409): add shell regression matrix for mobile, desktop, and dashboa
The merge completes a multi-step shell regression hardening effort spanning desktop, mobile, and dashboard entry points, adding 12 test files or test expansions to lock down the shell preload and native contracts. A companion fix exempts internal coordination tools (`list_agents`, `delegate_task`, e

Fusion-Task-Id: FN-3409
2026-05-08 01:57:55 -07:00

63 lines
2.8 KiB
TypeScript

import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { ShellConnectionStatus } from "../ShellConnectionStatus";
import type { ShellConnectionNativeResult } from "../../shell-native";
function makeStatus(overrides: Partial<ShellConnectionNativeResult> = {}): ShellConnectionNativeResult {
return {
hostKind: "desktop-shell",
available: true,
mode: "remote",
profileId: "p1",
profileLabel: "Prod",
serverOrigin: "https://fusion.example.com",
openConnectionManager: vi.fn(async () => ({ ok: true })),
...overrides,
};
}
describe("ShellConnectionStatus", () => {
it("renders local desktop mode", () => {
render(<ShellConnectionStatus status={makeStatus({ mode: "local" })} />);
expect(screen.getByText("Desktop local mode")).toBeInTheDocument();
expect(screen.getByText("Switch server")).toBeInTheDocument();
});
it("renders remote desktop mode summary", () => {
render(<ShellConnectionStatus status={makeStatus()} />);
expect(screen.getByText("Desktop")).toBeInTheDocument();
expect(screen.getByText("Prod · https://fusion.example.com")).toBeInTheDocument();
expect(screen.getByText("Switch server")).toBeInTheDocument();
expect(screen.getByTestId("shell-connection-status-button")).toHaveAttribute("type", "button");
});
it("renders remote mobile mode summary", () => {
render(
<ShellConnectionStatus
status={makeStatus({ hostKind: "mobile-shell", mode: "remote", profileLabel: "Tablet", serverOrigin: "https://remote.example.com" })}
/>,
);
expect(screen.getByText("Mobile")).toBeInTheDocument();
expect(screen.getByText("Tablet · https://remote.example.com")).toBeInTheDocument();
expect(screen.getByText("Manage connections")).toBeInTheDocument();
});
it("hides in browser/unsupported mode", () => {
const { rerender } = render(<ShellConnectionStatus status={makeStatus({ hostKind: "browser", available: false })} />);
expect(screen.queryByTestId("shell-connection-status-button")).toBeNull();
rerender(<ShellConnectionStatus status={makeStatus({ hostKind: "mobile-shell", available: false })} />);
expect(screen.queryByTestId("shell-connection-status-button")).toBeNull();
});
it("invokes action and reports failures", async () => {
const onError = vi.fn();
const openConnectionManager = vi.fn(async () => ({ ok: false as const, reason: "failed" as const, error: "no bridge" }));
render(<ShellConnectionStatus status={makeStatus({ openConnectionManager })} onError={onError} />);
fireEvent.click(screen.getByTestId("shell-connection-status-button"));
await waitFor(() => expect(openConnectionManager).toHaveBeenCalledTimes(1));
expect(onError).toHaveBeenCalledWith("no bridge");
});
});