Files
co-lite/solvway-admin-portal/app/components/registration/RegistrationForm.compact.test.tsx
T
ngqileandClaude Opus 5.5 ba6ab7554d feat(pages): a short sign-up form on landing pages, and coloured sections join
Landing-page forms drop job title, ask for one service in a dropdown and fold the
privacy notice behind one line above the consent box. QR, invitation and customer
forms keep the full form. Sections with a colour look join with no gap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
2026-12-04 10:47:02 +08:00

50 lines
2.8 KiB
TypeScript

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(<RegistrationForm {...base} submit={async () => 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(<RegistrationForm {...base} submit={submit} compact />);
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(<RegistrationForm {...base} submit={async () => 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();
});
});