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

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

  it("returns styled source for Dialog", () => {
    const result = handleAdd(registry, { component: "Dialog" });
    expect(result).not.toBeNull();
    expect(result?.files[0].content).toContain("Dialog");
    expect(result?.dependencies).toContain("pettyui/dialog");
  });

  it("returns null without styled version", () => {
    const result = handleAdd(registry, { component: "Checkbox" });
    expect(result).toBeNull();
  });

  it("returns null for unknown component", () => {
    const result = handleAdd(registry, { component: "FakeComponent" });
    expect(result).toBeNull();
  });

  it("uses custom target dir", () => {
    const result = handleAdd(registry, { component: "Dialog", targetDir: "src/ui" });
    expect(result).not.toBeNull();
    expect(result?.files[0].path).toContain("src/ui");
  });
});
