59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { ComponentRegistry } from "../src/registry.js";
|
|
|
|
describe("ComponentRegistry", () => {
|
|
const registry = new ComponentRegistry();
|
|
|
|
it("loads all components", () => {
|
|
const all = registry.listComponents();
|
|
expect(all.length).toBeGreaterThan(30);
|
|
});
|
|
|
|
it("finds by exact name", () => {
|
|
const comp = registry.getComponent("Dialog");
|
|
expect(comp).toBeDefined();
|
|
expect(comp?.meta.name).toBe("Dialog");
|
|
});
|
|
|
|
it("finds case-insensitive", () => {
|
|
const lower = registry.getComponent("dialog");
|
|
const upper = registry.getComponent("DIALOG");
|
|
expect(lower).toBeDefined();
|
|
expect(upper).toBeDefined();
|
|
expect(lower?.meta.name).toBe("Dialog");
|
|
});
|
|
|
|
it("returns undefined for unknown component", () => {
|
|
const comp = registry.getComponent("NonExistentWidget");
|
|
expect(comp).toBeUndefined();
|
|
});
|
|
|
|
it("searches by description keyword", () => {
|
|
const results = registry.search("modal overlay");
|
|
expect(results.length).toBeGreaterThan(0);
|
|
const names = results.map((r) => r.meta.name);
|
|
expect(names).toContain("Dialog");
|
|
});
|
|
|
|
it("searches by intent — searchable dropdown finds Combobox", () => {
|
|
const results = registry.search("searchable dropdown");
|
|
expect(results.length).toBeGreaterThan(0);
|
|
const names = results.map((r) => r.meta.name);
|
|
expect(names).toContain("Combobox");
|
|
});
|
|
|
|
it("returns json schemas for dialog", () => {
|
|
const comp = registry.getComponent("dialog");
|
|
expect(comp).toBeDefined();
|
|
expect(comp?.jsonSchemas).toBeDefined();
|
|
expect(Object.keys(comp?.jsonSchemas ?? {}).length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("reports hasStyledVersion correctly for dialog", () => {
|
|
const comp = registry.getComponent("dialog");
|
|
expect(comp).toBeDefined();
|
|
expect(typeof comp?.hasStyledVersion).toBe("boolean");
|
|
expect(comp?.hasStyledVersion).toBe(true);
|
|
});
|
|
});
|