The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { act, type ReactNode } from "react"; |
| 3 | import { createRoot } from "react-dom/client"; |
| 4 | import { expect, it, vi } from "vite-plus/test"; |
| 5 | |
| 6 | const queries = vi.hoisted(() => [] as { cwd: string | null; searchQuery: string }[]); |
| 7 | |
| 8 | vi.mock("@t3tools/client-runtime/state/filesystem", () => ({ |
| 9 | resolveFilesystemReadAccess: () => ({ canReadFiles: true, isPending: false }), |
| 10 | })); |
| 11 | vi.mock("../../state/session", () => ({ environmentSession: { sessionStateAtom: () => null } })); |
| 12 | vi.mock("../../state/query", () => ({ useEnvironmentQuery: () => ({ data: null, error: null }) })); |
| 13 | vi.mock("../../state/presentation", () => ({ |
| 14 | useEnvironmentPresentation: () => ({ isReady: true, presentation: null }), |
| 15 | })); |
| 16 | vi.mock("../settings/appearance/AppearancePreferencesProvider", () => ({ |
| 17 | useAppearancePreferences: () => ({ themeAppearance: "dark" }), |
| 18 | })); |
| 19 | vi.mock("./preload-workspace-file", () => ({ preloadWorkspaceFileContents: () => {} })); |
| 20 | vi.mock("./FileTreeBrowser", () => ({ FileTreeBrowser: () => null })); |
| 21 | vi.mock("./useFileTreeEntries", () => ({ |
| 22 | useFileTreeEntries: (input: { cwd: string | null; searchQuery: string }) => { |
| 23 | queries.push({ cwd: input.cwd, searchQuery: input.searchQuery }); |
| 24 | return { refresh: () => {}, selectPath: () => {} }; |
| 25 | }, |
| 26 | })); |
| 27 | vi.mock("../../components/ui/SheetPane", () => ({ |
| 28 | SheetPane: ({ children }: { children: ReactNode }) => children, |
| 29 | })); |
| 30 | vi.mock("../../components/ui/ScreenContent", () => ({ |
| 31 | ScreenContent: ({ children }: { children: ReactNode }) => children, |
| 32 | })); |
| 33 | vi.mock("../../components/ui/AppBar", () => ({ |
| 34 | AppBar: (props: { search: { value: string; onChangeText: (value: string) => void } }) => ( |
| 35 | <input |
| 36 | value={props.search.value} |
| 37 | onChange={(event) => props.search.onChangeText(event.target.value)} |
| 38 | /> |
| 39 | ), |
| 40 | })); |
| 41 | |
| 42 | import { ThreadFileNavigatorPane } from "./thread-file-navigator-pane"; |
| 43 | |
| 44 | it("starts unfiltered when the mounted pane switches to another workspace", () => { |
| 45 | (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; |
| 46 | const container = document.body.appendChild(document.createElement("div")); |
| 47 | const root = createRoot(container); |
| 48 | const render = (cwd: string) => |
| 49 | act(() => |
| 50 | root.render( |
| 51 | <ThreadFileNavigatorPane |
| 52 | cwd={cwd} |
| 53 | environmentId={EnvironmentId.make("env")} |
| 54 | projectName="Files" |
| 55 | selectedPath={null} |
| 56 | onSelectFile={() => {}} |
| 57 | />, |
| 58 | ), |
| 59 | ); |
| 60 | try { |
| 61 | render("/first"); |
| 62 | const input = container.querySelector("input")!; |
| 63 | act(() => { |
| 64 | Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call( |
| 65 | input, |
| 66 | "alpha", |
| 67 | ); |
| 68 | input.dispatchEvent(new Event("input", { bubbles: true })); |
| 69 | }); |
| 70 | expect(queries.at(-1)).toEqual({ cwd: "/first", searchQuery: "alpha" }); |
| 71 | |
| 72 | render("/second"); |
| 73 | expect(queries.at(-1)).toEqual({ cwd: "/second", searchQuery: "" }); |
| 74 | expect(container.querySelector("input")!.value).toBe(""); |
| 75 | } finally { |
| 76 | act(() => root.unmount()); |
| 77 | container.remove(); |
| 78 | } |
| 79 | }); |