Repository navigation
fix: keep Files in the selected account scope #2343
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8d1e6e6
fix: keep Files and attachments in the selected account scope
8ea8e47
test: assert signed-out catalog requests remain blocked
a76ee18
fix: keep unresolved account selections clearable
997c5b7
fix(files): preserve account recovery and complete selected mentions
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
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
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
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
131 changes: 131 additions & 0 deletions
131
components/Sandboxes/__tests__/SandboxAccountReadiness.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,131 @@ | ||
| // @vitest-environment jsdom | ||
| import React from "react"; | ||
| import { | ||
| act, | ||
| cleanup, | ||
| fireEvent, | ||
| render, | ||
| screen, | ||
| waitFor, | ||
| } from "@testing-library/react"; | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import { afterEach, beforeEach, expect, it, vi } from "vitest"; | ||
| import SandboxFileTree from "../SandboxFileTree"; | ||
| import AccountOverrideBadge from "@/components/AccountOverrideBadge"; | ||
| import { AccountOverrideProvider } from "@/providers/AccountOverrideProvider"; | ||
| import { fetchAccountIdByEmail } from "@/lib/accounts/fetchAccountIdByEmail"; | ||
|
|
||
| vi.mock("next/navigation", () => ({ | ||
| useSearchParams: () => | ||
| new URLSearchParams({ email: "selected@example.test" }), | ||
| useRouter: () => ({ replace: vi.fn() }), | ||
| })); | ||
| vi.mock("@privy-io/react-auth", () => ({ | ||
| usePrivy: () => ({ | ||
| user: { id: "actor-a" }, | ||
| authenticated: true, | ||
| getAccessToken: async () => "synthetic-token", | ||
| }), | ||
| })); | ||
| vi.mock("@/lib/api/getClientApiBaseUrl", () => ({ | ||
| getClientApiBaseUrl: () => "https://api.example.test", | ||
| })); | ||
| vi.mock("@/lib/accounts/fetchAccountIdByEmail", () => ({ | ||
| fetchAccountIdByEmail: vi.fn(), | ||
| })); | ||
| const fetchMock = vi.fn(); | ||
| let client: QueryClient; | ||
| function renderFiles() { | ||
| return render( | ||
| <QueryClientProvider client={client}> | ||
| <AccountOverrideProvider> | ||
| <AccountOverrideBadge /> | ||
| <SandboxFileTree /> | ||
| </AccountOverrideProvider> | ||
| </QueryClientProvider>, | ||
| ); | ||
| } | ||
| function expectUnresolvedFiles() { | ||
| expect(screen.getByText(/selected account is not ready/i)).toBeDefined(); | ||
| expect(screen.getByText(/clear.*account.*above/i)).toBeDefined(); | ||
| expect(screen.queryByText(/No files yet/)).toBeNull(); | ||
| expect(screen.queryByText("Loading files...")).toBeNull(); | ||
| expect( | ||
| screen.getByRole("button", { name: "Clear account override" }), | ||
| ).toBeDefined(); | ||
| expect(fetchMock).not.toHaveBeenCalled(); | ||
| } | ||
| beforeEach(() => { | ||
| window.sessionStorage.clear(); | ||
| vi.mocked(fetchAccountIdByEmail).mockReset(); | ||
| fetchMock.mockReset().mockImplementation(async (url: string) => { | ||
| const request = new URL(url); | ||
| if (request.pathname !== "/api/sandboxes") | ||
| throw new Error("Unexpected request"); | ||
| return { | ||
| ok: true, | ||
| json: async () => ({ | ||
| status: "success", | ||
| account_id: request.searchParams.get("account_id"), | ||
| sandboxes: [], | ||
| filetree: [], | ||
| }), | ||
| }; | ||
| }); | ||
| vi.stubGlobal("fetch", fetchMock); | ||
| client = new QueryClient({ defaultOptions: { queries: { retry: false } } }); | ||
| }); | ||
| afterEach(() => { | ||
| cleanup(); | ||
| client.clear(); | ||
| window.sessionStorage.clear(); | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| it("does not label a pending account as empty and returns to default only on clear", async () => { | ||
| let release!: (value: string) => void; | ||
| vi.mocked(fetchAccountIdByEmail).mockReturnValueOnce( | ||
| new Promise((resolve) => { | ||
| release = resolve; | ||
| }), | ||
| ); | ||
| renderFiles(); | ||
| await waitFor(() => expect(fetchAccountIdByEmail).toHaveBeenCalledTimes(1)); | ||
| expectUnresolvedFiles(); | ||
| fireEvent.click( | ||
| screen.getByRole("button", { name: "Clear account override" }), | ||
| ); | ||
| await waitFor(() => expect(screen.getByText(/No files yet/)).toBeDefined()); | ||
| expect(fetchMock).toHaveBeenCalledTimes(1); | ||
| expect( | ||
| new URL(fetchMock.mock.calls[0][0]).searchParams.has("account_id"), | ||
| ).toBe(false); | ||
| await act(async () => release("selected-account")); | ||
| expect(screen.queryByText(/selected account is not ready/i)).toBeNull(); | ||
| }); | ||
|
|
||
| it.each(["missing", "failed"])( | ||
| "distinguishes a %s account lookup from a settled empty account", | ||
| async (kind) => { | ||
| if (kind === "missing") | ||
| vi.mocked(fetchAccountIdByEmail).mockResolvedValue(null); | ||
| else | ||
| vi.mocked(fetchAccountIdByEmail).mockRejectedValue( | ||
| new Error("Account lookup failed"), | ||
| ); | ||
| renderFiles(); | ||
| await waitFor(() => expect(client.isFetching()).toBe(0)); | ||
| expectUnresolvedFiles(); | ||
| }, | ||
| ); | ||
|
|
||
| it("shows the real empty state after the selected account is resolved and its list loads", async () => { | ||
| vi.mocked(fetchAccountIdByEmail).mockResolvedValue("selected-account"); | ||
| renderFiles(); | ||
| await waitFor(() => expect(screen.getByText("No files yet.")).toBeDefined()); | ||
| expect(screen.queryByText(/selected account is not ready/i)).toBeNull(); | ||
| expect(fetchMock).toHaveBeenCalledTimes(1); | ||
| expect( | ||
| new URL(fetchMock.mock.calls[0][0]).searchParams.get("account_id"), | ||
| ).toBe("selected-account"); | ||
| }); |
32 changes: 32 additions & 0 deletions
32
components/Sandboxes/__tests__/SandboxFileTree.override.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,32 @@ | ||
| // @vitest-environment jsdom | ||
| import React from "react"; | ||
| import { expect, it, vi } from "vitest"; | ||
| import { | ||
| fixture, | ||
| render, | ||
| screen, | ||
| fireEvent, | ||
| SandboxFileTree, | ||
| } from "./guardedJourney.fixture"; | ||
|
|
||
| vi.mock("@/providers/AccountOverrideProvider", () => ({ | ||
| useAccountOverride: () => ({ accountIdOverride: "selected-b", email: null }), | ||
| })); | ||
|
|
||
| it("shows read-only files without upload controls for a selected account", () => { | ||
| render(<SandboxFileTree />); | ||
| expect(screen.getByText(/selected account are read-only/)).toBeDefined(); | ||
| expect(screen.getByText("Opened draft")).toBeDefined(); | ||
| expect(screen.queryByText("Drop replacement")).toBeNull(); | ||
| const protect = screen.getByRole("checkbox") as HTMLInputElement; | ||
| expect(protect.disabled).toBe(true); | ||
| fireEvent.click(protect); | ||
| expect(fixture.legacy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("does not offer uploads for an empty selected account", () => { | ||
| fixture.empty = true; | ||
| render(<SandboxFileTree />); | ||
| expect(screen.getByText("No files yet.")).toBeDefined(); | ||
| expect(screen.queryByLabelText("Upload files")).toBeNull(); | ||
| }); |
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.