mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-01 14:12:51 +00:00
* 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>
60 lines
2.1 KiB
TypeScript
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",
|
|
});
|
|
});
|
|
});
|