import {
  DEFAULT_EDITOR_HOST_KIND,
  normalizeEditorHostKind,
  resolveEditorHostKind,
} from "@/components/editor/editor-host-config";
import { describe, expect, it } from "vitest";

const phase6MindmapSuccessSelectors = [
  '[data-testid="mnote-mindmap-editor-root"]',
  '[data-testid="simple-mind-map-runtime"]',
  '[data-testid="mindmap-rust-shell"]',
];

describe("editor-host-config", () => {
  it("保持 island 为默认正式 host", () => {
    expect(DEFAULT_EDITOR_HOST_KIND).toBe("leptos_tiptap_island");
  });

  it("将 inline 和旧 runtime 兼容别名收敛到正式 island host", () => {
    expect(normalizeEditorHostKind("leptos_tiptap_inline")).toBe("leptos_tiptap_island");
    expect(normalizeEditorHostKind("leptos_tiptap_runtime")).toBe("leptos_tiptap_island");
    expect(normalizeEditorHostKind("leptos_tiptap")).toBe("leptos_tiptap_island");
  });

  it("旧 iframe debug host 配置应折返到正式 island host", () => {
    expect(normalizeEditorHostKind("leptos_tiptap_iframe_debug")).toBe("leptos_tiptap_island");
    expect(normalizeEditorHostKind("iframe_debug")).toBe("leptos_tiptap_island");
    expect(normalizeEditorHostKind("leptos_tiptap_debug")).toBe("leptos_tiptap_island");
    expect(
      resolveEditorHostKind({
        override: "leptos_tiptap_iframe_debug",
        runtimeDefault: "leptos_tiptap_island",
      }),
    ).toBe("leptos_tiptap_island");
  });

  it("不再允许通过 query 或 runtime 默认值切回 blocknote", () => {
    expect(
      resolveEditorHostKind({
        override: "blocknote",
        runtimeDefault: "leptos_tiptap_island",
      }),
    ).toBe("leptos_tiptap_island");
    expect(normalizeEditorHostKind("blocknote")).toBe("leptos_tiptap_island");
  });

  it("Phase 6 mindmap 成功条件不应依赖旧 React runtime 标记", () => {
    expect(phase6MindmapSuccessSelectors).not.toContain(
      ".mnote-mindmap-react-mount",
    );
    expect(phase6MindmapSuccessSelectors).not.toContain(
      "window.__mindmapInstance",
    );
  });
});
