import { describe, it, expect } from "vitest";
import { routes, navGroups, defaultPath } from "./routes";

// routes 是控制台导航的单一事实源 —— 派生分组必须保序、不丢项、不串组。
describe("navGroups", () => {
  it("按注册顺序归并分组，每条路由都落到对应组", () => {
    const groups = navGroups();
    const flat = groups.flatMap((g) => g.items);
    // 不丢项、不重复
    expect(flat).toHaveLength(routes.length);
    expect(new Set(flat.map((r) => r.path)).size).toBe(routes.length);
  });

  it("分组首次出现的顺序即组顺序（保持注册顺序）", () => {
    const seen: string[] = [];
    for (const r of routes) if (!seen.includes(r.group)) seen.push(r.group);
    expect(navGroups().map((g) => g.group)).toEqual(seen);
  });

  it("同组路由保持注册时的相对顺序", () => {
    for (const g of navGroups()) {
      const expected = routes.filter((r) => r.group === g.group).map((r) => r.path);
      expect(g.items.map((r) => r.path)).toEqual(expected);
    }
  });

  it("defaultPath 指向一个真实存在的路由", () => {
    expect(routes.some((r) => r.path === defaultPath)).toBe(true);
  });
});
