test: cover typing idle gate

This commit is contained in:
Peter Steinberger
2026-01-06 03:13:39 +00:00
parent ca8f66f844
commit 58186aa56e

View File

@@ -0,0 +1,33 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { createTypingController } from "./typing.js";
describe("typing controller", () => {
afterEach(() => {
vi.useRealTimers();
});
it("stops after run completion and dispatcher idle", async () => {
vi.useFakeTimers();
const onReplyStart = vi.fn(async () => {});
const typing = createTypingController({
onReplyStart,
typingIntervalSeconds: 1,
typingTtlMs: 30_000,
});
await typing.startTypingLoop();
expect(onReplyStart).toHaveBeenCalledTimes(1);
vi.advanceTimersByTime(2_000);
expect(onReplyStart).toHaveBeenCalledTimes(3);
typing.markRunComplete();
vi.advanceTimersByTime(1_000);
expect(onReplyStart).toHaveBeenCalledTimes(4);
typing.markDispatchIdle();
vi.advanceTimersByTime(2_000);
expect(onReplyStart).toHaveBeenCalledTimes(4);
});
});