import { cleanup, render, screen } from "@testing-library/react"; import { afterEach, describe, expect, it, vi } from "vitest"; import { pluginRegistry } from "@/lib/plugins/registry"; import { ChatInputPluginActions, type ChatInputActionsSlotProps, } from "./chat-input-plugin-actions"; const SLOT = "chat-input-actions"; // Minimal store: the wrapper only reads taskSessionsByTask.itemsByTaskId. const mockState = { taskSessionsByTask: { itemsByTaskId: { t1: [ { id: "s1", task_id: "t1" }, { id: "s2", task_id: "t1" }, ], }, }, }; vi.mock("@/components/state-provider", () => ({ useOptionalAppStore: (selector: (s: typeof mockState) => unknown) => selector(mockState), })); describe("ChatInputPluginActions", () => { afterEach(() => { cleanup(); pluginRegistry.unregisterPlugin("plugin-a"); }); it("renders nothing when no plugin registered a chat-input-actions component", () => { const { container } = render( , ); expect(container.innerHTML).toBe(""); }); it("forwards task context, the active session, and all session ids", () => { pluginRegistry.forPlugin("plugin-a").registerComponent(SLOT, ({ slotProps }) => { const ctx = slotProps as ChatInputActionsSlotProps; return (
{`${ctx.taskId}|${ctx.activeSessionId}|${ctx.sessionIds.join(",")}`}
); }); render(); expect(screen.getByTestId("plugin-icon").textContent).toBe("t1|s2|s1,s2"); }); it("includes the active session id even when the store list omits it", () => { pluginRegistry.forPlugin("plugin-a").registerComponent(SLOT, ({ slotProps }) => { const ctx = slotProps as ChatInputActionsSlotProps; return
{ctx.sessionIds.join(",")}
; }); // taskId with no store entry -> only the active session propagates. render(); expect(screen.getByTestId("plugin-icon").textContent).toBe("s9"); }); it("propagates only the active session when taskId is null", () => { pluginRegistry.forPlugin("plugin-a").registerComponent(SLOT, ({ slotProps }) => { const ctx = slotProps as ChatInputActionsSlotProps; return (
{`${ctx.taskId}|${ctx.activeSessionId}|${ctx.sessionIds.join(",")}`}
); }); render(); expect(screen.getByTestId("plugin-icon").textContent).toBe("null|s9|s9"); }); });