fix: e2e findings (paste guests, form errors, send feedback, check-in, invite recipients) #44
No files matched your search
@@ -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(<CheckinPage />);
|
||||
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(<CheckinPage />);
|
||||
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(<CheckinPage />);
|
||||
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("");
|
||||
});
|
||||
});
|
||||
@@ -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 = <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")} />;
|
||||
body = <RegistrationForm tooManyKey="InviteTooMany" info={open} initial={value.includes("@") ? { email: value.trim() } : { mobile: value.trim() }} submit={(b) => registerWalkIn(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />;
|
||||
} else {
|
||||
body = (
|
||||
<form onSubmit={lookup} className="space-y-4" noValidate>
|
||||
{error && <p role="alert" className="text-sm text-destructive">{error}</p>}
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="chk-value">{t("ChkLookup")}</Label>
|
||||
<Input id="chk-value" className="h-11" value={value} onChange={(e) => setValue(e.target.value)} disabled={busy} />
|
||||
<Input id="chk-value" className="h-11" value={value} onChange={(e) => setValue(e.target.value)} disabled={busy} aria-invalid={!!error} />
|
||||
</div>
|
||||
<Button type="submit" className="h-11 w-full" disabled={busy}>{t("InviteCheckin")}</Button>
|
||||
</form>
|
||||
|
||||
@@ -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(<EventForm onSubmit={vi.fn()} />);
|
||||
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());
|
||||
});
|
||||
});
|
||||
@@ -59,6 +59,9 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
|
||||
const [pickersError, setPickersError] = useState<string | null>(null);
|
||||
|
||||
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});
|
||||
// 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<string | null>(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) {
|
||||
<DatePicker
|
||||
id="evt-start"
|
||||
value={startDate}
|
||||
onChange={setStartDate}
|
||||
onChange={(v) => { setStartDate(v); clearError("startDate"); }}
|
||||
aria-label={t("EvtStartDate")}
|
||||
required
|
||||
disabled={saving}
|
||||
@@ -275,7 +279,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
|
||||
<DatePicker
|
||||
id="evt-end"
|
||||
value={endDate}
|
||||
onChange={setEndDate}
|
||||
onChange={(v) => { 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}
|
||||
/>
|
||||
|
||||
@@ -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(<GuestsCard eventUuid="u1" />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Send to all unsent" }));
|
||||
expect(await screen.findByRole("status")).toHaveTextContent("No unsent invitations");
|
||||
});
|
||||
});
|
||||
@@ -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"));
|
||||
|
||||
|
||||
@@ -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(<UserForm onSubmit={vi.fn()} />);
|
||||
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();
|
||||
});
|
||||
});
|
||||
@@ -68,6 +68,9 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF
|
||||
const [loadingPickers, setLoadingPickers] = useState(true);
|
||||
|
||||
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});
|
||||
// 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<string | null>(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 && (
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="user-company">{t("Company")}</Label>
|
||||
<Select value={company} onValueChange={(v) => setCompany(v)} disabled={saving}>
|
||||
<Select value={company} onValueChange={(v) => { setCompany(v); clearError("company"); }} disabled={saving}>
|
||||
<SelectTrigger id="user-company" aria-invalid={!!fieldErrors.company} className="w-full">
|
||||
<SelectValue placeholder={t("SelectCompany")} />
|
||||
</SelectTrigger>
|
||||
@@ -244,8 +247,8 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF
|
||||
<PasswordFields
|
||||
password={password}
|
||||
confirmPassword={confirmPassword}
|
||||
onPassword={setPassword}
|
||||
onConfirmPassword={setConfirmPassword}
|
||||
onPassword={(v) => { setPassword(v); clearError("password"); }}
|
||||
onConfirmPassword={(v) => { setConfirmPassword(v); clearError("confirmPassword"); }}
|
||||
disabled={saving}
|
||||
passwordError={fieldErrors.password}
|
||||
confirmError={fieldErrors.confirmPassword}
|
||||
|
||||
@@ -569,6 +569,7 @@ export const DEFAULT_MESSAGES: Record<string, string> = {
|
||||
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.",
|
||||
|
||||
@@ -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: [] });
|
||||
});
|
||||
});
|
||||
@@ -46,8 +46,11 @@ export interface Attendance {
|
||||
const base = (uuid: string) => `/api/events/${encodeURIComponent(uuid)}`;
|
||||
|
||||
export const listGuests = (uuid: string) => apiGet<EventGuest[]>(`${base(uuid)}/guests`);
|
||||
export const addGuests = (uuid: string, guests: GuestInput[], preview: boolean) =>
|
||||
apiPost<AddGuestsResult>(`${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<AddGuestsResult> => {
|
||||
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<unknown>(`${base(uuid)}/guests/${id}`);
|
||||
export const sendInvites = (uuid: string, target: { guestIds: number[] } | { allUnsent: true }) =>
|
||||
apiPost<{ sent: number; skippedNoEmail: number }>(`${base(uuid)}/guests/send`, target);
|
||||
|
||||
+2
@@ -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
|
||||
|
||||
+39
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user