Files
fusion/packages/dashboard/app/components/__tests__/NativeShellConnectionManager.test.tsx
Fusion 419c6f3b31 feat(FN-3400): add native shell connection handoff, plugin management CLI/l
This merge adds a complete plugin management system (FN-3565) with CLI commands, a loader, runner, and dashboard routes, along with project-scoped auth storage (FN-3544), native shell connection support for mobile (FN-3400) spanning onboarding, connection manager, and remote desktop handoff, and ref

Fusion-Task-Id: FN-3400
2026-05-06 05:29:56 -07:00

75 lines
2.8 KiB
TypeScript

import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { NativeShellConnectionManager } from "../NativeShellConnectionManager";
function createShellApi() {
return {
getState: vi.fn(),
listProfiles: vi.fn(),
saveProfile: vi.fn(async () => ({ id: "p1", name: "Prod", serverUrl: "https://fusion.example.com", createdAt: "", updatedAt: "" })),
deleteProfile: vi.fn(async () => undefined),
setActiveProfile: vi.fn(async () => ({ host: "mobile-shell", activeProfileId: "p1", profiles: [] })),
setDesktopMode: vi.fn(async () => ({ host: "desktop-shell", desktopMode: "remote", activeProfileId: null, profiles: [] })),
startQrScan: vi.fn(),
openConnectionManager: vi.fn(),
subscribe: vi.fn(() => () => undefined),
};
}
describe("NativeShellConnectionManager", () => {
it("switches desktop mode", async () => {
const shellApi = createShellApi();
render(
<NativeShellConnectionManager
open={true}
shellApi={shellApi}
shellState={{ host: "desktop-shell", desktopMode: "remote", activeProfileId: null, profiles: [] }}
onClose={vi.fn()}
/>,
);
fireEvent.click(screen.getByText("Local"));
await waitFor(() => expect(shellApi.setDesktopMode).toHaveBeenCalledWith("local"));
});
it("activates and deletes profiles", async () => {
const shellApi = createShellApi();
render(
<NativeShellConnectionManager
open={true}
shellApi={shellApi}
shellState={{ host: "mobile-shell", activeProfileId: null, profiles: [{ id: "p1", name: "Prod", serverUrl: "https://fusion.example.com", authToken: null, createdAt: "", updatedAt: "" }] }}
onClose={vi.fn()}
/>,
);
fireEvent.click(screen.getByLabelText("Use Prod"));
fireEvent.click(screen.getByLabelText("Delete Prod"));
await waitFor(() => {
expect(shellApi.setActiveProfile).toHaveBeenCalledWith("p1");
expect(shellApi.deleteProfile).toHaveBeenCalledWith("p1");
});
});
it("edits and saves active profile", async () => {
const shellApi = createShellApi();
render(
<NativeShellConnectionManager
open={true}
shellApi={shellApi}
shellState={{ host: "mobile-shell", activeProfileId: "p1", profiles: [{ id: "p1", name: "Prod", serverUrl: "https://fusion.example.com", authToken: null, createdAt: "", updatedAt: "" }] }}
onClose={vi.fn()}
/>,
);
fireEvent.change(screen.getByDisplayValue("https://fusion.example.com"), { target: { value: "https://next.example.com" } });
fireEvent.click(screen.getByText("Save"));
await waitFor(() => {
expect(shellApi.saveProfile).toHaveBeenCalled();
expect(shellApi.setActiveProfile).toHaveBeenCalledWith("p1");
});
});
});