Show our own save-email error, and open review cards as the deck row view.
A bad address was stopped by the browser bubble before the designed line could appear. Final review opened every part of a method card at once instead of the three-row policy the decks use.
This commit is contained in:
1 parent
0efc907633
commit
7336cba6f5
13 files changed
+274
-685
No files matched your search
@@ -59,7 +59,7 @@ function ScreenWithStateProbe({
|
||||
/**
|
||||
* Confirms the persistence half of the Add-Platform flow that lets the
|
||||
* final-review chip edit modal start from a known seed instead of always
|
||||
* snapping back to preset copy. See {@link CommunicationMethodEditFields}
|
||||
* snapping back to preset copy. See {@link MethodCardPolicyDialog}
|
||||
* and `buildPublishPayload` for the read side.
|
||||
*/
|
||||
const COMMUNICATION_STEPS = [
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { fireEvent } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import CreateFlowLayoutClient from "../../app/(app)/create/CreateFlowLayoutClient";
|
||||
import { CreateFlowTextFieldScreen } from "../../app/(app)/create/screens/text/CreateFlowTextFieldScreen";
|
||||
import { CREATE_FLOW_COMMUNITY_SAVE_FORM_ID } from "../../app/(app)/create/utils/createFlowPaths";
|
||||
import {
|
||||
cleanup,
|
||||
renderWithProviders as render,
|
||||
screen,
|
||||
waitFor,
|
||||
} from "../utils/test-utils";
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
back: vi.fn(),
|
||||
}),
|
||||
usePathname: () => "/create/community-save",
|
||||
useSearchParams: () => new URLSearchParams(),
|
||||
}));
|
||||
|
||||
const errorCopy = "Check your email address. We need it to send your link.";
|
||||
|
||||
function renderSaveStep() {
|
||||
return render(
|
||||
<CreateFlowLayoutClient>
|
||||
<CreateFlowTextFieldScreen
|
||||
messageNamespace="create.community.communitySave"
|
||||
stateField="communitySaveEmail"
|
||||
maxLength={254}
|
||||
inputType="email"
|
||||
showCharacterCount={false}
|
||||
/>
|
||||
</CreateFlowLayoutClient>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("community-save email", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("shows the designed error for an address the browser would reject", async () => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(async () =>
|
||||
new Response(JSON.stringify({ user: null }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}),
|
||||
),
|
||||
);
|
||||
renderSaveStep();
|
||||
|
||||
const form = await waitFor(() => {
|
||||
const node = document.getElementById(CREATE_FLOW_COMMUNITY_SAVE_FORM_ID);
|
||||
expect(node).not.toBeNull();
|
||||
return node as HTMLFormElement;
|
||||
});
|
||||
expect(form).toHaveAttribute("novalidate");
|
||||
|
||||
const input = screen.getByRole("textbox", { name: "Email address" });
|
||||
fireEvent.change(input, { target: { value: "not-an-email" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Submit email" }));
|
||||
|
||||
expect(await screen.findByText(errorCopy)).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Submit email" })).toHaveAttribute(
|
||||
"formnovalidate",
|
||||
);
|
||||
});
|
||||
|
||||
it("shows the same error for an address with no dot in the domain", async () => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(async () =>
|
||||
new Response(JSON.stringify({ user: null }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}),
|
||||
),
|
||||
);
|
||||
renderSaveStep();
|
||||
const input = await screen.findByRole("textbox", { name: "Email address" });
|
||||
fireEvent.change(input, { target: { value: "maya@example" } });
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Submit email" }));
|
||||
expect(await screen.findByText(errorCopy)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -19,6 +19,10 @@ function catalogChipName(label: string) {
|
||||
);
|
||||
}
|
||||
|
||||
function openMethodStep(dialog: HTMLElement, name: string) {
|
||||
fireEvent.click(within(dialog).getByRole("button", { name }));
|
||||
}
|
||||
|
||||
async function confirmDiscardCustomizeEdits() {
|
||||
fireEvent.click(
|
||||
await screen.findByRole("button", { name: "Discard" }),
|
||||
@@ -312,12 +316,18 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
await screen.findByRole("button", { name: catalogChipName("Video meetings") }),
|
||||
);
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
expect(within(dialog).getAllByRole("textbox")).toHaveLength(3);
|
||||
expect(within(dialog).queryAllByRole("textbox")).toHaveLength(0);
|
||||
expect(
|
||||
within(dialog).queryByText("No custom fields yet."),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
within(dialog).getByText(/core principle/i),
|
||||
within(dialog).getByRole("button", { name: "Core principle and scope" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "How it works" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "Norms" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -571,26 +581,33 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
expect(screen.getByPlaceholderText("Policy description")).toHaveValue("");
|
||||
});
|
||||
|
||||
it("opens method chip modal editable, with Save disabled until a field changes", async () => {
|
||||
it("opens a method chip as the deck's routing card, with Save off until a part changes", async () => {
|
||||
render(<FinalReviewWithCustomizeSelections />);
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
|
||||
const saveButton = within(dialog).getByRole("button", { name: "Save" });
|
||||
expect(saveButton).toBeDisabled();
|
||||
expect(within(dialog).queryAllByRole("textbox")).toHaveLength(0);
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "Core principle and scope" }),
|
||||
).toBeInTheDocument();
|
||||
expect(within(dialog).getByRole("button", { name: "Save" })).toBeDisabled();
|
||||
|
||||
openMethodStep(dialog, "Core principle and scope");
|
||||
const principleField = within(dialog).getByRole("textbox", {
|
||||
name: /core principle/i,
|
||||
});
|
||||
expect(principleField).not.toBeDisabled();
|
||||
expect(principleField).toHaveValue("");
|
||||
|
||||
fireEvent.change(principleField, { target: { value: "Edited principle" } });
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "Save" }),
|
||||
).not.toBeDisabled();
|
||||
within(dialog).getByRole("button", { name: "Core principle and scope" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
expect(within(dialog).getByRole("button", { name: "Save" })).toBeEnabled();
|
||||
});
|
||||
|
||||
it("opens a core-values chip with the matching preset meaning/signals", async () => {
|
||||
@@ -792,9 +809,10 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const methodDialog = await screen.findByRole("dialog");
|
||||
expect(within(methodDialog).getAllByRole("textbox").length).toBeGreaterThan(
|
||||
0,
|
||||
);
|
||||
expect(
|
||||
within(methodDialog).getByRole("button", { name: "Core principle and scope" }),
|
||||
).toBeInTheDocument();
|
||||
expect(within(methodDialog).queryAllByRole("textbox")).toHaveLength(0);
|
||||
fireEvent.keyDown(document, { key: "Escape" });
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
@@ -818,7 +836,7 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "Remove" }),
|
||||
within(dialog).getByRole("button", { name: "Deselect" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
within(dialog).queryByRole("button", { name: "Back" }),
|
||||
@@ -845,7 +863,7 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Remove" }));
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Deselect" }));
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -855,13 +873,10 @@ describe("FinalReviewScreen — chip detail modal", () => {
|
||||
});
|
||||
|
||||
/**
|
||||
* Save semantics for {@link FinalReviewChipEditModal}. Mirrors the
|
||||
* "edits ride along to publish" promise documented in the modal:
|
||||
*
|
||||
* 1. Save starts disabled (no edits yet → nothing to persist).
|
||||
* 2. Editing any field flips Save on; clicking it writes the typed
|
||||
* `{group}MethodDetailsById[id]` entry into create-flow state.
|
||||
* 3. Closing without Save discards every typed change.
|
||||
* Save semantics for {@link FinalReviewChipEditModal}. A method chip opens
|
||||
* the deck routing card. Save on a part returns to the rows. Save on the
|
||||
* card writes `{group}MethodDetailsById[id]`. Closing without that card
|
||||
* Save discards the typed change.
|
||||
*/
|
||||
describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||
const baseSelections: CreateFlowState = {
|
||||
@@ -883,20 +898,18 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
const saveButton = within(dialog).getByRole("button", { name: "Save" });
|
||||
expect(saveButton).toBeDisabled();
|
||||
const principleField = within(dialog).getByRole("textbox", {
|
||||
name: /core principle/i,
|
||||
});
|
||||
|
||||
fireEvent.change(principleField, {
|
||||
target: { value: "Edited principle" },
|
||||
});
|
||||
expect(within(dialog).getByRole("button", { name: "Save" })).toBeDisabled();
|
||||
openMethodStep(dialog, "Core principle and scope");
|
||||
fireEvent.change(
|
||||
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||
{ target: { value: "Edited principle" } },
|
||||
);
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
within(dialog).getByRole("button", { name: "Save" }),
|
||||
).not.toBeDisabled();
|
||||
).toBeEnabled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -913,12 +926,13 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
const principleField = within(dialog).getByRole("textbox", {
|
||||
name: /core principle/i,
|
||||
});
|
||||
fireEvent.change(principleField, {
|
||||
target: { value: "Edited principle" },
|
||||
});
|
||||
openMethodStep(dialog, "Core principle and scope");
|
||||
fireEvent.change(
|
||||
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||
{ target: { value: "Edited principle" } },
|
||||
);
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
expect(latest.communicationMethodDetailsById?.signal?.corePrinciple).toBeUndefined();
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Save" }));
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -941,13 +955,14 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
const principleField = within(dialog).getByRole("textbox", {
|
||||
name: /core principle/i,
|
||||
});
|
||||
fireEvent.change(principleField, {
|
||||
target: { value: "Should NOT persist" },
|
||||
});
|
||||
openMethodStep(dialog, "Core principle and scope");
|
||||
fireEvent.change(
|
||||
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||
{ target: { value: "Should NOT persist" } },
|
||||
);
|
||||
|
||||
fireEvent.keyDown(document, { key: "Escape" });
|
||||
expect(screen.getByRole("dialog")).toBeInTheDocument();
|
||||
fireEvent.keyDown(document, { key: "Escape" });
|
||||
await confirmDiscardCustomizeEdits();
|
||||
await waitFor(() => {
|
||||
@@ -970,12 +985,11 @@ describe("FinalReviewScreen — chip edit modal save semantics", () => {
|
||||
fireEvent.click(await screen.findByRole("button", { name: catalogChipName("Signal") }));
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
expect(dispatchBeforeUnload()).toBe(false);
|
||||
const principleField = within(dialog).getByRole("textbox", {
|
||||
name: /core principle/i,
|
||||
});
|
||||
fireEvent.change(principleField, {
|
||||
target: { value: "Unsaved on tab close" },
|
||||
});
|
||||
openMethodStep(dialog, "Core principle and scope");
|
||||
fireEvent.change(
|
||||
within(dialog).getByRole("textbox", { name: /core principle/i }),
|
||||
{ target: { value: "Unsaved on tab close" } },
|
||||
);
|
||||
expect(dispatchBeforeUnload()).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user