The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { ServerConfigStreamEvent } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it, vi } from "vite-plus/test"; |
| 3 | |
| 4 | const mocks = vi.hoisted(() => ({ |
| 5 | state: null as unknown as import("effect/reactivity").Atom.Writable<{ |
| 6 | readonly latestEvent: ServerConfigStreamEvent | null; |
| 7 | }>, |
| 8 | addToast: vi.fn<(toast: { readonly title?: unknown }) => void>(), |
| 9 | })); |
| 10 | |
| 11 | // The event atom is derived from server state, as in production; nothing else reads it. |
| 12 | vi.mock(import("../state/server"), async () => { |
| 13 | const { Atom } = await import("effect/reactivity"); |
| 14 | mocks.state = Atom.make<{ readonly latestEvent: ServerConfigStreamEvent | null }>({ |
| 15 | latestEvent: null, |
| 16 | }); |
| 17 | return { |
| 18 | primaryServerConfigAtom: Atom.make(null), |
| 19 | primaryServerConfigEventAtom: Atom.make((get) => get(mocks.state).latestEvent), |
| 20 | } as never; |
| 21 | }); |
| 22 | vi.mock(import("../state/primaryEnvironment"), async () => { |
| 23 | const { Atom } = await import("effect/reactivity"); |
| 24 | return { primaryEnvironmentIdAtom: Atom.make(null) } as never; |
| 25 | }); |
| 26 | vi.mock( |
| 27 | import("./KeybindingsConfigWarning"), |
| 28 | () => ({ KeybindingsConfigWarning: () => null }) as never, |
| 29 | ); |
| 30 | vi.mock( |
| 31 | import("./ui/toast"), |
| 32 | () => |
| 33 | ({ |
| 34 | toastManager: { add: mocks.addToast }, |
| 35 | stackedThreadToast: (toast: unknown) => toast, |
| 36 | }) as never, |
| 37 | ); |
| 38 | |
| 39 | import { appAtomRegistry } from "../rpc/atomRegistry"; |
| 40 | import { startKeybindingsUpdateToasts } from "./KeybindingsUpdateToast"; |
| 41 | |
| 42 | function keybindingsUpdated(issues: ReadonlyArray<unknown>): ServerConfigStreamEvent { |
| 43 | return { type: "keybindingsUpdated", payload: { keybindings: [], issues } } as never; |
| 44 | } |
| 45 | |
| 46 | describe("startKeybindingsUpdateToasts", () => { |
| 47 | it("only toasts invalid reloads the server reports after start", () => { |
| 48 | const stop = startKeybindingsUpdateToasts(); |
| 49 | try { |
| 50 | appAtomRegistry.set(mocks.state, { latestEvent: keybindingsUpdated([]) }); |
| 51 | appAtomRegistry.set(mocks.state, { |
| 52 | latestEvent: keybindingsUpdated([ |
| 53 | { kind: "keybindings.malformed-config", message: "Unexpected token" }, |
| 54 | ]), |
| 55 | }); |
| 56 | |
| 57 | expect(mocks.addToast.mock.calls.map(([toast]) => toast.title)).toEqual([ |
| 58 | "Invalid keybindings configuration", |
| 59 | ]); |
| 60 | } finally { |
| 61 | stop(); |
| 62 | } |
| 63 | }); |
| 64 | }); |