Show Login and Ask an organizer sent and error states.

Connect the live modals to the drawn sent, expired, invalid-email, and send-failed screens, pin the phone footer above the keyboard, and send the light login email.
This commit is contained in:
adilallo committed 2026-11-11 16:55:09 -07:00
1 parent 44010c7b73
commit 27d74e510c
29 files changed
+771 -281

No files matched your search

@@ -0,0 +1,98 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import "@testing-library/jest-dom/vitest";
import { renderWithProviders } from "../utils/test-utils";
import AskOrganizerInquiryModal from "../../app/components/modals/AskOrganizerInquiry";
describe("AskOrganizerInquiryModal", () => {
const fetchMock = vi.fn();
beforeEach(() => {
fetchMock.mockReset();
vi.stubGlobal("fetch", fetchMock);
});
afterEach(() => {
vi.unstubAllGlobals();
});
it("opens as a phone sheet and sends the question into the sent state", async () => {
const user = userEvent.setup();
fetchMock.mockResolvedValue({
ok: true,
json: async () => ({ ok: true }),
});
renderWithProviders(
<AskOrganizerInquiryModal isOpen onClose={vi.fn()} />,
);
await waitFor(() => {
expect(screen.getByRole("dialog")).toHaveClass("h-full", "max-h-full");
});
expect(
screen.getByRole("heading", { name: "Ask an organizer" }),
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: /send question/i }),
).toBeInTheDocument();
await user.type(
screen.getByRole("textbox", { name: /email address/i }),
"rosa@example.org",
);
await user.type(
screen.getByRole("textbox", { name: /your question/i }),
"How do we decide who holds the keys to our shared accounts?",
);
await user.click(screen.getByRole("button", { name: /send question/i }));
expect(
await screen.findByRole("heading", { name: "Thanks" }),
).toBeInTheDocument();
expect(
screen.getByText(/one of us will write back within two working days/i),
).toBeInTheDocument();
expect(
screen.getAllByRole("button", { name: /^close$/i }).length,
).toBeGreaterThan(1);
});
it("keeps the question and shows the danger toast when send fails", async () => {
const user = userEvent.setup();
fetchMock.mockRejectedValue(new Error("network"));
renderWithProviders(
<AskOrganizerInquiryModal isOpen onClose={vi.fn()} />,
);
await user.type(
screen.getByRole("textbox", { name: /email address/i }),
"rosa@example.org",
);
await user.type(
screen.getByRole("textbox", { name: /your question/i }),
"How do we decide who holds the keys to our shared accounts?",
);
await user.click(screen.getByRole("button", { name: /send question/i }));
await waitFor(() => {
expect(
screen.getAllByText("We could not send that.").length,
).toBeGreaterThan(0);
});
expect(
screen.getAllByText(/your question is still here/i).length,
).toBeGreaterThan(0);
expect(
screen.getByRole("textbox", { name: /email address/i }),
).toHaveValue("rosa@example.org");
expect(
screen.getByRole("textbox", { name: /your question/i }),
).toHaveValue(
"How do we decide who holds the keys to our shared accounts?",
);
expect(
screen.getByRole("button", { name: /send question/i }),
).toBeInTheDocument();
});
});
+2 -4
View File
@@ -289,12 +289,10 @@ describe("Create", () => {
</Create>,
);
const closeButton = screen.getByLabelText("Close");
screen.getByLabelText("Test Input"); // Verify input is rendered
const input = screen.getByLabelText("Test Input");
// Focus should start on first focusable element (close button)
await waitFor(() => {
expect(closeButton).toHaveFocus();
expect(input).toHaveFocus();
});
// Tab should move focus to next element
+2 -2
View File
@@ -156,8 +156,8 @@ describe("Login", () => {
expect(screen.getByRole("dialog")).toBeInTheDocument();
});
expect(
screen.getByRole("link", { name: /back to home/i }),
).toBeInTheDocument();
screen.getAllByRole("link", { name: /back to home/i }).length,
).toBeGreaterThan(0);
});
it("does not render a more-options kebab", async () => {
+51 -16
View File
@@ -73,7 +73,7 @@ describe("LoginForm", () => {
screen.getByRole("textbox", { name: /email address/i }),
).toHaveAttribute("maxLength", String(EMAIL_MAX_LEN));
expect(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
).toBeInTheDocument();
});
@@ -95,10 +95,10 @@ describe("LoginForm", () => {
"not-an-email",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
expect(
await screen.findByText(/enter a valid email address/i),
await screen.findByText(/enter an email address like name@example.org/i),
).toBeInTheDocument();
expect(requestMagicLink).not.toHaveBeenCalled();
});
@@ -112,7 +112,7 @@ describe("LoginForm", () => {
" Pat@Example.COM ",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -124,8 +124,14 @@ describe("LoginForm", () => {
expect(
await screen.findByRole("heading", { name: /check your email/i }),
).toBeInTheDocument();
expect(screen.getByText(/we sent a login link/i)).toBeInTheDocument();
expect(screen.getByText(/check spam or promotions/i)).toBeInTheDocument();
expect(
screen.getByText(/we sent a login link to pat@example.com/i),
).toBeInTheDocument();
expect(screen.getByText(/it works for 60 minutes/i)).toBeInTheDocument();
expect(screen.getByRole("button", { name: /^close$/i })).toBeInTheDocument();
expect(
screen.getByRole("button", { name: /send it again/i }),
).toBeInTheDocument();
});
it("submits a long email without treating length as invalid", async () => {
@@ -139,7 +145,7 @@ describe("LoginForm", () => {
email,
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(email, "/", undefined);
@@ -162,7 +168,7 @@ describe("LoginForm", () => {
"save@example.com",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -199,7 +205,7 @@ describe("LoginForm", () => {
"guest@example.com",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -237,7 +243,7 @@ describe("LoginForm", () => {
"guest@example.com",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -286,7 +292,7 @@ describe("LoginForm", () => {
"a@b.co",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -309,7 +315,7 @@ describe("LoginForm", () => {
"ok@example.com",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
expect(await screen.findByText("Server says no")).toBeInTheDocument();
});
@@ -327,7 +333,7 @@ describe("LoginForm", () => {
"ok@example.com",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
expect(
await screen.findByText(/try again in 4 seconds/i),
@@ -338,7 +344,13 @@ describe("LoginForm", () => {
navMock.searchParams = new URLSearchParams("error=expired_link");
renderLoginForm();
expect(
screen.getByText(/that login link has expired/i),
screen.getByRole("heading", { name: /that link has expired/i }),
).toBeInTheDocument();
expect(
screen.getByText(/expired or was already used/i),
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: /send a new link/i }),
).toBeInTheDocument();
});
@@ -346,7 +358,10 @@ describe("LoginForm", () => {
navMock.searchParams = new URLSearchParams("error=invalid_link");
renderLoginForm();
expect(
screen.getByText(/that login link is not valid/i),
screen.getByRole("heading", { name: /that link has expired/i }),
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: /send a new link/i }),
).toBeInTheDocument();
});
@@ -383,10 +398,30 @@ describe("LoginForm", () => {
"ok@example.com",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
expect(
await screen.findByText(/check your connection/i),
).toBeInTheDocument();
});
it("send it again requests another link from the sent state", async () => {
const user = userEvent.setup();
vi.mocked(requestMagicLink).mockResolvedValue({ ok: true });
renderLoginForm();
await user.type(
screen.getByRole("textbox", { name: /email address/i }),
"pat@example.com",
);
await user.click(
screen.getByRole("button", { name: /send login link/i }),
);
expect(
await screen.findByRole("button", { name: /send it again/i }),
).toBeInTheDocument();
await user.click(screen.getByRole("button", { name: /send it again/i }));
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledTimes(2);
});
});
});
+5 -5
View File
@@ -177,7 +177,7 @@ describe("AuthModalProvider (header overlay)", () => {
"guest@example.com",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -211,7 +211,7 @@ describe("AuthModalProvider (header overlay)", () => {
"guest@example.com",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -285,14 +285,14 @@ describe("AuthModalProvider (header overlay)", () => {
screen.getByRole("heading", { name: /log in to invite your members/i }),
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: /back to your rule/i }),
).toBeInTheDocument();
screen.getAllByRole("button", { name: /back to your rule/i }).length,
).toBeGreaterThan(0);
await user.type(
screen.getByRole("textbox", { name: /email address/i }),
"guest@example.com",
);
await user.click(
screen.getByRole("button", { name: /send me a magic link/i }),
screen.getByRole("button", { name: /send login link/i }),
);
await waitFor(() => {
expect(requestMagicLink).toHaveBeenCalledWith(
@@ -111,6 +111,7 @@ describe("POST /api/auth/magic-link/request", () => {
expect(sendMagicLinkEmailMock).toHaveBeenCalledWith(
"member@example.com",
expect.stringContaining("/api/auth/magic-link/verify?token="),
"https://x.test",
);
});
@@ -130,6 +131,7 @@ describe("POST /api/auth/magic-link/request", () => {
expect(sendMagicLinkEmailMock).toHaveBeenCalledWith(
email,
expect.stringContaining("/api/auth/magic-link/verify?token="),
"https://x.test",
);
});
+35
View File
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";
import { MAGIC_LINK_TTL_MINUTES } from "../../lib/privacyRetention";
import { buildMagicLinkMail } from "../../lib/server/magicLinkMail";
const VERIFY_URL =
"https://communityrule.info/api/auth/magic-link/verify?token=abc";
describe("buildMagicLinkMail", () => {
const mail = buildMagicLinkMail({
verifyUrl: VERIFY_URL,
origin: "https://communityrule.info",
});
it("uses the drawn subject, once-and-minutes line, and log in button", () => {
expect(mail.subject).toBe("Your login link for CommunityRule");
expect(mail.previewText).toBe(
`It works once, for ${MAGIC_LINK_TTL_MINUTES} minutes.`,
);
expect(mail.text).toContain("Log in to CommunityRule");
expect(mail.text).toContain(VERIFY_URL);
expect(mail.text).toContain(
`It works once, for ${MAGIC_LINK_TTL_MINUTES} minutes.`,
);
expect(mail.html).toContain("background:#000000");
expect(mail.html).toContain(">Log in</a>");
expect(mail.html).toContain(`href="${VERIFY_URL}"`);
expect(mail.html).toContain("/privacy");
expect(mail.html).toContain("/about");
});
it("does not invent a first name", () => {
expect(mail.html).not.toContain("Hi ");
expect(mail.text).not.toContain("Hi ");
});
});
+3 -3
View File
@@ -4,8 +4,8 @@ import { MAGIC_LINK_TTL_MINUTES } from "../../lib/privacyRetention";
describe("privacy retention copy", () => {
it("states the login link lifetime in the sent state", () => {
expect(login.successBody).toContain(
`works for ${MAGIC_LINK_TTL_MINUTES} minutes`,
);
expect(
login.sentBody.replace("{minutes}", String(MAGIC_LINK_TTL_MINUTES)),
).toContain(`works for ${MAGIC_LINK_TTL_MINUTES} minutes`);
});
});