import { expect, test } from "./fixtures"; test("plugin view groups keep their own tabs and disappear when no view applies", async ({ workbench: page }) => { await page.evaluate(async () => { const backendModule = "/src/features/plugins/backend.ts"; const storeModule = "/src/features/plugins/store.ts"; const { createMemoryPluginsBackend, setPluginsBackend } = await import(/* @vite-ignore */ backendModule); const { usePlugins } = await import(/* @vite-ignore */ storeModule); const base = createMemoryPluginsBackend(); const template = (await base.list()).plugins[0]; const plugins = ["test.views", "test.other"].map((id) => ({ ...template, id, status: "inactive" })); setPluginsBackend({ ...base, renderView: async (_pluginId: string, id: string) => ({ toolbar: [], body: { kind: "message", value: `${id} content` }, status: null, }), }); const view = (pluginId: string, id: string, title: string, when?: string, group?: string) => ({ pluginId, point: "views", key: id, decl: { id, title, location: "right", when, group }, }); usePlugins.setState({ plugins, ui: [ view("test.views", "routes", "Framework", "plugin.test.views.ready", "framework"), view("test.views", "beans", "Beans", "plugin.test.views.beans", "framework"), view("test.views", "legacy", "Legacy"), view("test.other", "routes", "Other framework", undefined, "framework"), ], }); }); const group = page.locator('[data-stripe-button="plugin.test.views.group:framework"]'); const other = page.locator('[data-stripe-button="plugin.test.other.group:framework"]'); await expect(group).toHaveCount(0); await expect(other).toBeVisible(); await expect(page.locator('[data-stripe-button="plugin.test.views.legacy"]')).toBeVisible(); const context = async (ready: boolean, beans: boolean) => page.evaluate( async ({ ready, beans }) => { const module = "/src/platform/context.ts"; const { setContext } = await import(/* @vite-ignore */ module); setContext("plugin.test.views.ready", ready); setContext("plugin.test.views.beans", beans); }, { ready, beans }, ); await context(true, true); await expect(group).toBeVisible(); await group.click(); const pane = page.locator('[data-toolwindow="plugin.test.views.group:framework"]'); await expect(pane.getByRole("tab")).toHaveText(["Framework", "Beans"]); await expect(pane.getByText("routes content")).toBeVisible(); await pane.getByRole("tab", { name: "Beans", exact: true }).click(); await expect(pane.getByText("beans content")).toBeVisible(); await context(true, false); await expect(pane.getByRole("tab", { name: "Beans", exact: true })).toHaveCount(0); await expect(pane.getByText("routes content")).toBeVisible(); await context(false, false); await expect(group).toHaveCount(0); await expect(pane).toHaveCount(0); await expect(other).toBeVisible(); }); test("plugin views display stripe and grouped tab badges and respect showToolWindowBadges", async ({ workbench: page, }) => { await page.evaluate(async () => { const backendModule = "/src/features/plugins/backend.ts"; const storeModule = "/src/features/plugins/store.ts"; const { createMemoryPluginsBackend, setPluginsBackend } = await import(/* @vite-ignore */ backendModule); const { usePlugins } = await import(/* @vite-ignore */ storeModule); const base = createMemoryPluginsBackend(); const template = (await base.list()).plugins[0]; setPluginsBackend({ ...base, renderView: async (_pluginId: string, id: string) => ({ toolbar: [], body: { kind: "message", value: `${id} findings` }, status: null, }), }); usePlugins.setState({ plugins: [{ ...template, id: "test.badge", status: "inactive" }], ui: [ { pluginId: "test.badge", point: "views", key: "findings", decl: { id: "findings", title: "Findings", icon: "warning", location: "right" }, }, { pluginId: "test.badge", point: "views", key: "errors", decl: { id: "errors", title: "Errors", icon: "error", location: "right", group: "checks" }, }, { pluginId: "test.badge", point: "views", key: "warnings", decl: { id: "warnings", title: "Warnings", icon: "warning", location: "right", group: "checks" }, }, ], }); }); const findingsBtn = page.locator('[data-stripe-button="plugin.test.badge.findings"]'); const checksBtn = page.locator('[data-stripe-button="plugin.test.badge.group:checks"]'); await expect(findingsBtn).toBeVisible(); await expect(checksBtn).toBeVisible(); await checksBtn.click(); const pane = page.locator('[data-toolwindow="plugin.test.badge.group:checks"]'); await expect(pane.getByRole("tab")).toHaveText(["Errors", "Warnings"]); await page.evaluate(async () => { const runtimeModule = "/src/features/plugins/runtimeUi.tsx"; const { handleRuntimeEvent } = await import(/* @vite-ignore */ runtimeModule); handleRuntimeEvent({ type: "viewBadgeChanged", pluginId: "test.badge", view: "findings", badge: "12" }); handleRuntimeEvent({ type: "viewBadgeChanged", pluginId: "test.badge", view: "errors", badge: "3" }); handleRuntimeEvent({ type: "viewBadgeChanged", pluginId: "test.badge", view: "warnings", badge: "5" }); }); await expect(findingsBtn).toContainText("12"); await expect(checksBtn).toContainText("8"); await expect(pane.getByRole("tab", { name: /Errors/ })).toContainText("3"); await expect(pane.getByRole("tab", { name: /Warnings/ })).toContainText("5"); await page.evaluate(async () => { const projectModule = "/src/platform/project.ts"; const { useProject } = await import(/* @vite-ignore */ projectModule); useProject.setState({ settings: { appearance: { showToolWindowBadges: false } } }); }); await expect(findingsBtn).not.toContainText("12"); await expect(checksBtn).not.toContainText("8"); await page.evaluate(async () => { const projectModule = "/src/platform/project.ts"; const runtimeModule = "/src/features/plugins/runtimeUi.tsx"; const { useProject } = await import(/* @vite-ignore */ projectModule); const { handleRuntimeEvent } = await import(/* @vite-ignore */ runtimeModule); useProject.setState({ settings: { appearance: { showToolWindowBadges: true } } }); handleRuntimeEvent({ type: "viewBadgeChanged", pluginId: "test.badge", view: "findings", badge: null }); }); await expect(findingsBtn).not.toContainText("12"); await expect(checksBtn).toContainText("8"); });