Files
WRNexusJS/packages/captcha/test/component.test.ts
T
Clintchiz 8d044565e3
Quality / quality (ubuntu-latest) (push) Failing after 21s
Quality / quality (windows-latest) (push) Canceled after 0s
feat: publish changed packages independently
2026-08-11 15:32:36 +05:30

73 lines
2.5 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",
"resetOnError",
]) {
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-reset-on-error='{resetOnError}'");
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-footer]");
expect(source).toContain("display: contents");
expect(source).toContain("order: -1");
expect(source).toContain("data-[captcha-size=big]");
expect(source).toContain("{...attrs}");
expect(source).toContain("--wire-");
expect(source).not.toMatch(/=\{/);
expect(source).toContain('data-wrnexus-runtime="captcha"');
expect(source).not.toContain("<script");
expect(source).not.toContain("captcha.js");
expect(source).not.toContain("lifecycle {");
});