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 { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { act, useLayoutEffect } from "react"; |
| 3 | import { createRoot } from "react-dom/client"; |
| 4 | import { expect, it, vi } from "vite-plus/test"; |
| 5 | |
| 6 | const harness = vi.hoisted(() => ({ saved: [] as unknown[] })); |
| 7 | |
| 8 | vi.mock("../../state/preferences", () => ({ saveMobilePreferences: {} })); |
| 9 | vi.mock("../../state/use-atom-command", () => ({ |
| 10 | useAtomCommand: () => async (value: unknown) => { |
| 11 | harness.saved.push(value); |
| 12 | return { _tag: "Success", value: undefined }; |
| 13 | }, |
| 14 | })); |
| 15 | |
| 16 | import { HomeListOptionsProvider, useHomeListOptions } from "./home-list-options"; |
| 17 | |
| 18 | const ENVIRONMENT = "env-1" as EnvironmentId; |
| 19 | const AVAILABLE = new Set([ENVIRONMENT]); |
| 20 | |
| 21 | it("saves the scope from every update made in one event", async () => { |
| 22 | harness.saved = []; |
| 23 | let controls: ReturnType<typeof useHomeListOptions> | undefined; |
| 24 | function Probe() { |
| 25 | const result = useHomeListOptions(AVAILABLE); |
| 26 | useLayoutEffect(() => { |
| 27 | controls = result; |
| 28 | }); |
| 29 | return null; |
| 30 | } |
| 31 | |
| 32 | const root = createRoot(document.createElement("div")); |
| 33 | await act(async () => |
| 34 | root.render( |
| 35 | <HomeListOptionsProvider projectGroupingMode="repository"> |
| 36 | <Probe /> |
| 37 | </HomeListOptionsProvider>, |
| 38 | ), |
| 39 | ); |
| 40 | act(() => { |
| 41 | controls!.setSelectedEnvironmentId(ENVIRONMENT); |
| 42 | controls!.setSelectedProjectKey("env-1:project-1"); |
| 43 | }); |
| 44 | |
| 45 | expect(harness.saved.at(-1)).toEqual({ |
| 46 | threadListFilters: { environmentId: ENVIRONMENT, projectKey: "env-1:project-1" }, |
| 47 | }); |
| 48 | expect(controls!.options.selectedEnvironmentId).toBe(ENVIRONMENT); |
| 49 | expect(controls!.options.selectedProjectKey).toBe("env-1:project-1"); |
| 50 | act(() => root.unmount()); |
| 51 | }); |