import { describe, it, expect, vi } from "vitest"; import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { RegistrationForm } from "./RegistrationForm"; // add-compact-landing-form: landing pages use a short form; QR, invitation and customer forms keep the full one. const info = { eventName: "INS enquiries", startDate: "2026-12-01", endDate: "2099-12-31", location: "KL", companyName: "INS", notice: { id: 1, textEn: "English text", textMs: "Teks Melayu" }, interests: [{ id: 11, name: "WiFi Managed Services" }, { id: 12, name: "Cloud IP PABX" }], }; const base = { info, onDone: () => {}, onInactive: () => {} }; describe("RegistrationForm compact", () => { it("has no job title, one service dropdown, and the notice folded above the consent box", async () => { const user = userEvent.setup(); render( undefined} compact />); expect(screen.queryByLabelText("Job title")).not.toBeInTheDocument(); expect(screen.queryByRole("checkbox", { name: "WiFi Managed Services" })).not.toBeInTheDocument(); const service = screen.getByRole("combobox", { name: "Service interested in (optional)" }); expect(service).toHaveValue(""); expect(screen.getByRole("option", { name: "Choose a service" })).toBeInTheDocument(); const notice = screen.getByText("English text").closest("details")!; expect(notice).not.toHaveAttribute("open"); await user.click(screen.getByText("How we use your details (English / Bahasa Malaysia)")); expect(notice).toHaveAttribute("open"); expect(notice.compareDocumentPosition(screen.getByRole("checkbox")) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); }); it("posts the one chosen service", async () => { const submit = vi.fn().mockResolvedValue(undefined); const user = userEvent.setup(); render(); await user.type(screen.getByLabelText("Your name"), "Tan"); await user.type(screen.getByLabelText("Mobile number"), "0125550101"); await user.selectOptions(screen.getByRole("combobox", { name: "Service interested in (optional)" }), "12"); await user.click(screen.getByRole("checkbox")); await user.click(screen.getByRole("button", { name: "Register" })); expect(submit.mock.calls[0][0]).toMatchObject({ interestIds: [12], jobTitle: "" }); }); it("keeps the full form without the option", () => { render( undefined} />); expect(screen.getByLabelText("Job title")).toBeInTheDocument(); expect(screen.getByRole("checkbox", { name: "WiFi Managed Services" })).toBeInTheDocument(); expect(screen.queryByRole("combobox")).not.toBeInTheDocument(); expect(screen.getByText("English text").closest("details")).toBeNull(); }); // add-hero-fits-screen: tighter spacing, but controls stay 44 px (h-11) for touch. it("is tighter than the full form, with the consent in small text and 44 px controls", () => { const { container, unmount } = render( undefined} compact />); expect(container.querySelector("form")).toHaveClass("space-y-3"); expect(screen.getByText(/I agree to INS/).parentElement).toHaveClass("text-sm"); for (const el of [screen.getByLabelText("Your name"), screen.getByLabelText("Mobile number"), screen.getByRole("combobox"), screen.getByRole("button", { name: "Register" })]) { expect(el).toHaveClass("h-11"); } unmount(); const full = render( undefined} />); expect(full.container.querySelector("form")).toHaveClass("space-y-4"); expect(screen.getByText(/I agree to INS/).parentElement).not.toHaveClass("text-sm"); }); });