import { expect, test } from "bun:test";
import { readdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { parse } from "@wrnexus/syntax";

const componentsDir = join(import.meta.dir, "..", "components");

test("all auth package components parse", () => {
  for (const file of readdirSync(componentsDir).filter((name) => name.endsWith(".wrn"))) {
    expect(() => parse(readFileSync(join(componentsDir, file), "utf8"))).not.toThrow();
  }
});

test("auth form blocks use WRNexus UI controls", () => {
  const formFiles = [
    "SignIn.wrn",
    "SignUp.wrn",
    "ForgotPassword.wrn",
    "ResetPassword.wrn",
    "OtpSignIn.wrn",
    "TwoFactorChallenge.wrn",
    "VerifyEmail.wrn",
    "VerifyPhone.wrn",
    "InvitationAccept.wrn",
    "MagicLinkSignIn.wrn",
  ];
  for (const file of formFiles) {
    const source = readFileSync(join(componentsDir, file), "utf8");
    expect(source).toMatch(/<(?:Input|PinInput|StrongPassword|TogglePassword|Checkbox|Select)\b/);
    expect(source).toContain("<Button");
  }
});
