import { describe, it, expect } from "vitest";
import { handleDiscover } from "../../src/tools/discover.js";
import { ComponentRegistry } from "../../src/registry.js";

describe("pettyui.discover", () => {
  const registry = new ComponentRegistry();

  it("finds components matching intent — modal overlay → Dialog first", () => {
    const results = handleDiscover(registry, { intent: "modal overlay" });
    expect(results.length).toBeGreaterThan(0);
    expect(results[0].name).toBe("Dialog");
  });

  it("returns multiple ranked matches — select option includes Select", () => {
    const results = handleDiscover(registry, { intent: "select option" });
    const names = results.map((r) => r.name);
    expect(names).toContain("Select");
  });

  it("returns empty for no matches — xyznonexistent → []", () => {
    const results = handleDiscover(registry, { intent: "xyznonexistent" });
    expect(results).toEqual([]);
  });

  it("limits results with maxResults: 3", () => {
    const results = handleDiscover(registry, { intent: "a", maxResults: 3 });
    expect(results.length).toBeLessThanOrEqual(3);
  });
});
