diff --git a/apps/app/src/views/ToolsView.plugin-detail.test.tsx b/apps/app/src/views/ToolsView.plugin-detail.test.tsx index df4c7a77f..a10fb9bd7 100644 --- a/apps/app/src/views/ToolsView.plugin-detail.test.tsx +++ b/apps/app/src/views/ToolsView.plugin-detail.test.tsx @@ -759,6 +759,105 @@ describe("PluginDetail official catalog lifecycle", () => { }); }); +describe("catalog bulk-close persistence regression", () => { + it.each([ + { action: "Close other tabs", target: "tasks", active: "tasks" }, + { action: "Close tabs to the right", target: "github", active: "github" }, + { action: "Close other tabs", target: "github", active: "tasks" }, + { action: "Close tabs to the right", target: "github", active: "tasks" }, + ])( + "$action on $target with $active active", + async ({ action, target, active }) => { + const entries = [ + GITHUB_CATALOG_ENTRY, + { + ...GITHUB_CATALOG_ENTRY, + entryId: "automations", + pluginId: "automations", + source: "builtin:automations", + displayName: "Automations", + }, + { + ...GITHUB_CATALOG_ENTRY, + entryId: "tasks", + pluginId: "tasks", + source: "builtin:tasks", + displayName: "Tasks", + }, + ]; + window.localStorage.setItem( + "bb.plugins.workspace.tabs", + JSON.stringify({ + tabs: ["github", "automations", "tasks"], + activePluginId: active, + }), + ); + vi.stubGlobal( + "fetch", + vi.fn(async (input: RequestInfo | URL) => { + const url = String(input); + if (url === "/api/v1/plugins") { + return new Response( + JSON.stringify({ enabled: true, plugins: [] }), + { + headers: { "content-type": "application/json" }, + }, + ); + } + if (url.startsWith("/api/v1/plugin-catalog/search")) { + return new Response( + JSON.stringify({ results: entries, collections: [] }), + { + headers: { "content-type": "application/json" }, + }, + ); + } + return new Response(JSON.stringify({ error: "not found" }), { + status: 404, + headers: { "content-type": "application/json" }, + }); + }), + ); + renderWithQueryClient( + + + + + , + ); + await screen.findByRole("button", { name: "Close Tasks" }); + const targetName = target === "github" ? "GitHub" : "Tasks"; + fireEvent.contextMenu( + screen.getByRole("button", { name: targetName, exact: true }), + ); + fireEvent.click( + await screen.findByRole("menuitem", { name: action, exact: true }), + ); + console.info( + JSON.stringify({ + action, + target, + active, + persisted: JSON.parse( + window.localStorage.getItem("bb.plugins.workspace.tabs") ?? "{}", + ), + location: screen.getByTestId("location").textContent, + }), + ); + await waitFor(() => { + expect( + JSON.parse( + window.localStorage.getItem("bb.plugins.workspace.tabs") ?? "{}", + ), + ).toEqual({ tabs: [target], activePluginId: target }); + expect(screen.getByTestId("location").textContent).toBe( + `/plugins/${target}`, + ); + }); + }, + ); +}); + describe("BB Official plugin detail routing", () => { it.each([false, true])( "keeps official attribution and tabs through collection navigation (compact: %s)",