Fix Share access, initials, copy confirm, and mailed export links #112
No files matched your search
@@ -30,10 +30,7 @@ export async function generateMetadata({
|
||||
const { shareSlug } = await params;
|
||||
const resolved = await loadSharedRule(shareSlug);
|
||||
if (!resolved) {
|
||||
return {
|
||||
title: messages.pages.ruleDetail.notFoundTitle,
|
||||
description: "The requested CommunityRule could not be found.",
|
||||
};
|
||||
notFound();
|
||||
}
|
||||
const { rule } = resolved;
|
||||
const description =
|
||||
|
||||
@@ -97,7 +97,7 @@ const Avatar = memo<AvatarProps>(
|
||||
const fallbackChrome =
|
||||
variant === "outlined"
|
||||
? "border-[1.5px] border-solid border-[var(--color-content-default-brand-primary)] bg-transparent text-[var(--color-content-default-brand-primary)]"
|
||||
: "bg-[var(--color-surface-invert-brand-primary)] text-[var(--color-content-default-primary)]";
|
||||
: "bg-[var(--color-surface-invert-brand-primary)] text-[var(--color-content-invert-primary)]";
|
||||
// White 30% ring on small photos: no DS token (opacity scale is black-alpha).
|
||||
const smallImageBorder =
|
||||
size === "small" && showImage && loaded
|
||||
|
||||
@@ -16,6 +16,7 @@ const TextInputContainer = forwardRef<HTMLInputElement, TextInputProps>(
|
||||
state: externalStateProp = "default",
|
||||
inputSize: inputSizeProp = "medium",
|
||||
disabled = false,
|
||||
readOnly = false,
|
||||
error = false,
|
||||
label,
|
||||
placeholder,
|
||||
@@ -109,6 +110,16 @@ const TextInputContainer = forwardRef<HTMLInputElement, TextInputProps>(
|
||||
};
|
||||
}
|
||||
|
||||
if (readOnly) {
|
||||
return {
|
||||
input:
|
||||
"bg-[var(--color-surface-default-secondary)] text-[var(--color-content-default-primary)] border border-solid border-[var(--color-border-default-primary)] cursor-default",
|
||||
label: "text-[var(--color-content-default-secondary)]",
|
||||
inputWrapper: "relative",
|
||||
focusRing: "",
|
||||
};
|
||||
}
|
||||
|
||||
if (error) {
|
||||
const filledStyles = isFilled
|
||||
? "font-medium leading-[20px]"
|
||||
@@ -231,6 +242,7 @@ const TextInputContainer = forwardRef<HTMLInputElement, TextInputProps>(
|
||||
labelId={labelId}
|
||||
state={actualState}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
error={error}
|
||||
label={label}
|
||||
placeholder={placeholder}
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface TextInputProps extends Omit<
|
||||
*/
|
||||
inputSize?: TextInputSizeValue;
|
||||
disabled?: boolean;
|
||||
readOnly?: boolean;
|
||||
error?: boolean;
|
||||
label?: string;
|
||||
placeholder?: string;
|
||||
@@ -43,6 +44,7 @@ export interface TextInputViewProps {
|
||||
labelId: string;
|
||||
state: "default" | "active" | "hover" | "focus";
|
||||
disabled: boolean;
|
||||
readOnly: boolean;
|
||||
error: boolean;
|
||||
label?: string;
|
||||
placeholder?: string;
|
||||
|
||||
@@ -13,6 +13,7 @@ export const TextInputView = forwardRef<HTMLInputElement, TextInputViewProps>(
|
||||
name,
|
||||
type,
|
||||
disabled,
|
||||
readOnly = false,
|
||||
error = false,
|
||||
className: _className,
|
||||
containerClasses,
|
||||
@@ -90,6 +91,7 @@ export const TextInputView = forwardRef<HTMLInputElement, TextInputViewProps>(
|
||||
onKeyDown={onKeyDown}
|
||||
onMouseDown={handleMouseDown}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
maxLength={maxLength}
|
||||
autoComplete={autoComplete}
|
||||
inputMode={inputMode}
|
||||
|
||||
@@ -245,9 +245,25 @@ const ShareContainer = memo<ShareProps>((props) => {
|
||||
|
||||
const handleCopyLink = useCallback(async () => {
|
||||
if (!settings) return;
|
||||
const text = settings.shareUrl;
|
||||
try {
|
||||
await navigator.clipboard.writeText(settings.shareUrl);
|
||||
await navigator.clipboard.writeText(text);
|
||||
setLinkCopied(true);
|
||||
return;
|
||||
} catch {
|
||||
// Some browsers deny clipboard without a secure context; fall back.
|
||||
}
|
||||
try {
|
||||
const field = document.createElement("textarea");
|
||||
field.value = text;
|
||||
field.setAttribute("readonly", "");
|
||||
field.style.position = "fixed";
|
||||
field.style.left = "-9999px";
|
||||
document.body.appendChild(field);
|
||||
field.select();
|
||||
const copied = document.execCommand("copy");
|
||||
field.remove();
|
||||
setLinkCopied(copied);
|
||||
} catch {
|
||||
setLinkCopied(false);
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ export const ShareView = memo(function ShareView({
|
||||
buttonType="outline"
|
||||
palette="default"
|
||||
size="small"
|
||||
disabled={inviteBusy || inviteValue.trim().length === 0}
|
||||
disabled={inviteBusy}
|
||||
onClick={onInvite}
|
||||
>
|
||||
{copy.invite}
|
||||
@@ -252,7 +252,7 @@ export const ShareView = memo(function ShareView({
|
||||
showHelpIcon={false}
|
||||
label={copy.anyoneWithLink}
|
||||
value={shareUrlDisplay}
|
||||
disabled
|
||||
readOnly
|
||||
textHint={copy.linkHint}
|
||||
/>
|
||||
<Button
|
||||
@@ -303,7 +303,10 @@ export const ShareView = memo(function ShareView({
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{linkCopied ? (
|
||||
</div>
|
||||
|
||||
{linkCopied ? (
|
||||
<div className="shrink-0 px-6 pb-2">
|
||||
<Alert
|
||||
type="toast"
|
||||
status="positive"
|
||||
@@ -314,8 +317,8 @@ export const ShareView = memo(function ShareView({
|
||||
hasTrailingIcon={false}
|
||||
className="w-full"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex shrink-0 items-center justify-between border-t border-solid border-[var(--color-border-default-secondary)] bg-[var(--color-surface-default-primary)] px-6 py-4">
|
||||
<Button
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user