import { describe, expect, test } from "vitest";
import { searchMenus } from "./SearchDialog.jsx";

describe("searchMenus", () => {
  const menus = [
    {
      code: "overview",
      label: "系统概览",
      path: "/overview"
    },
    {
      code: "app-users",
      label: "用户管理",
      children: [{ code: "app-users-list", label: "用户列表", path: "/app/users" }]
    },
    {
      code: "system",
      label: "后台设置",
      children: [
        { code: "system-users", label: "后台用户", path: "/system/users" },
        { code: "system-roles", label: "角色配置", path: "/system/roles" }
      ]
    }
  ];

  test("matches visible menu labels and returns navigable targets", () => {
    expect(searchMenus(menus, "后台")).toEqual([
      expect.objectContaining({ target: "/system/users", title: "后台设置", type: "菜单" }),
      expect.objectContaining({ target: "/system/users", title: "后台用户", type: "菜单" })
    ]);
  });

  test("matches menu code and keeps breadcrumb for context", () => {
    expect(searchMenus(menus, "app-users-list")).toEqual([
      expect.objectContaining({ subtitle: "用户管理 / 用户列表", target: "/app/users", title: "用户列表" })
    ]);
  });

  test("returns nothing for blank keyword", () => {
    expect(searchMenus(menus, "   ")).toEqual([]);
  });
});
