Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

1.4 KB
Raw Blame
import { fireEvent, render, screen } from "@testing-library/react";

const automationRow = {
  id: "auto-1",
  name: "Ping webhook",
  trigger: { id: "trig-1" },
  action: { type: "WEBHOOK" },
};

const useQueryMock = vi.fn();

vi.mock("next-auth/react", () => ({
  useSession: () => ({ data: null, status: "unauthenticated" }),
}));

vi.mock("@/src/utils/api", () => ({
  api: {
    automations: {
      getAutomations: {
        useQuery: () => useQueryMock(),
      },
    },
    useUtils: () => ({
      automations: { getAutomations: { fetch: vi.fn(async () => []) } },
    }),
  },
}));

import { MonitorAutomationsPanel } from "./MonitorAutomationsPanel";

describe("MonitorAutomationsPanel selection", () => {
  it("does not mutate the memoized set: toggling the same unselected row twice reports it selected both times", () => {
    useQueryMock.mockReturnValue({ data: [automationRow], isPending: false });
    const onTriggerIdsChange = vi.fn();
    render(
      <MonitorAutomationsPanel
        projectId="p1"
        triggerIds={[]}
        onTriggerIdsChange={onTriggerIdsChange}
      />,
    );
    const row = screen.getByRole("button", { name: /ping webhook/i });
    fireEvent.click(row);
    fireEvent.click(row);
    expect(onTriggerIdsChange).toHaveBeenNthCalledWith(1, ["trig-1"]);
    expect(onTriggerIdsChange).toHaveBeenNthCalledWith(2, ["trig-1"]);
  });
});