mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-08 17:02:17 +00:00
Adds API 1.3 `ui.notify(level, title, body, actions) -> result<_, error>`: up to three buttons, each running one of the plugin's declared commands with an optional argument in the balloon's window and dismissing the balloon. An invalid action or an undeclared command fails the call and shows nothing. The plugin `Notification` event carries the actions; SDK `host::notify_with_actions` and `NotificationAction`. Closes #1955. Co-authored-by: arnaud-ritti <[email protected]>
41 lines
1.8 KiB
TypeScript
41 lines
1.8 KiB
TypeScript
import { expect, test } from "./fixtures";
|
|
|
|
test("plugin notification actions run their command and dismiss the balloon", async ({ workbench: page }) => {
|
|
await page.evaluate(async () => {
|
|
const backendPath = "/src/features/plugins/backend.ts";
|
|
const { createMemoryPluginsBackend, setPluginsBackend } = await import(/* @vite-ignore */ backendPath);
|
|
const state = window as unknown as { notificationCalls: unknown[] };
|
|
state.notificationCalls = [];
|
|
setPluginsBackend({
|
|
...createMemoryPluginsBackend(),
|
|
runCommand: async (...args: unknown[]) => {
|
|
state.notificationCalls.push(args);
|
|
return null;
|
|
},
|
|
});
|
|
const bridgePath = "/src/features/plugins/bridge.ts";
|
|
const { handlePluginEvent } = await import(/* @vite-ignore */ bridgePath);
|
|
handlePluginEvent({
|
|
type: "notification",
|
|
pluginId: "hello",
|
|
level: "info",
|
|
title: "Build complete",
|
|
body: "Choose the next step",
|
|
actions: [
|
|
{ label: "Review changes", command: "word-count", argument: "first\nsecond" },
|
|
{ label: "Open results", command: "insert-date", argument: null },
|
|
{ label: "Undo change", command: "insert-date", argument: "undo" },
|
|
],
|
|
});
|
|
});
|
|
const review = page.getByRole("button", { name: "Review changes", exact: true });
|
|
await expect(review).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Open results", exact: true })).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "Undo change", exact: true })).toBeVisible();
|
|
await review.click();
|
|
await expect(review).toBeHidden();
|
|
await expect
|
|
.poll(() => page.evaluate(() => (window as unknown as { notificationCalls: unknown[] }).notificationCalls))
|
|
.toEqual([["hello", "word-count", "first\nsecond", null, []]]);
|
|
});
|