Files
community-rule/tests/components/AskOrganizerInquiry.test.tsx
T
adilallo 27d74e510c 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.
2026-11-11 16:55:09 -07:00

99 lines
3.1 KiB
TypeScript

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();
});
});