Rebuild Share and Delete Account from the privacy designs.

Share asks the person who holds the pen to confirm their community agreed before a link turns on, and deleting an account lists each owned Rule with PDF and RULE.md export. Case-study Share copies the page link instead of opening the privacy modal, and the sign-in banner stays below the header so Share remains clickable.
This commit is contained in:
adilallo committed 2026-11-09 19:54:09 -07:00
1 parent 5cbda35e32
commit b6795c1f18
28 files changed
+1467 -377

No files matched your search

@@ -0,0 +1,53 @@
import { describe, it, expect, vi } from "vitest";
import userEvent from "@testing-library/user-event";
import { renderWithProviders as render, screen } from "../../utils/test-utils";
import "@testing-library/jest-dom/vitest";
import DeleteAccount from "../../../app/components/modals/DeleteAccount";
describe("DeleteAccount modal", () => {
it("does not render dialog when closed", () => {
render(
<DeleteAccount
isOpen={false}
onClose={vi.fn()}
onConfirm={vi.fn()}
rules={[]}
onExportPdf={vi.fn()}
onExportMarkdown={vi.fn()}
/>,
);
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
it("keeps Delete account disabled until the box is ticked", async () => {
const user = userEvent.setup();
const onConfirm = vi.fn();
const onExportPdf = vi.fn();
render(
<DeleteAccount
isOpen
onClose={vi.fn()}
onConfirm={onConfirm}
rules={[{ id: "rule-1", title: "Juniper Street Food Share" }]}
onExportPdf={onExportPdf}
onExportMarkdown={vi.fn()}
/>,
);
expect(
screen.getByRole("heading", { level: 1, name: "Delete your account" }),
).toBeInTheDocument();
expect(screen.getByText("Juniper Street Food Share")).toBeInTheDocument();
const confirm = screen.getByRole("button", { name: "Delete account" });
expect(confirm).toBeDisabled();
await user.click(screen.getByRole("button", { name: "PDF" }));
expect(onExportPdf).toHaveBeenCalledWith("rule-1");
await user.click(
screen.getByRole("checkbox", {
name: "I understand this can’t be undone",
}),
);
expect(confirm).toBeEnabled();
await user.click(confirm);
expect(onConfirm).toHaveBeenCalledTimes(1);
});
});
+121 -89
View File
@@ -1,117 +1,149 @@
import { describe, it, expect, vi } from "vitest";
import { describe, it, expect, vi, beforeEach } from "vitest";
import userEvent from "@testing-library/user-event";
import { renderWithProviders as render, screen } from "../../utils/test-utils";
import { fireEvent } from "@testing-library/react";
import {
renderWithProviders as render,
screen,
waitFor,
} from "../../utils/test-utils";
import "@testing-library/jest-dom/vitest";
import Share from "../../../app/components/modals/Share";
import type { RuleShareSettings } from "../../../lib/ruleShareTypes";
const noopHandlers = {
onCopyLink: vi.fn(),
onEmailShare: vi.fn(),
onSignalShare: vi.fn(),
onSlackShare: vi.fn(),
onDiscordShare: vi.fn(),
const previewSettings: RuleShareSettings = {
visibility: "private",
shareSlug: null,
shareUrl: "https://communityrule.info/rules/rule-1",
shareUrlDisplay: null,
title: "Juniper Street Food Share",
ownerEmail: "name@example.org",
ownerInitials: "N",
readers: [
{ email: "rosa@example.org", initials: "R", role: "reader" },
{ email: "a@example.org", initials: "A", role: "reader" },
{ email: "b@example.org", initials: "B", role: "reader" },
{ email: "c@example.org", initials: "C", role: "reader" },
{ email: "d@example.org", initials: "D", role: "reader" },
{ email: "e@example.org", initials: "E", role: "reader" },
],
copyEnabled: true,
};
function openShare(overrides: Partial<RuleShareSettings> = {}) {
return render(
<Share
isOpen
onClose={vi.fn()}
previewSettings={{ ...previewSettings, ...overrides }}
/>,
);
}
const writeText = vi.fn().mockResolvedValue(undefined);
beforeEach(() => {
writeText.mockReset();
writeText.mockResolvedValue(undefined);
Object.defineProperty(window.navigator, "clipboard", {
configurable: true,
value: { writeText },
});
});
describe("Share modal", () => {
it("does not render dialog when closed", () => {
render(
<Share isOpen={false} onClose={vi.fn()} {...noopHandlers} />,
<Share
isOpen={false}
onClose={vi.fn()}
previewSettings={previewSettings}
/>,
);
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
it("renders localized heading and copy link action when open", async () => {
const user = userEvent.setup();
const onCopyLink = vi.fn();
render(
<Share
isOpen={true}
onClose={vi.fn()}
{...noopHandlers}
onCopyLink={onCopyLink}
/>,
);
it("renders invite-only copy and people with access", () => {
openShare();
expect(screen.getByRole("dialog")).toBeInTheDocument();
expect(
screen.getByRole("heading", { level: 1, name: /Share this CommunityRule/ }),
screen.getByRole("heading", { level: 1, name: "Share this Rule" }),
).toBeInTheDocument();
await user.click(screen.getByRole("button", { name: "Copy link" }));
expect(onCopyLink).toHaveBeenCalledTimes(1);
expect(screen.getByText("Juniper Street Food Share")).toBeInTheDocument();
expect(screen.getByText("You")).toBeInTheDocument();
expect(screen.getByText("rosa@example.org")).toBeInTheDocument();
expect(screen.getByText("Five more people can read it")).toBeInTheDocument();
expect(screen.getByText("Only people you invite can open it.")).toBeInTheDocument();
});
it("invokes channel handlers for Signal, Slack, and Discord", async () => {
const user = userEvent.setup();
const onSignalShare = vi.fn();
const onSlackShare = vi.fn();
const onDiscordShare = vi.fn();
render(
<Share
isOpen={true}
onClose={vi.fn()}
{...noopHandlers}
onSignalShare={onSignalShare}
onSlackShare={onSlackShare}
onDiscordShare={onDiscordShare}
/>,
it("copies the private Rule URL", async () => {
openShare();
fireEvent.click(screen.getByRole("button", { name: /Copy link/i }));
await waitFor(() => {
expect(screen.getByText("Link copied")).toBeInTheDocument();
});
expect(writeText).toHaveBeenCalledWith(
"https://communityrule.info/rules/rule-1",
);
await user.click(screen.getByRole("button", { name: "Signal" }));
await user.click(screen.getByRole("button", { name: "Slack" }));
await user.click(screen.getByRole("button", { name: "Discord" }));
expect(onSignalShare).toHaveBeenCalledTimes(1);
expect(onSlackShare).toHaveBeenCalledTimes(1);
expect(onDiscordShare).toHaveBeenCalledTimes(1);
expect(screen.getByRole("button", { name: /Copied/i })).toHaveAttribute(
"aria-pressed",
"true",
);
});
it("asks for community agreement before turning a link on", async () => {
const user = userEvent.setup();
openShare();
await user.click(screen.getByRole("button", { name: /Only people you invite/i }));
await user.click(
await screen.findByRole("option", { name: "Anyone with the link" }),
);
expect(
screen.getByText(
"Anyone with the link can read it without logging in and pass it on. Check with your community first.",
),
).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Turn on link" })).toBeDisabled();
expect(screen.getByRole("button", { name: /Copy link/i })).toBeDisabled();
await user.click(
screen.getByRole("checkbox", {
name: "Our community agreed to share this Rule",
}),
);
expect(screen.getByRole("button", { name: "Turn on link" })).toBeEnabled();
});
it("turns the preview link on after community agreement", async () => {
const user = userEvent.setup();
openShare();
await user.click(screen.getByRole("button", { name: /Only people you invite/i }));
await user.click(
await screen.findByRole("option", { name: "Anyone with the link" }),
);
await user.click(
screen.getByRole("checkbox", {
name: "Our community agreed to share this Rule",
}),
);
await user.click(screen.getByRole("button", { name: "Turn on link" }));
expect(
screen.getByDisplayValue("communityrule.info/r/k7f2-9qxm"),
).toBeInTheDocument();
expect(
screen.getByRole("button", { name: "Turn off link" }),
).toBeInTheDocument();
});
it("calls onClose when Done is clicked", async () => {
const user = userEvent.setup();
const onClose = vi.fn();
render(<Share isOpen={true} onClose={onClose} {...noopHandlers} />);
render(
<Share
isOpen
onClose={onClose}
previewSettings={previewSettings}
/>,
);
await user.click(screen.getByRole("button", { name: "Done" }));
expect(onClose).toHaveBeenCalledTimes(1);
});
it("confirms Copy link with Copied! when the handler succeeds", async () => {
const user = userEvent.setup();
const onCopyLink = vi.fn().mockResolvedValue(true);
render(
<Share
isOpen={true}
onClose={vi.fn()}
{...noopHandlers}
onCopyLink={onCopyLink}
/>,
);
await user.click(screen.getByRole("button", { name: "Copy link" }));
expect(onCopyLink).toHaveBeenCalledTimes(1);
expect(screen.getByRole("button", { name: "Copied!" })).toHaveAttribute(
"aria-pressed",
"true",
);
expect(screen.getByText("Link copied to clipboard")).toBeInTheDocument();
});
it("keeps Copy link when the handler reports failure", async () => {
const user = userEvent.setup();
render(
<Share
isOpen={true}
onClose={vi.fn()}
{...noopHandlers}
onCopyLink={vi.fn().mockResolvedValue(false)}
/>,
);
await user.click(screen.getByRole("button", { name: "Copy link" }));
expect(screen.getByRole("button", { name: "Copy link" })).toBeInTheDocument();
expect(
screen.queryByRole("button", { name: "Copied!" }),
).not.toBeInTheDocument();
});
it("calls onClose when header overflow (more) is activated, matching modal chrome parity", async () => {
const user = userEvent.setup();
const onClose = vi.fn();
render(<Share isOpen={true} onClose={onClose} {...noopHandlers} />);
await user.click(screen.getByRole("button", { name: "More share options" }));
expect(onClose).toHaveBeenCalledTimes(1);
});
});
+12 -3
View File
@@ -61,6 +61,8 @@ function viewProps(
onOpenDeleteAccount: vi.fn(),
onCloseDeleteAccount: vi.fn(),
onConfirmDeleteAccount: vi.fn(),
onExportRulePdf: vi.fn(),
onExportRuleMarkdown: vi.fn(),
onDismissProfileSuccess: vi.fn(),
onDismissActionError: vi.fn(),
onDismissRulesError: vi.fn(),
@@ -127,12 +129,13 @@ describe("ProfilePageView", () => {
);
const dialog = screen.getByRole("dialog", {
name: copy.deleteAccountModalTitle,
name: messages.modals.deleteAccount.title,
});
expect(dialog).toHaveTextContent(copy.deleteAccountModalBody);
expect(dialog).toHaveTextContent(messages.modals.deleteAccount.description);
const confirm = within(dialog).getByRole("button", {
name: copy.deleteAccountConfirm,
name: messages.modals.deleteAccount.confirm,
});
expect(confirm).toBeDisabled();
expect(confirm.className).toContain(
"border-[var(--color-border-default-negative-primary)]",
);
@@ -140,6 +143,12 @@ describe("ProfilePageView", () => {
"bg-[var(--color-surface-invert-primary)]",
);
await user.click(
within(dialog).getByRole("checkbox", {
name: messages.modals.deleteAccount.confirmLabel,
}),
);
expect(confirm).toBeEnabled();
await user.click(confirm);
expect(onConfirmDeleteAccount).toHaveBeenCalledTimes(1);
});
@@ -118,6 +118,27 @@ describe("UseCaseCompletedRulePage", () => {
);
});
test("Share copies the page link through a banner instead of a privacy modal", async () => {
const user = userEvent.setup();
const writeText = vi.fn().mockResolvedValue(undefined);
Object.defineProperty(window.navigator, "clipboard", {
configurable: true,
value: { writeText },
});
render(
await UseCaseCompletedRulePage({
params: Promise.resolve({ slug: "food-not-bombs" }),
}),
);
await user.click(screen.getByRole("button", { name: "Share" }));
expect(writeText).toHaveBeenCalled();
expect(screen.getByText("Link copied")).toBeInTheDocument();
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
test("Share button reads Share under the marketing case-study bundle", async () => {
rtlRender(
<MessagesProvider messages={marketingMessages}>
+1 -1
View File
@@ -31,7 +31,7 @@ describe("createFlowLayoutTokens", () => {
expect(CREATE_FLOW_PAGE_GUTTER_CLASS).toBe("px-5 md:px-12 lg:px-16");
});
it("offsets fixed top banners below the create-flow header", () => {
it("offsets fixed top banners below the create-flow header so Share stays clickable", () => {
expect(CREATE_FLOW_FIXED_TOP_BANNER_OFFSET_CLASS).toBe("top-14 md:top-16");
});