Files
fusion/packages/dashboard/app/components/__tests__/ShellConnectionStatus.test.tsx
Fusion 3df6dab652 docs(FN-3408): document shell connection chrome contracts
- Add architecture notes describing shell connection chrome contracts
- Expand dashboard README with shell chrome expectations and integration details
- Add desktop README note aligning desktop shell behavior with documented contracts

Fusion-Task-Id: FN-3408
2026-05-08 00:40:15 -07:00

62 lines
2.7 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();
});
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");
});
});