The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { DesktopCliCommandState } from "@t3tools/contracts"; |
| 2 | import { AtomRegistry } from "effect/reactivity"; |
| 3 | import * as AsyncResult from "effect/reactivity/AsyncResult"; |
| 4 | import { afterAll, describe, expect, it, vi } from "vite-plus/test"; |
| 5 | |
| 6 | import { desktopCliCommandStateAtom } from "./desktopCliCommand"; |
| 7 | |
| 8 | const getState = vi.fn<() => Promise<DesktopCliCommandState>>(); |
| 9 | vi.stubGlobal("window", { desktopBridge: { cliCommand: { getState } } }); |
| 10 | |
| 11 | describe("desktopCliCommandStateAtom", () => { |
| 12 | afterAll(() => { |
| 13 | vi.unstubAllGlobals(); |
| 14 | }); |
| 15 | |
| 16 | it("reloads stale state when Settings mounts it again", async () => { |
| 17 | getState.mockResolvedValue({ |
| 18 | supported: true, |
| 19 | installedPath: null, |
| 20 | onPath: false, |
| 21 | launcherPath: null, |
| 22 | }); |
| 23 | using now = vi.spyOn(Date, "now").mockReturnValue(1_000_000); |
| 24 | const registry = AtomRegistry.make(); |
| 25 | |
| 26 | const unmountFirst = registry.mount(desktopCliCommandStateAtom); |
| 27 | await vi.waitFor(() => { |
| 28 | const result = registry.get(desktopCliCommandStateAtom); |
| 29 | expect(AsyncResult.isInitial(result) || result.waiting).toBe(false); |
| 30 | }); |
| 31 | unmountFirst(); |
| 32 | await vi.waitFor(() => expect(registry.getNodes().size).toBe(1)); |
| 33 | |
| 34 | now.mockReturnValue(1_060_000); |
| 35 | const unmountSecond = registry.mount(desktopCliCommandStateAtom); |
| 36 | await vi.waitFor(() => expect(getState).toHaveBeenCalledTimes(2)); |
| 37 | unmountSecond(); |
| 38 | registry.dispose(); |
| 39 | }); |
| 40 | }); |