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:
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();
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user