The best way to control Claude Code, Codex and more from any computer or phone

main
ts 55 lines 1.95 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2 import { createComposerTypingGuardState, updateComposerTypingGuard } from "./composerTypingGuard";
3
4 function typing() {
5 return updateComposerTypingGuard(
6 updateComposerTypingGuard(createComposerTypingGuardState(), { type: "focus" }),
7 { type: "type", now: 1000 },
8 );
9 }
10
11 describe("composer typing guard", () => {
12 it.each(["idle", "send", "blur"] as const)(
13 "releases on %s and never re-holds the request",
14 (type) => {
15 let state = updateComposerTypingGuard(typing(), {
16 type: "requests",
17 requestIds: ["question"],
18 now: 1200,
19 });
20 state = updateComposerTypingGuard(state, { type });
21 expect([...state.held]).toEqual([]);
22 const released = state.held;
23 state = updateComposerTypingGuard(state, { type });
24 expect(state.held).toBe(released);
25 state = updateComposerTypingGuard(state, { type: "focus" });
26 state = updateComposerTypingGuard(state, { type: "type", now: 2000 });
27 state = updateComposerTypingGuard(state, { type: "requests", requestIds: [], now: 2100 });
28 state = updateComposerTypingGuard(state, {
29 type: "requests",
30 requestIds: ["question", "new-question"],
31 now: 2200,
32 });
33 expect([...state.held]).toEqual(["new-question"]);
34 },
35 );
36
37 it("does not hide a request that already took over when typing starts", () => {
38 let state = updateComposerTypingGuard(createComposerTypingGuardState(), {
39 type: "requests",
40 requestIds: ["question"],
41 now: 0,
42 });
43 const held = state.held;
44 state = updateComposerTypingGuard(state, { type: "focus" });
45 state = updateComposerTypingGuard(state, { type: "type", now: 1000 });
46 expect(state.held).toBe(held);
47 state = updateComposerTypingGuard(state, {
48 type: "requests",
49 requestIds: ["question"],
50 now: 1100,
51 });
52 expect([...state.held]).toEqual([]);
53 expect(state.held).toBe(held);
54 });
55 });