Files
openidea/src/features/services/dockerGutter.test.ts
T
l0ng-ai d171a946fe fix(editor): Spring, endpoint, npm, Docker and plugin gutter icons join the shared icon area (#3472)
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.
2026-11-15 10:31:42 +08:00

48 lines
2.0 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import { EditorView } from "@codemirror/view";
import { iconAreaExtension } from "@/editor/core/cm/iconArea";
import * as ui from "@/ui";
import { dockerGutter } from "./dockerGutter";
import { useComposeFiles } from "./compose";
afterEach(() => {
vi.restoreAllMocks();
useComposeFiles.setState({ overrides: {}, contentDetected: {} });
});
it("refreshes markers and menus after edits, removes non-service keys and respects exclusions", async () => {
const menu = vi.spyOn(ui, "showContextMenu").mockImplementation(() => {});
const view = new EditorView({
doc: "services:\n web:\n image: nginx\n x-defaults:\n image: nginx\nvolumes:\n data:\n",
parent: document.body,
extensions: [
iconAreaExtension,
dockerGutter({ doc: 1, path: "/p/stack.yml", language: "yaml", uiMode: null, readOnly: false }),
],
});
const markers = () => [...view.dom.querySelectorAll<HTMLButtonElement>(".cm-gutterElement button")];
try {
await vi.waitFor(() => expect(markers().map((m) => m.title)).toContain("Compose Up 'web'"));
expect(markers().some((m) => m.title.includes("x-defaults") || m.title.includes("data"))).toBe(false);
view.dispatch({
changes: { from: 0, to: view.state.doc.length, insert: "# moved\nservices:\n db:\n image: postgres\n" },
});
await vi.waitFor(() => expect(markers().some((m) => m.title === "Compose Up 'db'")).toBe(true));
expect(markers().some((m) => m.title === "Compose Up 'web'")).toBe(false);
markers()
.find((m) => m.title === "Compose Up 'db'")!
.click();
expect(menu).toHaveBeenCalledWith(
expect.anything(),
expect.arrayContaining([
expect.objectContaining({ label: "Compose Up 'db'" }),
expect.objectContaining({ label: "Modify Run Configuration…" }),
]),
);
useComposeFiles.setState({ overrides: { "/p/stack.yml": "excluded" } });
await vi.waitFor(() => expect(markers()).toHaveLength(0));
} finally {
view.destroy();
}
});