Файли
openidea/src/workbench/ContributedToolbar.test.tsx
T
l0ng-ai 047cac209b feat(plugins): plugin API 1.4 (#2207)
Plugin API 1.4: grants for unencrypted HTTP, local sockets, IDE commands and owned database sources; window status items, output channels, content tabs, editor selections, decorations, search, Problems and VCS reads; runs, keyed terminals with exit events, plugin run targets, dynamic run configurations and test parsers; language features, injections, snippets and menu locations; plugin MCP tools on the built-in server; four official API examples. Released 1.3 plugins keep working.
2026-11-09 08:40:40 +08:00

34 рядки
1.2 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import { ContributedToolbar } from "./ContributedToolbar";
import { registerMenuSlotItem } from "./contributions";
import { registerAction } from "@/platform/actions";
import { setContext } from "@/platform/context";
const offs: (() => void)[] = [];
afterEach(() =>
offs
.splice(0)
.reverse()
.forEach((f) => f()),
);
it("renders toolbar slots with command icons and honors when clauses", () => {
const run = vi.fn();
offs.push(registerAction({ id: "test.pluginMenu", title: "Plugin action", icon: "run", run }));
offs.push(
registerMenuSlotItem("editor.title", {
action: "test.pluginMenu",
label: "Plugin action",
icon: "run",
when: "editorLang == sql",
}),
);
setContext("editorLang", "sql");
const r = render(<ContributedToolbar slot="editor.title" />);
fireEvent.click(screen.getByRole("button", { name: /Plugin action/ }));
expect(run).toHaveBeenCalledOnce();
r.unmount();
setContext("editorLang", "text");
render(<ContributedToolbar slot="editor.title" />);
expect(screen.queryByRole("button")).toBeNull();
});