test(web): add mux refresh test for useSessionEvents

This commit is contained in:
Gaurav Bhola 2026-04-06 23:02:30 -07:00
parent 1fa88cdf9d
commit 5cb17c081a
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { renderHook, waitFor } from "@testing-library/react";
import { useSessionEvents } from "../useSessionEvents";
import type { DashboardSession } from "@/lib/types";
const now = new Date().toISOString();
const s1 = { id: "s1", projectId: "proj", lastActivityAt: now } as unknown as DashboardSession;
describe("useSessionEvents - mux", () => {
beforeEach(() => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ sessions: [s1] }),
} as unknown as Response),
);
});
afterEach(() => {
vi.unstubAllGlobals();
vi.clearAllTimers();
});
it("triggers refresh when mux patch contains unknown id", async () => {
const initialSessions = [s1];
const muxSessions = [
{ id: "s1", status: "working", activity: "active", attentionLevel: "none", lastActivityAt: now },
{ id: "s2", status: "working", activity: "active", attentionLevel: "none", lastActivityAt: now },
];
renderHook(() => useSessionEvents(initialSessions, "proj", muxSessions));
await waitFor(() => {
expect(fetch).toHaveBeenCalledWith(
"/api/sessions?project=proj",
expect.objectContaining({ signal: expect.any(AbortSignal) }),
);
});
});
});