mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-25 09:41:04 +01:00
test(ui): cover agent route sync after rename
This commit is contained in:
1 parent
cba11ea168
commit
c8ee3fc914
2 files changed
+45
-2
No files matched your search
@@ -1,8 +1,11 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { queryKeys } from "../lib/queryKeys";
|
||||
import {
|
||||
buildHeartbeatProgressLogLine,
|
||||
heartbeatProgressLogLineKey,
|
||||
syncAgentRouteAfterRename,
|
||||
} from "./AgentDetail";
|
||||
|
||||
describe("buildHeartbeatProgressLogLine", () => {
|
||||
@@ -59,3 +62,43 @@ describe("heartbeatProgressLogLineKey", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("syncAgentRouteAfterRename", () => {
|
||||
it("replaces stale agent routes after a rename changes the URL key", () => {
|
||||
const queryClient = new QueryClient();
|
||||
const navigate = vi.fn();
|
||||
queryClient.setQueryData(queryKeys.agents.detail("old-agent"), { id: "agent-1" });
|
||||
queryClient.setQueryData(queryKeys.agents.detail("renamed-agent"), { id: "agent-1" });
|
||||
|
||||
const redirected = syncAgentRouteAfterRename(
|
||||
queryClient,
|
||||
navigate,
|
||||
{ id: "agent-1", name: "Old Agent", urlKey: "old-agent" },
|
||||
{ id: "agent-1", name: "Renamed Agent", urlKey: "renamed-agent" },
|
||||
"configuration",
|
||||
);
|
||||
|
||||
expect(redirected).toBe(true);
|
||||
expect(navigate).toHaveBeenCalledWith("/agents/renamed-agent/configuration", { replace: true });
|
||||
expect(queryClient.getQueryData(queryKeys.agents.detail("old-agent"))).toBeUndefined();
|
||||
expect(queryClient.getQueryData(queryKeys.agents.detail("renamed-agent"))).toEqual({ id: "agent-1" });
|
||||
});
|
||||
|
||||
it("does not redirect when the canonical route ref stays the same", () => {
|
||||
const queryClient = new QueryClient();
|
||||
const navigate = vi.fn();
|
||||
queryClient.setQueryData(queryKeys.agents.detail("same-agent"), { id: "agent-1" });
|
||||
|
||||
const redirected = syncAgentRouteAfterRename(
|
||||
queryClient,
|
||||
navigate,
|
||||
{ id: "agent-1", name: "Same Agent", urlKey: "same-agent" },
|
||||
{ id: "agent-1", name: "Same Agent", urlKey: "same-agent" },
|
||||
"configuration",
|
||||
);
|
||||
|
||||
expect(redirected).toBe(false);
|
||||
expect(navigate).not.toHaveBeenCalled();
|
||||
expect(queryClient.getQueryData(queryKeys.agents.detail("same-agent"))).toEqual({ id: "agent-1" });
|
||||
});
|
||||
});
|
||||
@@ -1646,7 +1646,7 @@ function CostsSection({
|
||||
* replace the URL with the new canonical reference. Returns true when a
|
||||
* redirect happened.
|
||||
*/
|
||||
function syncAgentRouteAfterRename(
|
||||
export function syncAgentRouteAfterRename(
|
||||
queryClient: QueryClient,
|
||||
navigate: NavigateFunction,
|
||||
previous: { id: string; urlKey?: string | null; name?: string | null },
|
||||
|
||||
Reference in new issue
Block a user