From b4d36175d3c3950872a30980af4f9b9da86877e8 Mon Sep 17 00:00:00 2001 From: ngqile Date: Wed, 2 Dec 2026 01:38:37 +0800 Subject: [PATCH] fix: paste guests, form errors, send feedback, check-in errors, invite recipients Found by the manual e2e of the production build: - paste guests preview counted an array, so it read "[object Object]" and never offered Save guests; - New event and Add user errors now clear when the field is fixed; - "Send to all unsent" says when nothing was unsent; - the check-in lookup shows an error on an empty submit and carries the typed email or mobile into the walk-in form; - invitation emails sent over Pub/Sub now save their recipient's link, so the Emails page shows the recipient. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../app/c/[token]/page.lookup.test.tsx | 46 +++++++++++++++++++ solvway-admin-portal/app/c/[token]/page.tsx | 9 ++-- .../events/EventForm.clearErrors.test.tsx | 23 ++++++++++ .../app/components/events/EventForm.tsx | 16 ++++--- .../events/GuestsCard.nothingToSend.test.tsx | 28 +++++++++++ .../app/components/events/GuestsCard.tsx | 2 +- .../users/UserForm.clearErrors.test.tsx | 22 +++++++++ .../app/components/users/UserForm.tsx | 15 +++--- .../app/lib/i18n/defaultMessages.ts | 1 + .../lib/services/adminGuests.added.test.ts | 14 ++++++ .../app/lib/services/adminGuests.ts | 7 ++- .../services/email/service/EmailService.java | 2 + .../EmailServiceRecipientLinkTest.java | 39 ++++++++++++++++ 13 files changed, 206 insertions(+), 18 deletions(-) create mode 100644 solvway-admin-portal/app/c/[token]/page.lookup.test.tsx create mode 100644 solvway-admin-portal/app/components/events/EventForm.clearErrors.test.tsx create mode 100644 solvway-admin-portal/app/components/events/GuestsCard.nothingToSend.test.tsx create mode 100644 solvway-admin-portal/app/components/users/UserForm.clearErrors.test.tsx create mode 100644 solvway-admin-portal/app/lib/services/adminGuests.added.test.ts create mode 100644 solvway-services-email/src/test/java/com/solvway/services/email/service/EmailServiceRecipientLinkTest.java diff --git a/solvway-admin-portal/app/c/[token]/page.lookup.test.tsx b/solvway-admin-portal/app/c/[token]/page.lookup.test.tsx new file mode 100644 index 0000000..a2be59e --- /dev/null +++ b/solvway-admin-portal/app/c/[token]/page.lookup.test.tsx @@ -0,0 +1,46 @@ +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 CheckinPage from "./page"; + +beforeEach(() => { + mocks.getCheckin.mockReset().mockResolvedValue({ + 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: [], + }); + mocks.lookupCheckin.mockReset().mockResolvedValue({ result: "FORM" }); +}); + +describe("/c/[token] lookup", () => { + it("shows a visible error and does not look up when the field is empty", async () => { + const user = userEvent.setup(); + render(); + await user.click(await screen.findByRole("button", { name: "Check in" })); + expect(await screen.findByText("Enter a mobile number or an email.")).toBeInTheDocument(); + expect(screen.getByLabelText("Mobile number or email")).toHaveAttribute("aria-invalid", "true"); + expect(mocks.lookupCheckin).not.toHaveBeenCalled(); + }); + + it("carries a looked-up email into the walk-in form", async () => { + const user = userEvent.setup(); + render(); + await user.type(await screen.findByLabelText("Mobile number or email"), "w@b.co"); + await user.click(screen.getByRole("button", { name: "Check in" })); + expect(await screen.findByLabelText("Email")).toHaveValue("w@b.co"); + expect(screen.getByLabelText("Mobile number")).toHaveValue(""); + }); + + it("carries a looked-up mobile into the walk-in form", async () => { + const user = userEvent.setup(); + render(); + await user.type(await screen.findByLabelText("Mobile number or email"), "0123456789"); + await user.click(screen.getByRole("button", { name: "Check in" })); + expect(await screen.findByLabelText("Mobile number")).toHaveValue("0123456789"); + expect(screen.getByLabelText("Email")).toHaveValue(""); + }); +}); diff --git a/solvway-admin-portal/app/c/[token]/page.tsx b/solvway-admin-portal/app/c/[token]/page.tsx index 2abed69..bbb752e 100644 --- a/solvway-admin-portal/app/c/[token]/page.tsx +++ b/solvway-admin-portal/app/c/[token]/page.tsx @@ -41,7 +41,10 @@ export default function CheckinPage() { async function lookup(e: FormEvent) { e.preventDefault(); - if (!value.trim()) return; + if (!value.trim()) { + setError(t("RegContactRequired")); + return; + } setBusy(true); setError(null); try { @@ -71,14 +74,14 @@ export default function CheckinPage() { if (phase === "welcome") body = ; else if (phase === "done") body = ; else if (phase === "form") { - body = registerWalkIn(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />; + body = registerWalkIn(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />; } else { body = (
{error &&

{error}

}
- setValue(e.target.value)} disabled={busy} /> + setValue(e.target.value)} disabled={busy} aria-invalid={!!error} />
diff --git a/solvway-admin-portal/app/components/events/EventForm.clearErrors.test.tsx b/solvway-admin-portal/app/components/events/EventForm.clearErrors.test.tsx new file mode 100644 index 0000000..039c2cf --- /dev/null +++ b/solvway-admin-portal/app/components/events/EventForm.clearErrors.test.tsx @@ -0,0 +1,23 @@ +import { render, screen, waitFor } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { describe, it, expect, vi } from "vitest"; + +vi.mock("@/app/lib/services/adminEvents", () => ({ listSalespersonOptions: vi.fn().mockResolvedValue([]) })); + +import { EventForm } from "./EventForm"; +import { pickDate } from "@/test/pickDate"; + +describe("EventForm error clearing", () => { + it("clears a field's error as soon as that field is filled", async () => { + render(); + await userEvent.click(screen.getByRole("button", { name: /create/i })); + expect(await screen.findByText("Name is required.")).toBeInTheDocument(); + + await userEvent.type(screen.getByLabelText("Name"), "A"); + expect(screen.queryByText("Name is required.")).not.toBeInTheDocument(); + expect(screen.getByText("Location is required.")).toBeInTheDocument(); + + pickDate("Start date", "2026-12-10"); + await waitFor(() => expect(screen.queryByText("Start date is required.")).not.toBeInTheDocument()); + }); +}); diff --git a/solvway-admin-portal/app/components/events/EventForm.tsx b/solvway-admin-portal/app/components/events/EventForm.tsx index 046bfbd..980b0fe 100644 --- a/solvway-admin-portal/app/components/events/EventForm.tsx +++ b/solvway-admin-portal/app/components/events/EventForm.tsx @@ -59,6 +59,9 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) { const [pickersError, setPickersError] = useState(null); const [fieldErrors, setFieldErrors] = useState>({}); + // A field's error goes away as soon as the user edits that field; the next submit re-validates. + const clearError = (k: string) => setFieldErrors((e) => (k in e ? Object.fromEntries(Object.entries(e).filter(([f]) => f !== k)) : e)); + const [formError, setFormError] = useState(null); const [saving, setSaving] = useState(false); @@ -197,6 +200,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) { value={companyChoice} onValueChange={(v) => { setCompanyChoice(v); + clearError("company"); setSelectedIds(new Set()); // the team is company-specific }} disabled={saving} @@ -224,7 +228,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) { id="evt-name" required value={name} - onChange={(e) => setName(e.target.value)} + onChange={(e) => { setName(e.target.value); clearError("name"); }} disabled={saving} aria-invalid={!!fieldErrors.name} /> @@ -241,7 +245,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) { id="evt-location" required value={location} - onChange={(e) => setLocation(e.target.value)} + onChange={(e) => { setLocation(e.target.value); clearError("location"); }} disabled={saving} aria-invalid={!!fieldErrors.location} /> @@ -257,7 +261,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) { { setStartDate(v); clearError("startDate"); }} aria-label={t("EvtStartDate")} required disabled={saving} @@ -275,7 +279,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) { { setEndDate(v); clearError("endDate"); }} aria-label={t("EvtEndDate")} required disabled={saving} @@ -312,7 +316,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) { type="number" min={1} value={capacity} - onChange={(e) => setCapacity(e.target.value)} + onChange={(e) => { setCapacity(e.target.value); clearError("capacity"); }} disabled={saving || !canSetLimits} aria-invalid={!!fieldErrors.capacity} /> @@ -329,7 +333,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) { type="number" min={1} value={invitationCap} - onChange={(e) => setInvitationCap(e.target.value)} + onChange={(e) => { setInvitationCap(e.target.value); clearError("invitationCap"); }} disabled={saving || !canSetLimits} aria-invalid={!!fieldErrors.invitationCap} /> diff --git a/solvway-admin-portal/app/components/events/GuestsCard.nothingToSend.test.tsx b/solvway-admin-portal/app/components/events/GuestsCard.nothingToSend.test.tsx new file mode 100644 index 0000000..37b155f --- /dev/null +++ b/solvway-admin-portal/app/components/events/GuestsCard.nothingToSend.test.tsx @@ -0,0 +1,28 @@ +import { describe, it, expect, vi } from "vitest"; +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; + +const mocks = vi.hoisted(() => ({ + listGuests: vi.fn(), + addGuests: vi.fn(), + removeGuest: vi.fn(), + sendInvites: vi.fn(), + getAttendance: vi.fn(), + useAdminAuth: vi.fn(), +})); +vi.mock("@/app/lib/services/adminGuests", () => mocks); +vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: mocks.useAdminAuth })); + +import { GuestsCard } from "./GuestsCard"; + +describe("GuestsCard send to all unsent", () => { + it("says so when nothing was sent or skipped", async () => { + mocks.listGuests.mockResolvedValue([]); + mocks.getAttendance.mockResolvedValue({}); + mocks.sendInvites.mockResolvedValue({ sent: 0, skippedNoEmail: 0 }); + mocks.useAdminAuth.mockReturnValue({ loading: false, hasModule: () => true }); + render(); + await userEvent.click(await screen.findByRole("button", { name: "Send to all unsent" })); + expect(await screen.findByRole("status")).toHaveTextContent("No unsent invitations"); + }); +}); diff --git a/solvway-admin-portal/app/components/events/GuestsCard.tsx b/solvway-admin-portal/app/components/events/GuestsCard.tsx index 7edbab7..3a05c0d 100644 --- a/solvway-admin-portal/app/components/events/GuestsCard.tsx +++ b/solvway-admin-portal/app/components/events/GuestsCard.tsx @@ -131,7 +131,7 @@ export function GuestsCard({ eventUuid, team = [] }: { eventUuid: string; team?: const send = (target: { guestIds: number[] } | { allUnsent: true }) => run(async () => { const res = await sendInvites(eventUuid, target); - setNotice(t("GuestSendResult", { sent: res.sent, skipped: res.skippedNoEmail })); + setNotice(res.sent + res.skippedNoEmail === 0 ? t("GuestNoUnsent") : t("GuestSendResult", { sent: res.sent, skipped: res.skippedNoEmail })); await load(); }, t("GuestSendFailed")); diff --git a/solvway-admin-portal/app/components/users/UserForm.clearErrors.test.tsx b/solvway-admin-portal/app/components/users/UserForm.clearErrors.test.tsx new file mode 100644 index 0000000..d096db2 --- /dev/null +++ b/solvway-admin-portal/app/components/users/UserForm.clearErrors.test.tsx @@ -0,0 +1,22 @@ +import { render, screen, waitFor } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { describe, it, expect, vi } from "vitest"; + +vi.mock("@/app/lib/services/adminRoles", () => ({ listAdminRoles: vi.fn().mockResolvedValue([]) })); +vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: vi.fn().mockReturnValue({ id: null }) })); + +import { UserForm } from "./UserForm"; + +describe("UserForm error clearing", () => { + it("clears a field's error as soon as that field is filled", async () => { + render(); + await userEvent.click(screen.getByRole("button", { name: /save|create|add/i })); + expect(await screen.findByText("Name is required.")).toBeInTheDocument(); + + await userEvent.type(screen.getByLabelText("Name"), "A"); + await waitFor(() => expect(screen.queryByText("Name is required.")).not.toBeInTheDocument()); + expect(screen.getByText("Email is required.")).toBeInTheDocument(); + await userEvent.type(screen.getByLabelText("Email"), "a@x.my"); + expect(screen.queryByText("Email is required.")).not.toBeInTheDocument(); + }); +}); diff --git a/solvway-admin-portal/app/components/users/UserForm.tsx b/solvway-admin-portal/app/components/users/UserForm.tsx index 08421b6..455885d 100644 --- a/solvway-admin-portal/app/components/users/UserForm.tsx +++ b/solvway-admin-portal/app/components/users/UserForm.tsx @@ -68,6 +68,9 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF const [loadingPickers, setLoadingPickers] = useState(true); const [fieldErrors, setFieldErrors] = useState>({}); + // A field's error goes away as soon as the user edits that field; the next submit re-validates. + const clearError = (k: string) => setFieldErrors((e) => (k in e ? Object.fromEntries(Object.entries(e).filter(([f]) => f !== k)) : e)); + const [formError, setFormError] = useState(null); const [saving, setSaving] = useState(false); @@ -161,7 +164,7 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF id="user-name" required value={name} - onChange={(e) => setName(e.target.value)} + onChange={(e) => { setName(e.target.value); clearError("name"); }} disabled={saving} aria-invalid={!!fieldErrors.name} /> @@ -188,7 +191,7 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF id="user-username" required value={username} - onChange={(e) => setUsername(e.target.value)} + onChange={(e) => { setUsername(e.target.value); clearError("username"); }} // The backend ignores username on update, so it is fixed once the user exists. disabled={saving || initial?.id != null} aria-invalid={!!fieldErrors.username} @@ -207,7 +210,7 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF type="email" required value={email} - onChange={(e) => setEmail(e.target.value)} + onChange={(e) => { setEmail(e.target.value); clearError("email"); }} disabled={saving} aria-invalid={!!fieldErrors.email} /> @@ -221,7 +224,7 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF {showCompany && (
- { setCompany(v); clearError("company"); }} disabled={saving}> @@ -244,8 +247,8 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF { setPassword(v); clearError("password"); }} + onConfirmPassword={(v) => { setConfirmPassword(v); clearError("confirmPassword"); }} disabled={saving} passwordError={fieldErrors.password} confirmError={fieldErrors.confirmPassword} diff --git a/solvway-admin-portal/app/lib/i18n/defaultMessages.ts b/solvway-admin-portal/app/lib/i18n/defaultMessages.ts index 6b7ba86..d9988b1 100644 --- a/solvway-admin-portal/app/lib/i18n/defaultMessages.ts +++ b/solvway-admin-portal/app/lib/i18n/defaultMessages.ts @@ -569,6 +569,7 @@ export const DEFAULT_MESSAGES: Record = { GuestAddedCount: "Added {count}", GuestSendAll: "Send to all unsent", GuestSendResult: "Sent {sent}, skipped {skipped} with no email", + GuestNoUnsent: "No unsent invitations", GuestSendFailed: "Could not send the invites.", GuestRegisteredRefused: "This guest has already registered and cannot be removed.", GuestRemoveFailed: "Could not remove the guest.", diff --git a/solvway-admin-portal/app/lib/services/adminGuests.added.test.ts b/solvway-admin-portal/app/lib/services/adminGuests.added.test.ts new file mode 100644 index 0000000..3ad360d --- /dev/null +++ b/solvway-admin-portal/app/lib/services/adminGuests.added.test.ts @@ -0,0 +1,14 @@ +import { describe, it, expect, vi } from "vitest"; + +const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn(), apiDelete: vi.fn() })); +vi.mock("@/app/lib/clientApi", () => mocks); + +import { addGuests } from "./adminGuests"; + +describe("addGuests result", () => { + it("turns the API's added guest list into a count", async () => { + // The mobile-api returns the added guests themselves, not a number. + mocks.apiPost.mockResolvedValue({ added: [{ name: "A" }, { name: "B" }], rejected: [] }); + expect(await addGuests("e1", [], true)).toEqual({ added: 2, rejected: [] }); + }); +}); diff --git a/solvway-admin-portal/app/lib/services/adminGuests.ts b/solvway-admin-portal/app/lib/services/adminGuests.ts index 0f45216..b8bff1e 100644 --- a/solvway-admin-portal/app/lib/services/adminGuests.ts +++ b/solvway-admin-portal/app/lib/services/adminGuests.ts @@ -46,8 +46,11 @@ export interface Attendance { const base = (uuid: string) => `/api/events/${encodeURIComponent(uuid)}`; export const listGuests = (uuid: string) => apiGet(`${base(uuid)}/guests`); -export const addGuests = (uuid: string, guests: GuestInput[], preview: boolean) => - apiPost(`${base(uuid)}/guests${preview ? "?preview=true" : ""}`, { guests }); +// The API lists the added guests; the screen only needs how many. +export const addGuests = async (uuid: string, guests: GuestInput[], preview: boolean): Promise => { + const res = await apiPost<{ added?: unknown[]; rejected: GuestRejection[] }>(`${base(uuid)}/guests${preview ? "?preview=true" : ""}`, { guests }); + return { added: res.added?.length ?? 0, rejected: res.rejected }; +}; export const removeGuest = (uuid: string, id: number) => apiDelete(`${base(uuid)}/guests/${id}`); export const sendInvites = (uuid: string, target: { guestIds: number[] } | { allUnsent: true }) => apiPost<{ sent: number; skippedNoEmail: number }>(`${base(uuid)}/guests/send`, target); diff --git a/solvway-services-email/src/main/java/com/solvway/services/email/service/EmailService.java b/solvway-services-email/src/main/java/com/solvway/services/email/service/EmailService.java index 73d8c9f..ae45715 100644 --- a/solvway-services-email/src/main/java/com/solvway/services/email/service/EmailService.java +++ b/solvway-services-email/src/main/java/com/solvway/services/email/service/EmailService.java @@ -38,6 +38,8 @@ public class EmailService { public Email save(Email email) { // A published email may carry "sender": null, which overrides the entity default; keep the column filled. if (email.getSender() == null) email.setSender(com.solvway.services.email.constants.EmailConstant.EMAIL_SENDER); + // Published emails arrive without the recipient back-reference, which would save email_id as NULL. + if (email.getRecipients() != null) email.getRecipients().forEach(r -> r.setEmail(email)); return emailRepository.save(email); } @Transactional diff --git a/solvway-services-email/src/test/java/com/solvway/services/email/service/EmailServiceRecipientLinkTest.java b/solvway-services-email/src/test/java/com/solvway/services/email/service/EmailServiceRecipientLinkTest.java new file mode 100644 index 0000000..7f7412e --- /dev/null +++ b/solvway-services-email/src/test/java/com/solvway/services/email/service/EmailServiceRecipientLinkTest.java @@ -0,0 +1,39 @@ +package com.solvway.services.email.service; + +import com.solvway.services.email.model.Email; +import com.solvway.services.email.model.Recipient; +import com.solvway.services.email.repo.EmailRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +/** Found live: invitation emails arrive over Pub/Sub with recipients not linked to the email, so email_id was saved as NULL. */ +@ExtendWith(MockitoExtension.class) +class EmailServiceRecipientLinkTest { + + @Mock private EmailRepository emailRepository; + @InjectMocks private EmailService service; + + @Test + void savedRecipientsPointBackAtTheEmail() { + when(emailRepository.save(any(Email.class))).thenAnswer(i -> i.getArgument(0)); + Recipient recipient = new Recipient(); + recipient.setRecipient("a@example.test"); + Email email = new Email(); + email.setRecipients(List.of(recipient)); + + service.save(email); + + assertThat(ReflectionTestUtils.getField(recipient, "email")).isSameAs(email); + } +} -- 2.54.1