File size: 1,028 Bytes
4e7644b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { render } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { AgentStatusPollingController } from ".";

const mocks = vi.hoisted(() => ({
  poll: vi.fn(),
  refreshAgents: vi.fn(),
  agents: [
    {
      id: "agent",
      name: "Agent",
      description: "",
      workspace_dir: "",
      enabled: true,
      pinned: false,
      startup_status: "starting" as const,
    },
  ],
}));

vi.mock("@/hooks/useAgentStatusPolling", () => ({
  useAgentStatusPolling: mocks.poll,
}));

vi.mock("@/stores/agentStore", () => ({
  useAgentStore: (selector: (state: typeof mocks) => unknown) =>
    selector(mocks),
}));

describe("AgentStatusPollingController", () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it("connects the shared store to the single polling hook", () => {
    render(<AgentStatusPollingController />);

    expect(mocks.poll).toHaveBeenCalledOnce();
    expect(mocks.poll).toHaveBeenCalledWith(mocks.agents, mocks.refreshAgents);
  });
});