Files
2026-07-25 13:38:18 +05:30

39 lines
2.1 KiB
TypeScript

import { expect, test } from "bun:test";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { parse } from "@wrnexus/syntax";
const componentPath = join(import.meta.dir, "../components/Captcha.wrn");
test("Captcha.wrn parses and exposes the full public contract", async () => {
const source = await readFile(componentPath, "utf8");
const ast = parse(source);
expect(ast.kind).toBe("component");
expect(ast.name).toBe("Captcha");
for (const prop of ["provider", "siteKey", "type", "action", "presentation", "difficulty", "disturbance", "imageStyle", "allowedStyles", "excludedStyles", "randomizeStyle", "size", "color", "class", "showListen"]) {
expect(source).toContain(`${prop} =`);
}
for (const event of ["ready", "challenge", "input", "verify", "success", "failure", "expired", "refresh", "audioStart", "audioEnd", "error"]) {
expect(source).toContain(`@event ${event} = function`);
}
expect(source).toContain("data-captcha-disturbance='{disturbance}'");
expect(source).toContain("data-captcha-image-style='{imageStyle}'");
expect(source).toContain("data-captcha-allowed-styles='{allowedStyles}'");
expect(source).toContain("data-captcha-excluded-styles='{excludedStyles}'");
expect(source).toContain("data-captcha-randomize-style='{randomizeStyle}'");
expect(source).toContain("data-captcha-show-listen='{showListen}'");
expect(source).toContain("data-captcha-not-robot-button");
expect(source).toContain("data-[captcha-size=compact]");
expect(source).toContain("data-[captcha-size=compact]:max-w-xs");
expect(source).toContain("group-data-[captcha-size=compact]/captcha:max-h-24");
expect(source).toContain("group-data-[captcha-size=compact]/captcha:h-8");
expect(source).toContain("group-data-[captcha-size=compact]/captcha:hidden");
expect(source).toContain("data-[captcha-size=big]");
expect(source).toContain("{...attrs}");
expect(source).toContain("--wire-");
expect(source).not.toMatch(/=\{/);
expect(source).toContain('src="/assets/wrnexus/captcha.js"');
expect(source).not.toContain('src="/__wrnexus/captcha.js"');
expect(source).not.toContain("lifecycle {");
});