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 { act, type ReactNode } from "react"; |
| 2 | import { createRoot } from "react-dom/client"; |
| 3 | import { expect, it, vi } from "vite-plus/test"; |
| 4 | |
| 5 | const checkout = vi.hoisted(() => ({ |
| 6 | projectRoot: "", |
| 7 | worktreePath: null as string | null, |
| 8 | branches: [] as Array<{ name: string; worktreePath: string | null }>, |
| 9 | })); |
| 10 | |
| 11 | vi.mock("@react-navigation/native", () => ({ useNavigation: () => ({}) })); |
| 12 | vi.mock("../../../components/ui/SheetHeader", () => ({ SheetHeader: () => null })); |
| 13 | vi.mock("../../../components/ui/FitSheet", () => ({ |
| 14 | FitSheet: ({ children }: { children: ReactNode }) => <div>{children}</div>, |
| 15 | })); |
| 16 | vi.mock("../../../native/StackHeader", () => ({ NativeStackScreenOptions: () => null })); |
| 17 | vi.mock("../../../components/ui/FormSection", () => ({ |
| 18 | FormSection: () => null, |
| 19 | FormField: () => null, |
| 20 | })); |
| 21 | vi.mock("../../../components/ui/ListSection", () => ({ |
| 22 | ListSection: ({ children }: { children: ReactNode }) => <div>{children}</div>, |
| 23 | })); |
| 24 | vi.mock("../../../components/ui/ListChoiceRow", () => ({ |
| 25 | ListChoiceRow: (props: { label: string; description: string; disabled: boolean }) => ( |
| 26 | <button disabled={props.disabled}> |
| 27 | <span>{props.label}</span> |
| 28 | <span>{props.description}</span> |
| 29 | </button> |
| 30 | ), |
| 31 | })); |
| 32 | vi.mock("./gitSheetComponents", () => ({ SheetActionButton: () => null })); |
| 33 | vi.mock("../../../state/entities", () => ({})); |
| 34 | vi.mock("../../../state/threads", () => ({})); |
| 35 | vi.mock("../../../state/use-thread-selection", () => ({ |
| 36 | useThreadSelection: () => ({ |
| 37 | selectedThread: { environmentId: "environment-1", worktreePath: checkout.worktreePath }, |
| 38 | selectedThreadProject: { workspaceRoot: checkout.projectRoot }, |
| 39 | }), |
| 40 | })); |
| 41 | vi.mock("../../../state/use-thread-detail", () => ({ |
| 42 | useSelectedThreadWorktreePath: () => checkout.worktreePath, |
| 43 | })); |
| 44 | vi.mock("../../../state/use-selected-thread-git-state", () => ({ |
| 45 | useSelectedThreadGitState: () => ({ |
| 46 | selectedThreadBranches: checkout.branches, |
| 47 | selectedThreadBranchesLoading: false, |
| 48 | gitOperationLabel: null, |
| 49 | }), |
| 50 | })); |
| 51 | vi.mock("../../../state/use-selected-thread-git-actions", () => ({ |
| 52 | useSelectedThreadGitActions: () => ({ canChangeThreadBranch: true }), |
| 53 | })); |
| 54 | vi.mock("../../../state/query", () => ({ useEnvironmentQuery: () => ({ data: null }) })); |
| 55 | vi.mock("../../../state/vcs", () => ({ vcsEnvironment: { branch: () => null } })); |
| 56 | |
| 57 | import { GitBranchesSheet } from "./GitBranchesSheet"; |
| 58 | |
| 59 | it("recognizes both the main checkout and a linked worktree as this thread's checkout", () => { |
| 60 | const directory = "/repo"; |
| 61 | const linked = "/repo-linked"; |
| 62 | checkout.projectRoot = directory; |
| 63 | checkout.branches = [ |
| 64 | { name: "feature/available", worktreePath: null }, |
| 65 | { name: "feature/linked", worktreePath: linked }, |
| 66 | { name: "main", worktreePath: directory }, |
| 67 | ]; |
| 68 | (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; |
| 69 | const container = document.createElement("div"); |
| 70 | const root = createRoot(container); |
| 71 | const rows = () => { |
| 72 | act(() => { |
| 73 | root.render( |
| 74 | <GitBranchesSheet |
| 75 | route={{ params: { environmentId: "environment-1", threadId: "thread-1" } }} |
| 76 | />, |
| 77 | ); |
| 78 | }); |
| 79 | return [...container.querySelectorAll("button")].map((button) => ({ |
| 80 | name: button.querySelectorAll("span")[0]?.textContent, |
| 81 | subtitle: button.querySelectorAll("span")[1]?.textContent, |
| 82 | disabled: button.disabled, |
| 83 | })); |
| 84 | }; |
| 85 | try { |
| 86 | checkout.worktreePath = null; |
| 87 | expect(rows()).toEqual([ |
| 88 | { name: "feature/available", subtitle: "Local branch", disabled: false }, |
| 89 | { name: "feature/linked", subtitle: "Checked out in another worktree", disabled: true }, |
| 90 | { name: "main", subtitle: "Checked out in this thread", disabled: false }, |
| 91 | ]); |
| 92 | |
| 93 | checkout.worktreePath = linked; |
| 94 | expect(rows()).toEqual([ |
| 95 | { name: "feature/available", subtitle: "Local branch", disabled: false }, |
| 96 | { name: "feature/linked", subtitle: "Checked out in this thread", disabled: false }, |
| 97 | { name: "main", subtitle: "Checked out in another worktree", disabled: true }, |
| 98 | ]); |
| 99 | } finally { |
| 100 | act(() => root.unmount()); |
| 101 | } |
| 102 | }); |