Pin phone sheets to the visible viewport, and let people correct login and organizer errors.
This commit is contained in:
1 parent
27d74e510c
commit
39807ef452
17 files changed
+236
-16
No files matched your search
@@ -95,4 +95,53 @@ describe("AskOrganizerInquiryModal", () => {
|
||||
screen.getByRole("button", { name: /send question/i }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows field hints for an invalid email and a short question, then clears them on edit", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithProviders(
|
||||
<AskOrganizerInquiryModal isOpen onClose={vi.fn()} />,
|
||||
);
|
||||
|
||||
await user.type(
|
||||
screen.getByRole("textbox", { name: /email address/i }),
|
||||
"not-an-email",
|
||||
);
|
||||
await user.type(
|
||||
screen.getByRole("textbox", { name: /your question/i }),
|
||||
"Too short",
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: /send question/i }));
|
||||
|
||||
expect(
|
||||
await screen.findByText("Enter an email address like name@example.org."),
|
||||
).toBeInTheDocument();
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
|
||||
await user.type(
|
||||
screen.getByRole("textbox", { name: /email address/i }),
|
||||
"@example.org",
|
||||
);
|
||||
expect(
|
||||
screen.queryByText("Enter an email address like name@example.org."),
|
||||
).not.toBeInTheDocument();
|
||||
|
||||
await user.clear(screen.getByRole("textbox", { name: /email address/i }));
|
||||
await user.type(
|
||||
screen.getByRole("textbox", { name: /email address/i }),
|
||||
"rosa@example.org",
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: /send question/i }));
|
||||
|
||||
expect(
|
||||
await screen.findByText("Please enter at least 10 characters."),
|
||||
).toBeInTheDocument();
|
||||
|
||||
await user.type(
|
||||
screen.getByRole("textbox", { name: /your question/i }),
|
||||
" more",
|
||||
);
|
||||
expect(
|
||||
screen.queryByText("Please enter at least 10 characters."),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,14 +1,23 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import { screen, fireEvent, waitFor } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import { renderWithProviders } from "../utils/test-utils";
|
||||
import Login from "../../app/components/modals/Login";
|
||||
|
||||
describe("Login", () => {
|
||||
const originalViewport = window.visualViewport;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(window, "visualViewport", {
|
||||
configurable: true,
|
||||
value: originalViewport,
|
||||
});
|
||||
});
|
||||
|
||||
it("uses blurredYellow backdrop by default (header overlay)", async () => {
|
||||
renderWithProviders(
|
||||
<Login isOpen onClose={vi.fn()} ariaLabelledBy="login-modal-heading">
|
||||
@@ -172,4 +181,30 @@ describe("Login", () => {
|
||||
expect(screen.getByLabelText("Close")).toBeInTheDocument();
|
||||
expect(screen.queryByLabelText("More options")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("pins the overlay to the visual viewport offset", async () => {
|
||||
Object.defineProperty(window, "visualViewport", {
|
||||
configurable: true,
|
||||
value: {
|
||||
height: 500,
|
||||
offsetTop: 80,
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
},
|
||||
});
|
||||
renderWithProviders(
|
||||
<Login isOpen onClose={vi.fn()} ariaLabelledBy="login-modal-heading">
|
||||
<p id="login-modal-heading">Login content</p>
|
||||
</Login>,
|
||||
);
|
||||
const backdrop = await waitFor(() => {
|
||||
const dialog = screen.getByRole("dialog");
|
||||
expect(dialog.parentElement).toHaveStyle({
|
||||
top: "80px",
|
||||
height: "500px",
|
||||
});
|
||||
return dialog.parentElement;
|
||||
});
|
||||
expect(backdrop).toHaveStyle({ bottom: "auto" });
|
||||
});
|
||||
});
|
||||
@@ -424,4 +424,29 @@ describe("LoginForm", () => {
|
||||
expect(requestMagicLink).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
it("shows the email field again when send it again fails", async () => {
|
||||
const user = userEvent.setup();
|
||||
vi.mocked(requestMagicLink)
|
||||
.mockResolvedValueOnce({ ok: true })
|
||||
.mockRejectedValueOnce(new Error("network"));
|
||||
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 }),
|
||||
);
|
||||
await user.click(
|
||||
await screen.findByRole("button", { name: /send it again/i }),
|
||||
);
|
||||
|
||||
expect(
|
||||
await screen.findByRole("textbox", { name: /email address/i }),
|
||||
).toHaveValue("pat@example.com");
|
||||
expect(
|
||||
screen.getByText(/check your connection/i),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user