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 { 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(); expect(screen.getByText("Desktop local mode")).toBeInTheDocument(); expect(screen.getByText("Switch server")).toBeInTheDocument(); }); it("renders remote desktop mode summary", () => { render(); 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( , ); 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(); expect(screen.queryByTestId("shell-connection-status-button")).toBeNull(); rerender(); 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(); fireEvent.click(screen.getByTestId("shell-connection-status-button")); await waitFor(() => expect(openConnectionManager).toHaveBeenCalledTimes(1)); expect(onError).toHaveBeenCalledWith("no bridge"); }); });