import { expect, test } from "bun:test";
import { compile } from "../src/index.ts";

test("compiles schema-backed actions and progressively enhanced forms", () => {
  const output = compile(
    `import { CreateUserSchema } from "./schema";
    page Users {
      action createUser using CreateUserSchema { invalidate("users"); return { id: input.name } }
      view { <form @submit='createUser'><input name='name' /></form> }
    }`,
    "Users.wrn",
  ).code;
  expect(output).toContain('data-wrn-action="createUser"');
  expect(output).toContain('name="_wrnexus_action" value="createUser"');
  expect(output).toContain("schema: CreateUserSchema");
  expect(output).toContain("__wrnexusInvalidatedTags");
  expect(output).toContain(
    "createActionClient<InferSchema<typeof CreateUserSchema>, Awaited<ReturnType<typeof createUser>>>",
  );
  expect(output).not.toContain("data-on-submit");
});
