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:
1 parent
3a264ac2df
commit
0fe2624002
11 files changed
+132
-14
No files matched your search
@@ -30,10 +30,7 @@ export async function generateMetadata({
|
|||||||
const { shareSlug } = await params;
|
const { shareSlug } = await params;
|
||||||
const resolved = await loadSharedRule(shareSlug);
|
const resolved = await loadSharedRule(shareSlug);
|
||||||
if (!resolved) {
|
if (!resolved) {
|
||||||
return {
|
notFound();
|
||||||
title: messages.pages.ruleDetail.notFoundTitle,
|
|
||||||
description: "The requested CommunityRule could not be found.",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
const { rule } = resolved;
|
const { rule } = resolved;
|
||||||
const description =
|
const description =
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ const Avatar = memo<AvatarProps>(
|
|||||||
const fallbackChrome =
|
const fallbackChrome =
|
||||||
variant === "outlined"
|
variant === "outlined"
|
||||||
? "border-[1.5px] border-solid border-[var(--color-content-default-brand-primary)] bg-transparent text-[var(--color-content-default-brand-primary)]"
|
? "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).
|
// White 30% ring on small photos: no DS token (opacity scale is black-alpha).
|
||||||
const smallImageBorder =
|
const smallImageBorder =
|
||||||
size === "small" && showImage && loaded
|
size === "small" && showImage && loaded
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const TextInputContainer = forwardRef<HTMLInputElement, TextInputProps>(
|
|||||||
state: externalStateProp = "default",
|
state: externalStateProp = "default",
|
||||||
inputSize: inputSizeProp = "medium",
|
inputSize: inputSizeProp = "medium",
|
||||||
disabled = false,
|
disabled = false,
|
||||||
|
readOnly = false,
|
||||||
error = false,
|
error = false,
|
||||||
label,
|
label,
|
||||||
placeholder,
|
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) {
|
if (error) {
|
||||||
const filledStyles = isFilled
|
const filledStyles = isFilled
|
||||||
? "font-medium leading-[20px]"
|
? "font-medium leading-[20px]"
|
||||||
@@ -231,6 +242,7 @@ const TextInputContainer = forwardRef<HTMLInputElement, TextInputProps>(
|
|||||||
labelId={labelId}
|
labelId={labelId}
|
||||||
state={actualState}
|
state={actualState}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
readOnly={readOnly}
|
||||||
error={error}
|
error={error}
|
||||||
label={label}
|
label={label}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export interface TextInputProps extends Omit<
|
|||||||
*/
|
*/
|
||||||
inputSize?: TextInputSizeValue;
|
inputSize?: TextInputSizeValue;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
readOnly?: boolean;
|
||||||
error?: boolean;
|
error?: boolean;
|
||||||
label?: string;
|
label?: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
@@ -43,6 +44,7 @@ export interface TextInputViewProps {
|
|||||||
labelId: string;
|
labelId: string;
|
||||||
state: "default" | "active" | "hover" | "focus";
|
state: "default" | "active" | "hover" | "focus";
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
|
readOnly: boolean;
|
||||||
error: boolean;
|
error: boolean;
|
||||||
label?: string;
|
label?: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export const TextInputView = forwardRef<HTMLInputElement, TextInputViewProps>(
|
|||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
disabled,
|
disabled,
|
||||||
|
readOnly = false,
|
||||||
error = false,
|
error = false,
|
||||||
className: _className,
|
className: _className,
|
||||||
containerClasses,
|
containerClasses,
|
||||||
@@ -90,6 +91,7 @@ export const TextInputView = forwardRef<HTMLInputElement, TextInputViewProps>(
|
|||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
onMouseDown={handleMouseDown}
|
onMouseDown={handleMouseDown}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
readOnly={readOnly}
|
||||||
maxLength={maxLength}
|
maxLength={maxLength}
|
||||||
autoComplete={autoComplete}
|
autoComplete={autoComplete}
|
||||||
inputMode={inputMode}
|
inputMode={inputMode}
|
||||||
|
|||||||
@@ -245,9 +245,25 @@ const ShareContainer = memo<ShareProps>((props) => {
|
|||||||
|
|
||||||
const handleCopyLink = useCallback(async () => {
|
const handleCopyLink = useCallback(async () => {
|
||||||
if (!settings) return;
|
if (!settings) return;
|
||||||
|
const text = settings.shareUrl;
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(settings.shareUrl);
|
await navigator.clipboard.writeText(text);
|
||||||
setLinkCopied(true);
|
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 {
|
} catch {
|
||||||
setLinkCopied(false);
|
setLinkCopied(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ export const ShareView = memo(function ShareView({
|
|||||||
buttonType="outline"
|
buttonType="outline"
|
||||||
palette="default"
|
palette="default"
|
||||||
size="small"
|
size="small"
|
||||||
disabled={inviteBusy || inviteValue.trim().length === 0}
|
disabled={inviteBusy}
|
||||||
onClick={onInvite}
|
onClick={onInvite}
|
||||||
>
|
>
|
||||||
{copy.invite}
|
{copy.invite}
|
||||||
@@ -252,7 +252,7 @@ export const ShareView = memo(function ShareView({
|
|||||||
showHelpIcon={false}
|
showHelpIcon={false}
|
||||||
label={copy.anyoneWithLink}
|
label={copy.anyoneWithLink}
|
||||||
value={shareUrlDisplay}
|
value={shareUrlDisplay}
|
||||||
disabled
|
readOnly
|
||||||
textHint={copy.linkHint}
|
textHint={copy.linkHint}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
@@ -303,7 +303,10 @@ export const ShareView = memo(function ShareView({
|
|||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{linkCopied ? (
|
</div>
|
||||||
|
|
||||||
|
{linkCopied ? (
|
||||||
|
<div className="shrink-0 px-6 pb-2">
|
||||||
<Alert
|
<Alert
|
||||||
type="toast"
|
type="toast"
|
||||||
status="positive"
|
status="positive"
|
||||||
@@ -314,8 +317,8 @@ export const ShareView = memo(function ShareView({
|
|||||||
hasTrailingIcon={false}
|
hasTrailingIcon={false}
|
||||||
className="w-full"
|
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">
|
<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
|
<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", () => {
|
it("renders a button with hover treatment when onClick is set", () => {
|
||||||
const onClick = vi.fn();
|
const onClick = vi.fn();
|
||||||
render(
|
render(
|
||||||
|
|||||||
@@ -81,4 +81,19 @@ describe("TextInput (size tests)", () => {
|
|||||||
expect(input).toBeRequired();
|
expect(input).toBeRequired();
|
||||||
expect(input).toHaveAttribute("form", "create-flow-community-save");
|
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();
|
).toBeInTheDocument();
|
||||||
expect(screen.getByText("Juniper Street Food Share")).toBeInTheDocument();
|
expect(screen.getByText("Juniper Street Food Share")).toBeInTheDocument();
|
||||||
expect(screen.getByText("You")).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("rosa@example.org")).toBeInTheDocument();
|
||||||
expect(screen.getByText("Five more people can read it")).toBeInTheDocument();
|
expect(screen.getByText("Five more people can read it")).toBeInTheDocument();
|
||||||
expect(screen.getByText("Only people you invite can open 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 () => {
|
it("copies the private Rule URL", async () => {
|
||||||
openShare();
|
openShare();
|
||||||
fireEvent.click(screen.getByRole("button", { name: /Copy link/i }));
|
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" }));
|
await user.click(screen.getByRole("button", { name: "Turn on link" }));
|
||||||
expect(
|
const linkField = screen.getByDisplayValue(
|
||||||
screen.getByDisplayValue("communityrule.info/r/k7f2-9qxm"),
|
"communityrule.info/r/k7f2-9qxm",
|
||||||
).toBeInTheDocument();
|
);
|
||||||
|
expect(linkField).toHaveAttribute("readonly");
|
||||||
|
expect(linkField).not.toBeDisabled();
|
||||||
expect(
|
expect(
|
||||||
screen.getByRole("button", { name: "Turn off link" }),
|
screen.getByRole("button", { name: "Turn off link" }),
|
||||||
).toBeInTheDocument();
|
).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