feat: visitor pages, My QR, sign-in frame and shell refinements #39
No files matched your search
@@ -21,13 +21,13 @@ Verify for every task: `cd solvway-admin-portal && npx vitest run; echo VITEST=$
|
||||
- [x] 2.1 `VisitorCard` (ground, card, event header with the company label, the dates and location with icons, footer) and `VisitorState` (icon, heading, text, action). `RegistrationForm` drops its header, adds the "Mobile or email is required" hint (new key in `defaultMessages.ts`), sets the notice as fine print, and aligns the consent row.
|
||||
- Depends on: 1.3
|
||||
- Scope: `solvway-admin-portal/app/components/registration/**` except `QrCodeItem*`, `solvway-admin-portal/app/lib/i18n/defaultMessages.ts`
|
||||
- [ ] 2.2 `/r`, `/i` and `/c` render every state inside `VisitorCard`, with `VisitorState` for loading, inactive, error, too many, not yet, ended, thank you, welcome and checked in. Existing behaviour and text stay the same.
|
||||
- [x] 2.2 `/r`, `/i` and `/c` render every state inside `VisitorCard`, with `VisitorState` for loading, inactive, error, too many, not yet, ended, thank you, welcome and checked in. Existing behaviour and text stay the same.
|
||||
- Depends on: 2.1
|
||||
- Scope: `solvway-admin-portal/app/r/**`, `solvway-admin-portal/app/i/**`, `solvway-admin-portal/app/c/**`
|
||||
|
||||
## 3. Staff screens
|
||||
|
||||
- [ ] 3.1 My QR codes as cards: the event name as the title, dates and location, the switched-off badge in the card header, the QR and a wrapping button row.
|
||||
- [x] 3.1 My QR codes as cards: the event name as the title, dates and location, the switched-off badge in the card header, the QR and a wrapping button row.
|
||||
- Depends on: 2.2
|
||||
- Scope: `solvway-admin-portal/app/my-qr/**`, `solvway-admin-portal/app/components/registration/QrCodeItem*`
|
||||
- [x] 3.2 Reset password uses the login page's two-column frame. Remove the stale brown and gold comments in login.
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ getCheckin: vi.fn(), lookupCheckin: vi.fn(), registerWalkIn: vi.fn() }));
|
||||
vi.mock("@/app/lib/services/publicInvite", () => mocks);
|
||||
vi.mock("next/navigation", () => ({ useParams: () => ({ token: "chk1" }) }));
|
||||
|
||||
import { ApiError } from "@/app/lib/clientApi";
|
||||
import CheckinPage from "./page";
|
||||
|
||||
const open = {
|
||||
state: "OPEN", eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC", companyName: "INS",
|
||||
notice: { id: 7, textEn: "We keep your data safe.", textMs: "Data anda selamat." }, interests: [],
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.getCheckin.mockReset().mockResolvedValue(open);
|
||||
mocks.lookupCheckin.mockReset().mockResolvedValue({ result: "CHECKED_IN", firstName: "Aini" });
|
||||
mocks.registerWalkIn.mockReset().mockResolvedValue({});
|
||||
});
|
||||
|
||||
const h1s = () => screen.getAllByRole("heading", { level: 1 });
|
||||
|
||||
describe("/c visitor card", () => {
|
||||
it("lookup sits in the card under the event header with one h1", async () => {
|
||||
render(<CheckinPage />);
|
||||
await screen.findByLabelText("Mobile number or email");
|
||||
expect(screen.getByText("INS", { selector: "p" })).toBeTruthy();
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]);
|
||||
expect(screen.getByText("2026-12-01 - 2026-12-02")).toBeTruthy();
|
||||
expect(document.querySelectorAll("main").length).toBe(1);
|
||||
});
|
||||
|
||||
it("walk-in form shows the notice before consent under one h1", async () => {
|
||||
const user = userEvent.setup();
|
||||
mocks.lookupCheckin.mockResolvedValue({ result: "FORM" });
|
||||
render(<CheckinPage />);
|
||||
await user.type(await screen.findByLabelText("Mobile number or email"), "0123456789");
|
||||
await user.click(screen.getByRole("button", { name: "Check in" }));
|
||||
await screen.findByLabelText("Your name");
|
||||
const notice = screen.getByText("We keep your data safe.");
|
||||
expect(notice.compareDocumentPosition(screen.getByLabelText(/I agree to INS/)) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]);
|
||||
});
|
||||
|
||||
it("welcome shows an icon and heading under the event header", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<CheckinPage />);
|
||||
await user.type(await screen.findByLabelText("Mobile number or email"), "0123456789");
|
||||
await user.click(screen.getByRole("button", { name: "Check in" }));
|
||||
const s = await screen.findByRole("status");
|
||||
expect(s.querySelector("svg")).toBeTruthy();
|
||||
expect(screen.getByRole("heading", { level: 2 }).textContent).toBe("Welcome, Aini. You're checked in.");
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]);
|
||||
});
|
||||
|
||||
it("not yet and ended have an icon and the heading as the only h1", async () => {
|
||||
mocks.getCheckin.mockResolvedValue({ state: "NOT_YET", startDate: "2026-12-01" });
|
||||
const { unmount } = render(<CheckinPage />);
|
||||
const s = await screen.findByRole("status");
|
||||
expect(s.querySelector("svg")).toBeTruthy();
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["Check-in opens on 2026-12-01."]);
|
||||
unmount();
|
||||
mocks.getCheckin.mockResolvedValue({ state: "ENDED", startDate: "2026-12-01" });
|
||||
render(<CheckinPage />);
|
||||
await screen.findByText("This event has ended.");
|
||||
expect(h1s().length).toBe(1);
|
||||
expect(document.querySelectorAll("main").length).toBe(1);
|
||||
});
|
||||
|
||||
it("inactive and load error are alerts with one h1 and no event details", async () => {
|
||||
mocks.getCheckin.mockRejectedValue(new ApiError("x", 404, { code: "CODE_INACTIVE" }));
|
||||
const { unmount } = render(<CheckinPage />);
|
||||
expect((await screen.findByRole("alert")).querySelector("svg")).toBeTruthy();
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["This code is no longer active."]);
|
||||
unmount();
|
||||
mocks.getCheckin.mockRejectedValue(new ApiError("x", 500, {}));
|
||||
render(<CheckinPage />);
|
||||
await screen.findByRole("alert");
|
||||
expect(h1s().length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
import { useEffect, useState, type FormEvent } from "react";
|
||||
import { useParams } from "next/navigation";
|
||||
import { AlertCircle, CheckCircle2, Clock, Loader2 } from "lucide-react";
|
||||
import { Button } from "@/app/components/ui/button";
|
||||
import { Input } from "@/app/components/ui/input";
|
||||
import { Label } from "@/app/components/ui/label";
|
||||
import { VisitorCard, VisitorState } from "@/app/components/registration/VisitorCard";
|
||||
import { RegistrationForm, apiData, failMessage } from "@/app/components/registration/RegistrationForm";
|
||||
import { getCheckin, lookupCheckin, registerWalkIn, type CheckinState } from "@/app/lib/services/publicInvite";
|
||||
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
||||
@@ -57,19 +59,22 @@ export default function CheckinPage() {
|
||||
}
|
||||
|
||||
const open = state?.state === "OPEN" ? state : null;
|
||||
const alone = (icon: typeof Clock, heading: string, role: "status" | "alert", tone?: "error") => (
|
||||
<VisitorCard><VisitorState h1 icon={icon} heading={heading} role={role} tone={tone} /></VisitorCard>
|
||||
);
|
||||
if (phase === "loading") return alone(Loader2, t("UiLoading"), "status");
|
||||
if (phase === "inactive") return alone(AlertCircle, t("RegInactive"), "alert");
|
||||
if (phase === "error" || !state) return alone(AlertCircle, error ?? "", "alert", "error");
|
||||
if (!open) return alone(Clock, state.state === "NOT_YET" ? t("ChkNotYet", { date: state.startDate }) : t("ChkEnded"), "status");
|
||||
|
||||
let body;
|
||||
if (phase === "loading") body = <p role="status">{t("UiLoading")}</p>;
|
||||
else if (phase === "inactive") body = <p role="alert">{t("RegInactive")}</p>;
|
||||
else if (phase === "error" || !state) body = <p role="alert" className="text-sm text-destructive">{error}</p>;
|
||||
else if (!open) body = <p role="status">{state.state === "NOT_YET" ? t("ChkNotYet", { date: state.startDate }) : t("ChkEnded")}</p>;
|
||||
else if (phase === "welcome") body = <p role="status" className="text-lg font-medium">{firstName ? t("InviteWelcome", { name: firstName }) : t("InviteWelcomeAnon")}</p>;
|
||||
else if (phase === "done") body = <p role="status" className="text-lg font-medium">{t("ChkDone", { event: open.eventName })}</p>;
|
||||
if (phase === "welcome") body = <VisitorState icon={CheckCircle2} heading={firstName ? t("InviteWelcome", { name: firstName }) : t("InviteWelcomeAnon")} role="status" />;
|
||||
else if (phase === "done") body = <VisitorState icon={CheckCircle2} heading={t("ChkDone", { event: open.eventName })} role="status" />;
|
||||
else if (phase === "form") {
|
||||
body = <RegistrationForm tooManyKey="InviteTooMany" info={open} submit={(b) => registerWalkIn(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />;
|
||||
} else {
|
||||
body = (
|
||||
<form onSubmit={lookup} className="space-y-4" noValidate>
|
||||
<h1 className="text-2xl font-semibold">{open.eventName}</h1>
|
||||
{error && <p role="alert" className="text-sm text-destructive">{error}</p>}
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="chk-value">{t("ChkLookup")}</Label>
|
||||
@@ -80,5 +85,5 @@ export default function CheckinPage() {
|
||||
);
|
||||
}
|
||||
|
||||
return <main className="mx-auto w-full max-w-md px-4 py-6">{body}</main>;
|
||||
return <VisitorCard event={open}>{body}</VisitorCard>;
|
||||
}
|
||||
@@ -10,17 +10,17 @@ const props = { info, submit: async () => undefined, onDone: () => {}, onInactiv
|
||||
const wrap = (ui: React.ReactElement) => render(ui);
|
||||
|
||||
describe("RegistrationForm look", () => {
|
||||
it("hides its own header when header is false", () => {
|
||||
wrap(<RegistrationForm {...props} header={false} />);
|
||||
it("renders no heading of its own: the visitor card carries the event header", () => {
|
||||
wrap(<RegistrationForm {...props} />);
|
||||
expect(screen.queryByRole("heading", { level: 1 })).toBeNull();
|
||||
});
|
||||
it("links a contact hint to the mobile field", () => {
|
||||
wrap(<RegistrationForm {...props} header={false} />);
|
||||
wrap(<RegistrationForm {...props} />);
|
||||
const hint = screen.getByText("Mobile or email is required");
|
||||
expect(screen.getByLabelText("Mobile number").getAttribute("aria-describedby")).toBe(hint.id);
|
||||
});
|
||||
it("shows the notice as fine print in both languages", () => {
|
||||
wrap(<RegistrationForm {...props} header={false} />);
|
||||
wrap(<RegistrationForm {...props} />);
|
||||
expect(screen.getByText("English text").parentElement?.className).toContain("text-muted-foreground");
|
||||
expect(screen.getByText("Teks Melayu")).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -30,10 +30,6 @@ export function failMessage(t: (k: string) => string, err: unknown, tooMany = "R
|
||||
}
|
||||
|
||||
interface Props {
|
||||
/** Heading text; the event name when omitted. */
|
||||
title?: string;
|
||||
/** Render the event header (default). Pages inside a VisitorCard pass false: the card shows it. */
|
||||
header?: boolean;
|
||||
/** i18n key for the too-many message (default RegTooMany, the /r wording). */
|
||||
tooManyKey?: string;
|
||||
info: RegistrationInfo;
|
||||
@@ -46,8 +42,9 @@ interface Props {
|
||||
onInactive: () => void;
|
||||
}
|
||||
|
||||
// The visitor registration form shared by /r, /i and /c: event header, fields, bilingual privacy notice and consent.
|
||||
export function RegistrationForm({ title, header = true, tooManyKey, info, initial, submit, onDone, onInactive }: Props) {
|
||||
// The visitor registration form shared by /r, /i and /c: fields, bilingual privacy notice and consent.
|
||||
// The event header comes from the VisitorCard around it.
|
||||
export function RegistrationForm({ tooManyKey, info, initial, submit, onDone, onInactive }: Props) {
|
||||
const t = useT();
|
||||
const [form, setForm] = useState<RegistrationBody>({ ...EMPTY, ...initial });
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
@@ -99,14 +96,6 @@ export function RegistrationForm({ title, header = true, tooManyKey, info, initi
|
||||
|
||||
return (
|
||||
<form onSubmit={onSubmit} className="space-y-4" noValidate>
|
||||
{header && (
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">{title ?? info.eventName}</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{info.companyName} | {info.startDate} - {info.endDate} | {info.location}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{formError && <p role="alert" className="text-sm text-destructive">{formError}</p>}
|
||||
{field("name", t("RegName"))}
|
||||
{field("mobile", t("RegMobile"), "tel", t("RegContactHint"))}
|
||||
|
||||
@@ -38,16 +38,19 @@ interface StateProps {
|
||||
action?: ReactNode;
|
||||
role?: "status" | "alert";
|
||||
tone?: "default" | "error";
|
||||
/** The heading is the page's h1: for states shown without the card's event header. */
|
||||
h1?: boolean;
|
||||
}
|
||||
|
||||
// A message inside the card (thanks, inactive, closed). Always h2: the card's event header carries the h1.
|
||||
export function VisitorState({ icon: Icon, heading, text, action, role, tone = "default" }: StateProps) {
|
||||
// A message inside the card (thanks, inactive, closed). h2 under the event header's h1; h1 when the card has no event header.
|
||||
export function VisitorState({ icon: Icon, heading, text, action, role, tone = "default", h1 }: StateProps) {
|
||||
const Heading = h1 ? "h1" : "h2";
|
||||
return (
|
||||
<div role={role} className="flex flex-col items-center gap-3 text-center">
|
||||
<span className={`flex size-12 items-center justify-center rounded-full ${tone === "error" ? "bg-destructive/10 text-destructive" : "bg-accent text-accent-foreground"}`}>
|
||||
<Icon className="size-6" aria-hidden="true" />
|
||||
</span>
|
||||
<h2 className="text-lg font-semibold">{heading}</h2>
|
||||
<Heading className="text-lg font-semibold">{heading}</Heading>
|
||||
{text && <p className="text-sm text-muted-foreground">{text}</p>}
|
||||
{action}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ getInvite: vi.fn(), submitInvite: vi.fn(), inviteCheckin: vi.fn() }));
|
||||
vi.mock("@/app/lib/services/publicInvite", () => mocks);
|
||||
vi.mock("next/navigation", () => ({ useParams: () => ({ token: "inv1" }) }));
|
||||
|
||||
import { ApiError } from "@/app/lib/clientApi";
|
||||
import InvitePage from "./page";
|
||||
|
||||
const info = {
|
||||
eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC", companyName: "INS",
|
||||
notice: { id: 7, textEn: "We keep your data safe.", textMs: "Data anda selamat." }, interests: [],
|
||||
guest: { name: "Aini Binti", mobile: "", email: "aini@b.co", companyName: "Acme" }, state: "OPEN",
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.getInvite.mockReset().mockResolvedValue(info);
|
||||
mocks.submitInvite.mockReset().mockResolvedValue({});
|
||||
mocks.inviteCheckin.mockReset().mockResolvedValue({ firstName: "Aini" });
|
||||
});
|
||||
|
||||
const h1s = () => screen.getAllByRole("heading", { level: 1 });
|
||||
|
||||
describe("/i visitor card", () => {
|
||||
it("form shows the invited title as the only h1 with the event header and notice before consent", async () => {
|
||||
render(<InvitePage />);
|
||||
await screen.findByLabelText("Your name");
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["You're invited to Expo 2026"]);
|
||||
expect(screen.getByText("INS", { selector: "p" })).toBeTruthy();
|
||||
expect(screen.getByText("2026-12-01 - 2026-12-02")).toBeTruthy();
|
||||
expect(screen.getByText("KLCC")).toBeTruthy();
|
||||
const notice = screen.getByText("We keep your data safe.");
|
||||
expect(notice.compareDocumentPosition(screen.getByLabelText(/I agree to INS/)) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(document.querySelectorAll("main").length).toBe(1);
|
||||
});
|
||||
|
||||
it("thank you, registered and checked in show an icon and heading under one h1", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<InvitePage />);
|
||||
await user.click(await screen.findByRole("button", { name: "Register" }));
|
||||
const s = await screen.findByRole("status");
|
||||
expect(s.querySelector("svg")).toBeTruthy();
|
||||
expect(screen.getByRole("heading", { level: 2 }).textContent).toContain("Thank you");
|
||||
expect(h1s().length).toBe(1);
|
||||
});
|
||||
|
||||
it("check-in day offers the button and welcomes with an icon under one h1", async () => {
|
||||
const user = userEvent.setup();
|
||||
mocks.getInvite.mockResolvedValue({ ...info, state: "CHECKIN" });
|
||||
render(<InvitePage />);
|
||||
await user.click(await screen.findByRole("button", { name: "Check in" }));
|
||||
const s = await screen.findByRole("status");
|
||||
expect(s.querySelector("svg")).toBeTruthy();
|
||||
expect(screen.getByRole("heading", { level: 2 }).textContent).toBe("Welcome, Aini. You're checked in.");
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]);
|
||||
});
|
||||
|
||||
it("inactive and error have an alert icon, one h1 and no event details", async () => {
|
||||
mocks.getInvite.mockRejectedValue(new ApiError("x", 404, { code: "INVITE_INACTIVE" }));
|
||||
const { unmount } = render(<InvitePage />);
|
||||
expect((await screen.findByRole("alert")).querySelector("svg")).toBeTruthy();
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["This invitation is no longer active."]);
|
||||
expect(screen.queryByText("Expo 2026")).toBeNull();
|
||||
unmount();
|
||||
mocks.getInvite.mockRejectedValue(new ApiError("x", 500, {}));
|
||||
render(<InvitePage />);
|
||||
await screen.findByRole("alert");
|
||||
expect(h1s().length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -33,7 +33,10 @@ describe("/i/[token] invite page", () => {
|
||||
expect((screen.getByLabelText("Company") as HTMLInputElement).value).toBe("Acme");
|
||||
expect(screen.getByText("Data anda selamat.")).toBeTruthy();
|
||||
expect(screen.getByRole("heading", { level: 1 }).textContent).toBe("You're invited to Expo 2026");
|
||||
expect(screen.getByText(/INS \| 2026-12-01 - 2026-12-02 \| KLCC/)).toBeTruthy();
|
||||
// refine-visitor-pages-and-shell: the card header shows company, dates and location on their own lines.
|
||||
expect(screen.getByText("INS")).toBeTruthy();
|
||||
expect(screen.getByText("2026-12-01 - 2026-12-02")).toBeTruthy();
|
||||
expect(screen.getByText("KLCC")).toBeTruthy();
|
||||
expect(screen.getByLabelText(/I agree to INS using my details/).getAttribute("aria-checked")).toBe("false");
|
||||
expect(mocks.getInvite).toHaveBeenCalledWith("inv1");
|
||||
});
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams } from "next/navigation";
|
||||
import { AlertCircle, CheckCircle2, Loader2 } from "lucide-react";
|
||||
import { Button } from "@/app/components/ui/button";
|
||||
import { VisitorCard, VisitorState } from "@/app/components/registration/VisitorCard";
|
||||
import { RegistrationForm, apiData, failMessage } from "@/app/components/registration/RegistrationForm";
|
||||
import { getInvite, inviteCheckin, submitInvite, type InviteInfo } from "@/app/lib/services/publicInvite";
|
||||
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
||||
@@ -46,18 +48,19 @@ export default function InvitePage() {
|
||||
}
|
||||
|
||||
const event = info?.eventName ?? "";
|
||||
const done = (text: string) => <VisitorState icon={CheckCircle2} heading={text} role="status" />;
|
||||
if (phase === "loading") return <VisitorCard><VisitorState h1 icon={Loader2} heading={t("UiLoading")} role="status" /></VisitorCard>;
|
||||
if (phase === "inactive") return <VisitorCard><VisitorState h1 icon={AlertCircle} heading={t("InviteInactive")} role="alert" /></VisitorCard>;
|
||||
if (phase === "error" || !info) return <VisitorCard><VisitorState h1 icon={AlertCircle} heading={error ?? ""} role="alert" tone="error" /></VisitorCard>;
|
||||
|
||||
let body;
|
||||
if (phase === "loading") body = <p role="status">{t("UiLoading")}</p>;
|
||||
else if (phase === "inactive") body = <p role="alert">{t("InviteInactive")}</p>;
|
||||
else if (phase === "error" || !info) body = <p role="alert" className="text-sm text-destructive">{error}</p>;
|
||||
else if (welcome !== null) body = <p role="status" className="text-lg font-medium">{welcome ? t("InviteWelcome", { name: welcome }) : t("InviteWelcomeAnon")}</p>;
|
||||
else if (info.state === "CHECKED_IN") body = <p role="status" className="text-lg font-medium">{t("InviteCheckedIn", { event })}</p>;
|
||||
else if (thanks) body = <p role="status" className="text-lg font-medium">{t("RegThanks", { event })}</p>;
|
||||
else if (info.state === "REGISTERED") body = <p role="status" className="text-lg font-medium">{t("InviteRegistered", { event })}</p>;
|
||||
if (welcome !== null) body = done(welcome ? t("InviteWelcome", { name: welcome }) : t("InviteWelcomeAnon"));
|
||||
else if (info.state === "CHECKED_IN") body = done(t("InviteCheckedIn", { event }));
|
||||
else if (thanks) body = done(t("RegThanks", { event }));
|
||||
else if (info.state === "REGISTERED") body = done(t("InviteRegistered", { event }));
|
||||
else if (info.state === "CHECKIN") {
|
||||
body = (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-2xl font-semibold">{event}</h1>
|
||||
{error && <p role="alert" className="text-sm text-destructive">{error}</p>}
|
||||
<Button className="h-11 w-full" onClick={checkIn}>{t("InviteCheckin")}</Button>
|
||||
</div>
|
||||
@@ -66,7 +69,6 @@ export default function InvitePage() {
|
||||
body = (
|
||||
<RegistrationForm
|
||||
info={info}
|
||||
title={t("InviteTitle", { event })}
|
||||
tooManyKey="InviteTooMany"
|
||||
initial={{ name: info.guest.name ?? "", mobile: info.guest.mobile ?? "", email: info.guest.email ?? "", companyName: info.guest.companyName ?? "" }}
|
||||
submit={(b) => submitInvite(token, b)}
|
||||
@@ -76,5 +78,5 @@ export default function InvitePage() {
|
||||
);
|
||||
}
|
||||
|
||||
return <main className="mx-auto w-full max-w-md px-4 py-6">{body}</main>;
|
||||
return <VisitorCard event={info} title={info.state === "OPEN" && welcome === null && !thanks ? t("InviteTitle", { event }) : undefined}>{body}</VisitorCard>;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ getRegistration: vi.fn(), submitRegistration: vi.fn() }));
|
||||
vi.mock("@/app/lib/services/publicRegistration", () => mocks);
|
||||
vi.mock("next/navigation", () => ({ useParams: () => ({ token: "tok1" }) }));
|
||||
|
||||
import { ApiError } from "@/app/lib/clientApi";
|
||||
import RegisterPage from "./page";
|
||||
|
||||
const info = {
|
||||
eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC", companyName: "INS",
|
||||
notice: { id: 7, textEn: "We keep your data safe.", textMs: "Data anda selamat." }, interests: [],
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.getRegistration.mockReset().mockResolvedValue(info);
|
||||
mocks.submitRegistration.mockReset().mockResolvedValue({});
|
||||
});
|
||||
|
||||
const h1s = () => screen.getAllByRole("heading", { level: 1 });
|
||||
|
||||
describe("/r visitor card", () => {
|
||||
it("shows the company label, one h1, dates and location, with the notice before consent", async () => {
|
||||
render(<RegisterPage />);
|
||||
await screen.findByLabelText("Your name");
|
||||
expect(screen.getByText("INS", { selector: "p" })).toBeTruthy();
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]);
|
||||
expect(screen.getByText("2026-12-01 - 2026-12-02")).toBeTruthy();
|
||||
expect(screen.getByText("KLCC")).toBeTruthy();
|
||||
const notice = screen.getByText("We keep your data safe.");
|
||||
const consent = screen.getByLabelText(/I agree to INS/);
|
||||
expect(notice.compareDocumentPosition(consent) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
expect(document.querySelectorAll("main").length).toBe(1);
|
||||
});
|
||||
|
||||
it("loading has a status and its heading as the only h1", () => {
|
||||
render(<RegisterPage />);
|
||||
expect(screen.getByRole("status")).toBeTruthy();
|
||||
expect(h1s().length).toBe(1);
|
||||
expect(document.querySelectorAll("main").length).toBe(1);
|
||||
});
|
||||
|
||||
it("inactive shows an alert heading as the only h1, no event details", async () => {
|
||||
mocks.getRegistration.mockRejectedValue(new ApiError("x", 404, { code: "CODE_INACTIVE" }));
|
||||
render(<RegisterPage />);
|
||||
await screen.findByRole("alert");
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["This code is no longer active."]);
|
||||
expect(screen.queryByText("Expo 2026")).toBeNull();
|
||||
expect(document.querySelector("svg")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("load error is an alert with one h1", async () => {
|
||||
mocks.getRegistration.mockRejectedValue(new ApiError("x", 429, { code: "TOO_MANY" }));
|
||||
render(<RegisterPage />);
|
||||
await screen.findByRole("alert");
|
||||
expect(h1s().length).toBe(1);
|
||||
});
|
||||
|
||||
it("thank you keeps the event header with an icon, one h1 and the register-another button", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<RegisterPage />);
|
||||
await user.type(await screen.findByLabelText("Your name"), "Aini");
|
||||
await user.type(screen.getByLabelText("Email"), "a@b.co");
|
||||
await user.click(screen.getByRole("button", { name: "Register" }));
|
||||
const done = await screen.findByRole("status");
|
||||
expect(done.textContent).toContain("Thank you, you're registered for Expo 2026");
|
||||
expect(done.querySelector("svg")).toBeTruthy();
|
||||
expect(screen.getByRole("heading", { level: 2 }).textContent).toContain("Thank you");
|
||||
expect(h1s().map((h) => h.textContent)).toEqual(["Expo 2026"]);
|
||||
expect(screen.getByRole("button", { name: "Register another person" })).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams } from "next/navigation";
|
||||
import { AlertCircle, CheckCircle2, Loader2 } from "lucide-react";
|
||||
import { Button } from "@/app/components/ui/button";
|
||||
import { VisitorCard, VisitorState } from "@/app/components/registration/VisitorCard";
|
||||
import { RegistrationForm, apiData } from "@/app/components/registration/RegistrationForm";
|
||||
import { getRegistration, submitRegistration, type RegistrationInfo } from "@/app/lib/services/publicRegistration";
|
||||
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
||||
@@ -32,19 +34,16 @@ export default function RegisterPage() {
|
||||
});
|
||||
}, [token, t]);
|
||||
|
||||
let body;
|
||||
if (phase === "loading") body = <p role="status">{t("UiLoading")}</p>;
|
||||
else if (phase === "inactive") body = <p role="alert">{t("RegInactive")}</p>;
|
||||
else if (phase === "done") {
|
||||
body = (
|
||||
<div className="space-y-4">
|
||||
<p role="status" className="text-lg font-medium">{t("RegThanks", { event: info?.eventName ?? "" })}</p>
|
||||
<Button className="h-11" onClick={() => setPhase("form")}>{t("RegAnother")}</Button>
|
||||
</div>
|
||||
);
|
||||
} else if (info) {
|
||||
body = <RegistrationForm info={info} submit={(b) => submitRegistration(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />;
|
||||
} else body = <p role="alert" className="text-sm text-destructive">{loadError}</p>;
|
||||
|
||||
return <main className="mx-auto w-full max-w-md px-4 py-6">{body}</main>;
|
||||
if (phase === "loading") return <VisitorCard><VisitorState h1 icon={Loader2} heading={t("UiLoading")} role="status" /></VisitorCard>;
|
||||
if (phase === "inactive") return <VisitorCard><VisitorState h1 icon={AlertCircle} heading={t("RegInactive")} role="alert" /></VisitorCard>;
|
||||
if (!info) return <VisitorCard><VisitorState h1 icon={AlertCircle} heading={loadError ?? ""} role="alert" tone="error" /></VisitorCard>;
|
||||
return (
|
||||
<VisitorCard event={info}>
|
||||
{phase === "done" ? (
|
||||
<VisitorState icon={CheckCircle2} heading={t("RegThanks", { event: info.eventName })} role="status" action={<Button className="h-11" onClick={() => setPhase("form")}>{t("RegAnother")}</Button>} />
|
||||
) : (
|
||||
<RegistrationForm info={info} submit={(b) => submitRegistration(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />
|
||||
)}
|
||||
</VisitorCard>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user