Files
paseo/packages/app/src/plugins/host-navigation.test.tsx
T
Omer Cohenandpaseo-bot[bot] 1d4c3a2722 feat(plugin): add host navigation capabilities for plugin surfaces (#3901)
* feat(plugin): add optional agent navigation capability

* feat(plugin): extend host navigation capability

* fix(plugin): preserve navigation tests after sdk rebase

* fix(plugin): scope host navigation contracts

---------

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
2026-08-29 21:33:09 +02:00

60 lines
2.1 KiB
TypeScript

/**
* @vitest-environment jsdom
*/
import { act, renderHook } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { navigateToWorkspace } from "@/stores/navigation-active-workspace-store";
import { navigateToAgent } from "@/utils/navigate-to-agent";
import { usePluginHostNavigation } from "./host-navigation";
vi.mock("@/utils/navigate-to-agent", () => ({
navigateToAgent: vi.fn(),
}));
vi.mock("@/stores/navigation-active-workspace-store", () => ({
navigateToWorkspace: vi.fn(),
}));
const navigateToAgentMock = vi.mocked(navigateToAgent);
const navigateToWorkspaceMock = vi.mocked(navigateToWorkspace);
describe("usePluginHostNavigation", () => {
beforeEach(() => {
navigateToAgentMock.mockReset();
navigateToWorkspaceMock.mockReset();
});
it("opens agents and workspaces on the rendering host", () => {
const { result } = renderHook(() => usePluginHostNavigation("host-1"));
act(() => result.current.openAgent({ agentId: "agent-1" }));
act(() => result.current.openWorkspace({ workspaceId: "workspace-1" }));
expect(navigateToAgentMock).toHaveBeenCalledWith({ serverId: "host-1", agentId: "agent-1" });
expect(navigateToWorkspaceMock).toHaveBeenCalledWith({
serverId: "host-1",
workspaceId: "workspace-1",
});
});
it("keeps the capability stable until the rendering host changes", () => {
const { result, rerender } = renderHook(({ serverId }) => usePluginHostNavigation(serverId), {
initialProps: { serverId: "host-1" },
});
const initialNavigation = result.current;
rerender({ serverId: "host-1" });
expect(result.current).toBe(initialNavigation);
rerender({ serverId: "host-2" });
expect(result.current).not.toBe(initialNavigation);
act(() => result.current.openAgent({ agentId: "agent-2" }));
act(() => result.current.openWorkspace({ workspaceId: "workspace-2" }));
expect(navigateToAgentMock).toHaveBeenCalledWith({ serverId: "host-2", agentId: "agent-2" });
expect(navigateToWorkspaceMock).toHaveBeenCalledWith({
serverId: "host-2",
workspaceId: "workspace-2",
});
});
});