-
Notifications
You must be signed in to change notification settings - Fork 30
fix: Unblock cloud branch picker during slow remote load #2269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
charlesvien
merged 2 commits into
main
from
05-20-unblock_cloud_branch_picker_during_slow_remote_load
May 21, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
apps/code/src/renderer/features/git-interaction/components/BranchSelector.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| import { Theme } from "@radix-ui/themes"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| vi.mock("@features/git-interaction/state/gitInteractionStore", () => ({ | ||
| useGitInteractionStore: () => ({ actions: { openBranch: vi.fn() } }), | ||
| })); | ||
|
|
||
| vi.mock("@features/git-interaction/utils/getSuggestedBranchName", () => ({ | ||
| getSuggestedBranchName: vi.fn(() => null), | ||
| })); | ||
|
|
||
| vi.mock("@features/git-interaction/utils/gitCacheKeys", () => ({ | ||
| invalidateGitBranchQueries: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@renderer/trpc", () => ({ | ||
| useTRPC: () => ({ | ||
| git: { | ||
| getAllBranches: { queryOptions: () => ({ queryKey: ["mock"] }) }, | ||
| checkoutBranch: { mutationOptions: () => ({}) }, | ||
| }, | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("@renderer/utils/toast", () => ({ | ||
| toast: { error: vi.fn() }, | ||
| })); | ||
|
|
||
| const mutateMock = vi.fn(); | ||
| vi.mock("@tanstack/react-query", () => ({ | ||
| useQuery: () => ({ data: [], isLoading: false }), | ||
| useMutation: () => ({ mutate: mutateMock }), | ||
| })); | ||
|
|
||
| import { BranchSelector } from "./BranchSelector"; | ||
|
|
||
| function renderInTheme(children: React.ReactElement) { | ||
| return render(<Theme>{children}</Theme>); | ||
| } | ||
|
|
||
| describe("BranchSelector cloud mode", () => { | ||
| it("keeps the trigger enabled while the initial cloud load is in flight", () => { | ||
| renderInTheme( | ||
| <BranchSelector | ||
| repoPath="owner/repo" | ||
| currentBranch={null} | ||
| workspaceMode="cloud" | ||
| cloudBranches={[]} | ||
| cloudBranchesLoading={true} | ||
| cloudSearchQuery="" | ||
| onBranchSelect={vi.fn()} | ||
| onCloudSearchChange={vi.fn()} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.getByRole("combobox", { name: "Branch" })).toBeEnabled(); | ||
| }); | ||
|
|
||
| it("surfaces the 'Use input as branch name' action when the typed value is new", async () => { | ||
| const user = userEvent.setup(); | ||
| renderInTheme( | ||
| <BranchSelector | ||
| repoPath="owner/repo" | ||
| currentBranch={null} | ||
| workspaceMode="cloud" | ||
| cloudBranches={["main", "feature-a"]} | ||
| cloudBranchesLoading={false} | ||
| cloudSearchQuery="brand-new-branch" | ||
| onBranchSelect={vi.fn()} | ||
| onCloudSearchChange={vi.fn()} | ||
| />, | ||
| ); | ||
|
|
||
| await user.click(screen.getByRole("combobox", { name: "Branch" })); | ||
|
|
||
| expect( | ||
| await screen.findByText('Use "brand-new-branch" as branch name'), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("hides the typed-name action when the input exactly matches an existing branch", async () => { | ||
| const user = userEvent.setup(); | ||
| renderInTheme( | ||
| <BranchSelector | ||
| repoPath="owner/repo" | ||
| currentBranch={null} | ||
| workspaceMode="cloud" | ||
| cloudBranches={["main", "feature-a"]} | ||
| cloudBranchesLoading={false} | ||
| cloudSearchQuery="main" | ||
| onBranchSelect={vi.fn()} | ||
| onCloudSearchChange={vi.fn()} | ||
| />, | ||
| ); | ||
|
|
||
| await user.click(screen.getByRole("combobox", { name: "Branch" })); | ||
|
|
||
| expect( | ||
| screen.queryByText(/Use "main" as branch name/), | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("commits the typed value via onBranchSelect when the sentinel action is selected", async () => { | ||
| const user = userEvent.setup(); | ||
| const onBranchSelect = vi.fn(); | ||
| renderInTheme( | ||
| <BranchSelector | ||
| repoPath="owner/repo" | ||
| currentBranch={null} | ||
| workspaceMode="cloud" | ||
| cloudBranches={[]} | ||
| cloudBranchesLoading={true} | ||
| cloudSearchQuery="brand-new-branch" | ||
| onBranchSelect={onBranchSelect} | ||
| onCloudSearchChange={vi.fn()} | ||
| />, | ||
| ); | ||
|
|
||
| await user.click(screen.getByRole("combobox", { name: "Branch" })); | ||
| await user.click( | ||
| await screen.findByText('Use "brand-new-branch" as branch name'), | ||
| ); | ||
|
|
||
| expect(onBranchSelect).toHaveBeenCalledWith("brand-new-branch"); | ||
| }); | ||
|
|
||
| it("invokes onCloudBranchCommit when the typed value is committed (so the parent can reset the search)", async () => { | ||
| const user = userEvent.setup(); | ||
| const onCloudBranchCommit = vi.fn(); | ||
| renderInTheme( | ||
| <BranchSelector | ||
| repoPath="owner/repo" | ||
| currentBranch={null} | ||
| workspaceMode="cloud" | ||
| cloudBranches={[]} | ||
| cloudBranchesLoading={true} | ||
| cloudSearchQuery="brand-new-branch" | ||
| onBranchSelect={vi.fn()} | ||
| onCloudSearchChange={vi.fn()} | ||
| onCloudBranchCommit={onCloudBranchCommit} | ||
| />, | ||
| ); | ||
|
|
||
| await user.click(screen.getByRole("combobox", { name: "Branch" })); | ||
| await user.click( | ||
| await screen.findByText('Use "brand-new-branch" as branch name'), | ||
| ); | ||
|
|
||
| expect(onCloudBranchCommit).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.