55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
applyFieldMapping,
|
|
FieldTypeSchema,
|
|
FormDefinitionSchema,
|
|
FormFieldSchema,
|
|
FormSubmissionPayloadSchema,
|
|
FormThemeSchema,
|
|
HONEYPOT_FIELD_KEY,
|
|
isHoneypotTriggered,
|
|
matchAllowedOrigin,
|
|
normalizeOrigin,
|
|
resolveSubmissionTarget,
|
|
} from "./index.js";
|
|
|
|
/**
|
|
* Public-API barrel smoke test. Verifies that every export is wired to the
|
|
* correct implementation — a forgotten or renamed re-export in index.ts
|
|
* would surface here rather than at a downstream import site.
|
|
*/
|
|
describe("@hivegrid/form-widget barrel", () => {
|
|
it("re-exports the honeypot field key constant", () => {
|
|
expect(HONEYPOT_FIELD_KEY).toBe("hp_extra_data");
|
|
});
|
|
|
|
it("re-exports the field-type enum schema", () => {
|
|
expect(FieldTypeSchema.parse("email")).toBe("email");
|
|
expect(FieldTypeSchema.safeParse("file").success).toBe(true);
|
|
expect(FieldTypeSchema.safeParse("radio").success).toBe(false);
|
|
});
|
|
|
|
it("re-exports the origin helpers", () => {
|
|
expect(normalizeOrigin("Example.com")).toBe("https://example.com");
|
|
expect(matchAllowedOrigin("https://example.com", ["example.com"])).toBe(true);
|
|
});
|
|
|
|
it("re-exports the honeypot helper", () => {
|
|
expect(isHoneypotTriggered({ [HONEYPOT_FIELD_KEY]: "spam" })).toBe(true);
|
|
});
|
|
|
|
it("re-exports the routing helpers", () => {
|
|
expect(resolveSubmissionTarget({}).type).toBe("generic");
|
|
expect(applyFieldMapping({ payload: { a: 1 } })).toEqual({ a: 1 });
|
|
});
|
|
|
|
it("re-exports the Zod schemas", () => {
|
|
expect(FormFieldSchema.safeParse({ key: "name", type: "text", label: "Name" }).success).toBe(true);
|
|
expect(FormThemeSchema.safeParse({ primaryColor: "#fff" }).success).toBe(true);
|
|
expect(FormDefinitionSchema.safeParse({ title: "C", fields: [{ key: "n", type: "text", label: "N" }] }).success).toBe(
|
|
true,
|
|
);
|
|
expect(FormSubmissionPayloadSchema.safeParse({ values: {} }).success).toBe(true);
|
|
});
|
|
});
|