Marketplace: toast a refused account change and refresh after a saved one (PR review #7)

changeAccount now catches a rejected updateMarketplace (e.g. an account for
another host) and toasts it instead of leaving an unhandled rejection, and
refreshes the marketplace after a successful change so the old fetch error
is replaced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-27 13:13:11 -07:00
co-authored by Claude Opus 5.5
parent c87299dda3
commit fe15f541b9
2 changed files with 61 additions and 3 deletions
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { useAppState } from "../../store/appState";
import type { AppSettings, CatalogItem, MarketplaceSnapshot } from "../../lib/types";
import type { MarketplaceApi } from "../../hooks/useMarketplace";
@@ -8,6 +8,10 @@ vi.mock("./InstallControls", () => ({
default: ({ headCommit }: { headCommit: string | null }) => <div>install controls at {headCommit}</div>,
}));
vi.mock("./AddMarketplaceModal", () => ({ default: () => <div>add modal</div> }));
const updateMarketplace = vi.fn();
vi.mock("../../lib/tauri-commands", () => ({
updateMarketplace: (m: unknown) => updateMarketplace(m),
}));
import BrowsePane from "./BrowsePane";
@@ -96,6 +100,43 @@ describe("BrowsePane", () => {
expect(screen.getByText("SKILL.md missing")).toBeInTheDocument();
});
describe("PR review #7: changing a marketplace's account", () => {
const withAccount = () =>
useAppState.setState({
toasts: [],
appSettings: {
marketplaces: [{ id: "m1", name: "Starter", url: "https://github.com/s/m.git", branch: null, account_id: null }],
marketplace_accounts: [{ id: "a1", label: "Work", host: "gitlab.com", method: "token", username: null }],
global_marketplace_installs: [],
} as unknown as AppSettings,
});
it("toasts a refused change instead of leaving it unhandled", async () => {
withAccount();
updateMarketplace.mockRejectedValueOnce("The account \"Work\" is for gitlab.com, but this marketplace is on github.com.");
const mp = api();
render(<BrowsePane mp={mp} />);
fireEvent.change(screen.getByLabelText("Account for Starter"), { target: { value: "a1" } });
await waitFor(() => expect(useAppState.getState().toasts).toHaveLength(1));
const toast = useAppState.getState().toasts[0];
expect(toast.kind).toBe("error");
expect(toast.detail).toContain("is for gitlab.com");
expect(mp.refresh).not.toHaveBeenCalled();
});
it("refreshes the marketplace after a successful change", async () => {
withAccount();
updateMarketplace.mockResolvedValueOnce({});
const mp = api();
render(<BrowsePane mp={mp} />);
fireEvent.change(screen.getByLabelText("Account for Starter"), { target: { value: "a1" } });
await waitFor(() => expect(mp.refresh).toHaveBeenCalledWith("m1"));
expect(updateMarketplace).toHaveBeenCalledWith(expect.objectContaining({ id: "m1", account_id: "a1" }));
expect(mp.reloadState).toHaveBeenCalled();
expect(useAppState.getState().toasts).toHaveLength(0);
});
});
it("refreshes one marketplace", () => {
const mp = api();
render(<BrowsePane mp={mp} />);