дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 01:31:41 +02:00
Following #3452, the remaining line-marker kinds kept a gutter column each (a Spring controller showed its mapping icons in a second column beside the run icon). Scripts and Docker/Compose targets join the run icons in the shared icon area (hidden with them), Spring mappings and endpoints follow, then plugin line markers, gutter actions and indexed mappings (now 14px like the others). Presses go to the pressed icon's source.
123 рядки
4.5 KiB
TypeScript
123 рядки
4.5 KiB
TypeScript
import { afterEach, expect, it, vi } from "vitest";
|
|
import { EditorState } from "@codemirror/state";
|
|
import { EditorView } from "@codemirror/view";
|
|
import type { EditorDocContext } from "@/editor/api";
|
|
import type { PluginEvent } from "@/bindings";
|
|
import { iconAreaExtension } from "@/editor/core/cm/iconArea";
|
|
import { pluginLineMarkerGutter } from "./lineMarkerGutter";
|
|
import { pluginIconName } from "./pluginIcon";
|
|
import { projectMarkerIcon } from "./markerIcons";
|
|
const mock = vi.hoisted(() => ({
|
|
markers: vi.fn(),
|
|
assets: vi.fn(),
|
|
event: undefined as ((event: PluginEvent) => void) | undefined,
|
|
off: vi.fn(),
|
|
}));
|
|
vi.mock(import("@/platform/ipc"), async (original) => {
|
|
const actual = await original();
|
|
return { ...actual, commands: { ...actual.commands, pluginLineMarkers: mock.markers } };
|
|
});
|
|
vi.mock("./backend", () => ({
|
|
pluginsBackend: () => ({
|
|
assets: mock.assets,
|
|
onEvent: (fn: (event: PluginEvent) => void) => {
|
|
mock.event = fn;
|
|
return mock.off;
|
|
},
|
|
}),
|
|
}));
|
|
vi.mock("./navigationButton", () => ({ navigationButton: () => document.createElement("button") }));
|
|
let view: EditorView | undefined;
|
|
afterEach(() => {
|
|
view?.destroy();
|
|
view = undefined;
|
|
vi.useRealTimers();
|
|
vi.clearAllMocks();
|
|
});
|
|
it("withdraws old interactive markers on reload and does not refresh on idle status changes", async () => {
|
|
vi.useFakeTimers();
|
|
mock.markers.mockResolvedValue({
|
|
status: "ok",
|
|
data: [{ pluginId: "test", line: 0, icon: "navigate", tooltip: "old", target: null }],
|
|
});
|
|
view = new EditorView({
|
|
parent: document.body,
|
|
state: EditorState.create({
|
|
doc: "select",
|
|
extensions: [iconAreaExtension, pluginLineMarkerGutter({ doc: 1 } as EditorDocContext)],
|
|
}),
|
|
});
|
|
await vi.advanceTimersByTimeAsync(450);
|
|
expect(view.dom.querySelector(".cm-openidea-iconArea .cm-plugin-mapping-button")).not.toBeNull();
|
|
const calls = mock.markers.mock.calls.length;
|
|
mock.event!({ type: "commandsChanged" });
|
|
await vi.advanceTimersByTimeAsync(450);
|
|
expect(mock.markers).toHaveBeenCalledTimes(calls);
|
|
mock.markers.mockResolvedValue({ status: "ok", data: [] });
|
|
mock.event!({ type: "documentIndexesChanged" });
|
|
expect(view.dom.querySelector(".cm-openidea-iconArea .cm-plugin-mapping-button")).toBeNull();
|
|
await vi.advanceTimersByTimeAsync(450);
|
|
expect(view.dom.querySelector(".cm-openidea-iconArea .cm-plugin-mapping-button")).toBeNull();
|
|
view.destroy();
|
|
view = undefined;
|
|
expect(mock.off).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("renders ordinary and custom registered icons alongside legacy marker aliases", async () => {
|
|
vi.useFakeTimers();
|
|
const icon = pluginIconName("markers", {
|
|
light: '<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6"/></svg>',
|
|
dark: null,
|
|
});
|
|
mock.markers.mockResolvedValue({
|
|
status: "ok",
|
|
data: ["run", "database", icon].map((icon, line) => ({
|
|
pluginId: "markers",
|
|
line,
|
|
icon,
|
|
tooltip: `marker ${line}`,
|
|
target: null,
|
|
})),
|
|
});
|
|
view = new EditorView({
|
|
parent: document.body,
|
|
state: EditorState.create({
|
|
doc: "legacy\nordinary\ncustom",
|
|
extensions: [iconAreaExtension, pluginLineMarkerGutter({ doc: 1 } as EditorDocContext)],
|
|
}),
|
|
});
|
|
await vi.advanceTimersByTimeAsync(450);
|
|
const markers = view.dom.querySelectorAll(".cm-plugin-mapping-button");
|
|
expect(markers).toHaveLength(3);
|
|
expect([...markers].map((el) => el.getAttribute("aria-label"))).toEqual(["marker 0", "marker 1", "marker 2"]);
|
|
expect(markers[0]!.innerHTML).not.toBe(markers[1]!.innerHTML);
|
|
expect(markers[2]!.querySelector("circle")).not.toBeNull();
|
|
});
|
|
|
|
it("refreshes a fallback when the package icon declaration arrives after its markers", async () => {
|
|
vi.useFakeTimers();
|
|
mock.markers.mockResolvedValue({
|
|
status: "ok",
|
|
data: [{ pluginId: "late", line: 0, icon: "icons/late.svg", tooltip: "late icon", target: null }],
|
|
});
|
|
view = new EditorView({
|
|
parent: document.body,
|
|
state: EditorState.create({
|
|
doc: "late",
|
|
extensions: [iconAreaExtension, pluginLineMarkerGutter({ doc: 1 } as EditorDocContext)],
|
|
}),
|
|
});
|
|
await vi.advanceTimersByTimeAsync(450);
|
|
expect(view.dom.querySelector(".cm-plugin-mapping-button circle")).toBeNull();
|
|
mock.assets.mockResolvedValue([
|
|
["markerIcon/late/light", '<svg viewBox="0 0 16 16"><circle cx="8" cy="8" r="6"/></svg>'],
|
|
]);
|
|
const remove = projectMarkerIcon("late", { id: "late", icon: "icons/late.svg" });
|
|
try {
|
|
await vi.advanceTimersByTimeAsync(450);
|
|
expect(view.dom.querySelector(".cm-plugin-mapping-button circle")).not.toBeNull();
|
|
} finally {
|
|
remove();
|
|
}
|
|
});
|