import { describe, expect, it } from "vitest";
import {
  resolveMindmapShortcutAction,
  shouldInterceptMindmapShortcut,
} from "./mindmap-shortcuts";

describe("mindmap shortcuts", () => {
  it("把基础快捷键解析为导图动作", () => {
    expect(resolveMindmapShortcutAction({ key: "Enter" })).toBe("insertSiblingAfter");
    expect(resolveMindmapShortcutAction({ key: "Tab" })).toBe("insertChild");
    expect(resolveMindmapShortcutAction({ key: "Delete" })).toBe("deleteNode");
    expect(resolveMindmapShortcutAction({ key: "F2" })).toBe("editNode");
    expect(resolveMindmapShortcutAction({ key: "Enter", ctrlKey: true })).toBeNull();
  });

  it("已进入 mindmap 时即使暂时没有 active node，也要拦截危险按键，避免 ProseMirror 误删整个 block", () => {
    expect(
      shouldInterceptMindmapShortcut({
        debugChromeEnabled: false,
        bridgeReady: true,
        readonly: false,
        isComposing: false,
        isEditableTarget: false,
        targetInsideRoot: false,
        keyboardShortcutArmed: true,
      }),
    ).toBe(true);
    expect(
      shouldInterceptMindmapShortcut({
        debugChromeEnabled: false,
        bridgeReady: true,
        readonly: false,
        isComposing: false,
        isEditableTarget: false,
        targetInsideRoot: false,
        keyboardShortcutArmed: false,
      }),
    ).toBe(false);
  });
});
