Files
dbx/apps/desktop/src/lib/__tests__/codemirrorStatementGutter.spec.ts
T

53 lines
2.0 KiB
TypeScript
Vendored

// @vitest-environment happy-dom
import { describe, expect, it } from "vitest";
import { createStatementGutterMarkerDom, shouldShowStatementGutter } from "@/lib/editor/codemirrorStatementGutter";
describe("CodeMirror statement gutter marker", () => {
it("keeps gutter visibility controlled by the run-button preference", () => {
expect(shouldShowStatementGutter(false)).toBe(false);
expect(shouldShowStatementGutter(true)).toBe(true);
});
it("keeps execution status inside the run button column", () => {
const marker = createStatementGutterMarkerDom({
canExecute: true,
executeLabel: "Execute SQL",
status: "success",
statusLabel: "1 statement succeeded",
});
expect(marker.tagName).toBe("BUTTON");
expect(marker.classList.contains("cm-run-statement-marker")).toBe(true);
expect(marker.querySelectorAll(".cm-statement-execution-badge--success")).toHaveLength(1);
expect(marker.getAttribute("aria-label")).toBe("Execute SQL. 1 statement succeeded");
});
it("renders a standalone status marker when run buttons are disabled", () => {
const marker = createStatementGutterMarkerDom({
canExecute: false,
executeLabel: "Execute SQL",
status: "error",
statusLabel: "1 statement failed",
});
expect(marker.tagName).toBe("SPAN");
expect(marker.classList.contains("cm-statement-execution-marker--error")).toBe(true);
expect(marker.querySelectorAll(".cm-statement-execution-badge")).toHaveLength(0);
expect(marker.getAttribute("aria-label")).toBe("1 statement failed");
});
it("renders an animated running marker", () => {
const marker = createStatementGutterMarkerDom({
canExecute: false,
executeLabel: "Execute SQL",
status: "running",
statusLabel: "1 statement running",
});
expect(marker.classList.contains("cm-statement-execution-marker--running")).toBe(true);
expect(marker.querySelector(".cm-statement-execution-spinner")).not.toBeNull();
expect(marker.getAttribute("aria-label")).toBe("1 statement running");
});
});