Show Share initials, a readable link, and a copy confirmation.

Filled avatars used white ink on yellow, the link field was a dimmed disabled input, and Copy failed silently when the clipboard API was denied.
This commit is contained in:
adilallo committed 2026-11-21 11:42:49 -07:00
1 parent 3a264ac2df
commit 0fe2624002
11 files changed
+132 -14

No files matched your search

+9
View File
@@ -117,6 +117,15 @@ describe("Avatar (behavioral tests)", () => {
);
});
it("paints filled initials in invert ink on the yellow field", () => {
render(
<Avatar alt="Ada Lovelace" initials="N" variant="filled" />,
);
expect(screen.getByText("N")).toHaveClass(
"text-[var(--color-content-invert-primary)]",
);
});
it("renders a button with hover treatment when onClick is set", () => {
const onClick = vi.fn();
render(
+15
View File
@@ -81,4 +81,19 @@ describe("TextInput (size tests)", () => {
expect(input).toBeRequired();
expect(input).toHaveAttribute("form", "create-flow-community-save");
});
it("keeps read-only values at full contrast", () => {
const { container } = render(
<TextInput
label="Share link"
value="communityrule.info/r/k7f2-9qxm"
readOnly
/>,
);
const input = container.querySelector("input");
expect(input).toHaveAttribute("readonly");
expect(input).not.toBeDisabled();
expect(input).toHaveClass("text-[var(--color-content-default-primary)]");
expect(container.querySelector(".opacity-40")).not.toBeInTheDocument();
});
});
+24 -3
View File
@@ -86,11 +86,30 @@ describe("Share modal", () => {
).toBeInTheDocument();
expect(screen.getByText("Juniper Street Food Share")).toBeInTheDocument();
expect(screen.getByText("You")).toBeInTheDocument();
expect(screen.getByText("N")).toBeInTheDocument();
expect(screen.getByText("R")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Invite" })).toBeEnabled();
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("confirms a copy when the clipboard API is denied", async () => {
writeText.mockRejectedValueOnce(new Error("denied"));
const exec = vi.fn().mockReturnValue(true);
Object.defineProperty(document, "execCommand", {
configurable: true,
value: exec,
});
openShare();
fireEvent.click(screen.getByRole("button", { name: /Copy link/i }));
await waitFor(() => {
expect(screen.getByText("Link copied")).toBeInTheDocument();
});
expect(screen.getByRole("button", { name: /Copied/i })).toBeInTheDocument();
expect(exec).toHaveBeenCalledWith("copy");
});
it("copies the private Rule URL", async () => {
openShare();
fireEvent.click(screen.getByRole("button", { name: /Copy link/i }));
@@ -141,9 +160,11 @@ describe("Share modal", () => {
}),
);
await user.click(screen.getByRole("button", { name: "Turn on link" }));
expect(
screen.getByDisplayValue("communityrule.info/r/k7f2-9qxm"),
).toBeInTheDocument();
const linkField = screen.getByDisplayValue(
"communityrule.info/r/k7f2-9qxm",
);
expect(linkField).toHaveAttribute("readonly");
expect(linkField).not.toBeDisabled();
expect(
screen.getByRole("button", { name: "Turn off link" }),
).toBeInTheDocument();
+41
View File
@@ -0,0 +1,41 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
const getReadablePublishedRuleMock = vi.fn();
const getSessionUserMock = vi.fn();
const notFoundMock = vi.fn(() => {
throw new Error("NEXT_NOT_FOUND");
});
vi.mock("next/navigation", () => ({
notFound: () => notFoundMock(),
}));
vi.mock("../../lib/server/publishedRules", () => ({
getReadablePublishedRule: (...args: unknown[]) =>
getReadablePublishedRuleMock(...args),
}));
vi.mock("../../lib/server/session", () => ({
getSessionUser: () => getSessionUserMock(),
}));
import { generateMetadata } from "../../app/(marketing)/r/[shareSlug]/page";
describe("shared Rule page", () => {
beforeEach(() => {
getReadablePublishedRuleMock.mockReset();
getSessionUserMock.mockReset();
notFoundMock.mockClear();
getSessionUserMock.mockResolvedValue(null);
});
it("returns 404 when the share link is off or unknown", async () => {
getReadablePublishedRuleMock.mockResolvedValue(null);
await expect(
generateMetadata({
params: Promise.resolve({ shareSlug: "k7f2-9qxm" }),
}),
).rejects.toThrow("NEXT_NOT_FOUND");
expect(notFoundMock).toHaveBeenCalled();
});
});