import { describe, expect, it } from "vitest";
import {
  buildSidebarDocumentOpenTarget,
  buildSidebarMindmapOpenTarget,
} from "./sidebar-navigation";

describe("sidebar-navigation", () => {
  it("页面树普通打开应留在当前窗口", () => {
    expect(buildSidebarDocumentOpenTarget("doc_1", "main", "http://127.0.0.1:3000")).toEqual({
      kind: "same-window",
      path: "/documents/doc_1",
    });
  });

  it("显式侧栏预览打开才应使用新窗口 URL", () => {
    expect(buildSidebarDocumentOpenTarget("doc_1", "sidebar", "http://127.0.0.1:3000")).toEqual({
      kind: "new-window",
      url: "http://127.0.0.1:3000/documents/doc_1?preview=sidebar",
    });
  });

  it("文件树里的 mindmap 主打开应进入 mindmap 对象编辑页", () => {
    expect(buildSidebarMindmapOpenTarget("doc_1", "mind_1", "main", "http://127.0.0.1:3000")).toEqual({
      kind: "same-window",
      path: "/mindmap/doc_1/mind_1",
    });
  });

  it("显式新标签打开 mindmap 也应使用同一对象编辑页", () => {
    expect(buildSidebarMindmapOpenTarget("doc_1", "mind_1", "sidebar", "http://127.0.0.1:3000")).toEqual({
      kind: "new-window",
      url: "http://127.0.0.1:3000/mindmap/doc_1/mind_1",
    });
  });
});
