fix(ui): desktop redeem entry — 兑换码 row in the account menu, the balance opens 点数与兑换码, icon-only controls named on hover (BUG-2361)
A beta user on a computer could not find where to redeem a code, and hovering the icons named nothing. The account menu now has its own 兑换码 row that opens 账户与点数 on its 兑换码 page with the box focused (desktop only); the balance on the account row is its own button (opens 账户与点数, tooltip 点数与兑换码); the desktop sidebar toggle and the collapsed rail's avatar are named on hover, and the rail's screen-reader name is Chinese. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
This commit is contained in:
@@ -32122,3 +32122,19 @@
|
||||
- 防复发:后台授予角色与身份角色在同一事务里由触发器同步,不再依赖手工改库。
|
||||
- 关联记录:BUG-1935(admin_runtime 读策略)、BUG-2346(后台两步验证)、首个 Owner 恢复迁移 20260807010000。
|
||||
- 修复版本:分支 `claude/admin-role-sync-2360`。
|
||||
|
||||
## BUG-2361 | 电脑上找不到兑换码入口,鼠标放到图标上也没有提示
|
||||
|
||||
- 状态:resolved(待 staging 验收)
|
||||
- 现象:2026-11-25 内测用户反馈:手机上好用,电脑上「有点找不到兑换入口,鼠标放过去也没有显示哪个是什么的指引」。
|
||||
- 触发条件:电脑浏览器。唯一入口是左下角头像 → 账户菜单「账户与点数」→ 弹窗里的「兑换码」页;菜单里没有「兑换」两个字,侧栏左下的余额只是文字;左上角收起侧栏的按钮只有图标、悬停无名字;侧栏收起成窄栏后,头像按钮没有名字也没有悬停提示。
|
||||
- 根因:入口命名只写了「账户与点数」,用户不会联想到兑换码;桌面上纯图标的控件(侧栏开合按钮、窄栏头像)没有悬停提示,SidebarRail 的读屏名还是英文。
|
||||
- 修复:
|
||||
- 账户菜单在「账户与点数」下面加一行「兑换码」(Ticket 图标,与其他行同样式),直接打开「账户与点数」的兑换码页;电脑上(hover + 精确指针)输入框自动获得光标,手机不弹键盘。首页走 Home 的 controls(`onOpenRedeem`),其他页走外壳的 `onOpenAccountDialog`(多传 `{ tab: "redeem" }`)。
|
||||
- 侧栏账户行右侧的「N 点」改成独立按钮(盖在原位置上,原文字只占位、读屏隐藏;按钮不能放进菜单按钮里),点开「账户与点数」(第一页就是兑换码),悬停提示「点数与兑换码」。
|
||||
- 桌面上 SidebarTrigger 悬停显示「收起侧边栏 / 展开侧边栏」;窄栏头像悬停显示「账户」并有读屏名;SidebarRail 读屏名改中文。手机不加提示(手机上按钮带「菜单」字样)。
|
||||
- 「点数不够」时的路径已存在(聊天先弹兑换引导,再开账户与点数;报告的「去补点数」打开同一弹窗,第一页是兑换码),未改。
|
||||
- 验证:新增 `frontend/tests/redeem-entry-2361.test.tsx`(5 条:余额按钮在菜单按钮之外且有读屏名、点击在站外页 / 首页分别打开账户与点数、菜单「兑换码」行位置与 tab、兑换码页输入框两帧后聚焦且只在电脑上、桌面纯图标控件的悬停名);三个钉住旧调用的测试按原值 / 新值 / 原因更新(account-dialogs-every-page-2127、account-menu-every-page-20260928、sidebar-contract)。tsc 无错,ESLint 0 错误;`next build --webpack` 成功,用编译后的样式在无头 Chrome 1440 / 300 宽量过:余额按钮文字与占位文字位置相差 0.2px。前端全量 5374 条,失败 28 条,均为本机缺数据库 / docker / YAML / swisseph 的环境项。
|
||||
- 防复发:入口按用户的说法命名(「兑换码」直接出现在菜单里);桌面纯图标控件必须有悬停名,测试钉住侧栏开合与窄栏头像。
|
||||
- 关联记录:BUG-2253(账户行显示余额)、BUG-2127(账户弹窗每页原地打开)、BUG-2203(手机侧栏按钮带「菜单」字样)。
|
||||
- 修复版本:分支 `claude/redeem-entry-2361`。
|
||||
|
||||
@@ -74,9 +74,10 @@ function AppShell({ children }: { children: ReactNode }) {
|
||||
rectificationEnabled={rectificationEnabled}
|
||||
controls={registration?.controls}
|
||||
sessionControls={sessionActions.controls}
|
||||
onOpenAccountDialog={(dialog, returnTarget) => {
|
||||
onOpenAccountDialog={(dialog, returnTarget, options) => {
|
||||
// Same source as the menu on `/` (use-home-shell-registration).
|
||||
accountDialogs.open(dialog, { returnTarget, source: dialog === "billing" ? "account-menu" : undefined });
|
||||
const source = dialog !== "billing" ? undefined : options?.tab === "redeem" ? "account-menu-redeem" : "account-menu";
|
||||
accountDialogs.open(dialog, { returnTarget, source, tab: options?.tab });
|
||||
}}
|
||||
onOpenSession={(sessionId) => {
|
||||
navigateAppPath(sessionHref("", sessionId), router.push);
|
||||
|
||||
@@ -1315,6 +1315,13 @@ button.shell-resize-handle:active { position: absolute; top: 0; right: -3px; z-i
|
||||
/* BUG-2253: the balance at the right end of the account row, small and quiet. */
|
||||
.sidebar-account-credits { color: var(--color-ink-tertiary); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; padding-right: var(--space-1); }
|
||||
.sidebar-account-trigger b { display: block; overflow: hidden; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 500; }
|
||||
/* BUG-2361: the balance is its own button laid over its place on the row (opens 账户与点数 → 兑换码).
|
||||
The copy inside the menu trigger only holds the width, so the name keeps the same room as before. */
|
||||
.sidebar-account-credits.is-placeholder { visibility: hidden; }
|
||||
.sidebar-account-credits-button { height: auto; min-height: 0; width: auto; gap: 0; color: var(--color-ink-tertiary); font-weight: 400; box-shadow: none; }
|
||||
.sidebar-account-credits-button { position: absolute; top: var(--space-2); bottom: var(--space-3); right: 0; display: flex; align-items: center; margin: 0; padding: 0 calc(var(--space-2) + var(--space-1)) 0 var(--space-2); border: 0; border-radius: var(--radius-md); background: transparent; font: inherit; font-size: 12px; cursor: pointer; transition: color var(--motion-instant) var(--ease-out); }
|
||||
.sidebar-account-credits-button:hover { background: transparent; color: var(--color-ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--color-border-strong); }
|
||||
.sidebar-account-credits-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--sidebar-ring) 56%, transparent); outline-offset: -3px; }
|
||||
[data-sidebar="trigger"] { width: 44px; height: 44px; display: grid; flex: 0 0 auto; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--sidebar-foreground); cursor: pointer; }
|
||||
[data-sidebar="trigger"] svg { width: 18px; height: 18px; }
|
||||
[data-sidebar="trigger"]:hover { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); }
|
||||
|
||||
@@ -24,14 +24,18 @@ import {
|
||||
MessageSquareWarning,
|
||||
Plus,
|
||||
Star,
|
||||
Ticket,
|
||||
Users,
|
||||
} from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { primeSessionArrivals } from "@/lib/sidebar-session-arrivals";
|
||||
import type { MouseEvent, ReactNode, Ref } from "react";
|
||||
import type { MouseEvent, ReactElement, ReactNode, Ref } from "react";
|
||||
import { OnboardingDot } from "@/components/onboarding-dot";
|
||||
import type { AccountDialogIntent } from "@/lib/account-dialog-intent";
|
||||
import type { BillingPaneTab } from "@/lib/home-types";
|
||||
import { newChatHref, sessionHref } from "@/lib/chat-session-url";
|
||||
import { LEGAL_DOCUMENTS_VISIBLE } from "@/lib/legal-entity";
|
||||
import { useOnboardingJourneyOptional } from "@/lib/onboarding-journey";
|
||||
@@ -106,6 +110,8 @@ export type AppSidebarControls = {
|
||||
onOpenProfile: () => void;
|
||||
onOpenGeneral: () => void;
|
||||
onOpenBilling: () => void;
|
||||
/** BUG-2361: 账户与点数 opened on its 兑换码 page. Optional so older registrations still type-check. */
|
||||
onOpenRedeem?: () => void;
|
||||
onOpenLogout: () => void;
|
||||
};
|
||||
|
||||
@@ -130,7 +136,7 @@ export type AppSidebarProps = {
|
||||
/** Opens a row off `/`: the shell routes it to `/?c=<id>`. `controls` wins on `/`. */
|
||||
onOpenSession?: (sessionId: string) => void;
|
||||
/** Off `/`: opens an account dialog in place, from the shell's account dialogs (BUG-2127). `controls` wins on `/`. */
|
||||
onOpenAccountDialog?: (dialog: AccountDialogIntent, returnTarget: HTMLButtonElement | null) => void;
|
||||
onOpenAccountDialog?: (dialog: AccountDialogIntent, returnTarget: HTMLButtonElement | null, options?: { tab?: BillingPaneTab }) => void;
|
||||
};
|
||||
|
||||
const NAV_PAGES = [
|
||||
@@ -182,6 +188,7 @@ export function AppSidebar({
|
||||
onOpenProfile,
|
||||
onOpenGeneral,
|
||||
onOpenBilling,
|
||||
onOpenRedeem,
|
||||
onOpenLogout,
|
||||
}: Partial<AppSidebarControls> = controls ?? {};
|
||||
const onSelectSession = controlledSelectSession ?? onOpenSession;
|
||||
@@ -357,6 +364,23 @@ export function AppSidebar({
|
||||
);
|
||||
}
|
||||
|
||||
/* BUG-2361: a name on hover/focus for a control that shows only an icon. Desktop only — the
|
||||
tooltip needs a pointer, and phones show words instead. `null` returns the control as it is. */
|
||||
function withHoverTooltip(label: string | null, control: ReactElement, side: "top" | "right" = "top") {
|
||||
if (label === null) return control;
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger render={control} />
|
||||
<TooltipContent side={side}>{label}</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
/* The collapsed rail's avatar: same tooltip as the rail's other entries (to the right). */
|
||||
function withRailTooltip(label: string | null, control: ReactElement) {
|
||||
return withHoverTooltip(label, control, "right");
|
||||
}
|
||||
|
||||
/* One entry of the account menu. The dialog opens in place on every page:
|
||||
on `/` through Home's controls, elsewhere through the shell (BUG-2127;
|
||||
off `/` the entry used to be a link to `/?account=<dialog>`). */
|
||||
@@ -366,10 +390,11 @@ export function AppSidebar({
|
||||
className: string,
|
||||
content: ReactNode,
|
||||
pointer: { onPointerEnter?: () => void; onPointerDown?: () => void } = {},
|
||||
options?: { tab?: BillingPaneTab },
|
||||
) {
|
||||
const openInPlace = onOpen ?? (() => {
|
||||
setOwnMenuOpen(false);
|
||||
onOpenAccountDialog?.(dialog, ownTriggerRef.current);
|
||||
onOpenAccountDialog?.(dialog, ownTriggerRef.current, options);
|
||||
});
|
||||
return (
|
||||
<DropdownMenuItem className={className} onClick={openInPlace} {...pointer}>{content}</DropdownMenuItem>
|
||||
@@ -511,18 +536,41 @@ export function AppSidebar({
|
||||
it keeps its own open state. Its entries open the dialogs in place
|
||||
everywhere (BUG-2127). Theme applies where the reader is. */
|
||||
<DropdownMenu open={accountMenuOpen} onOpenChange={onAccountMenuOpenChange} modal={false}>
|
||||
<DropdownMenuTrigger
|
||||
className="sidebar-account-trigger"
|
||||
ref={controls ? accountTriggerRef : ownTriggerRef}
|
||||
type="button"
|
||||
>
|
||||
{account.avatar
|
||||
? <UserAvatar avatar={account.avatar} imageVersion={account.avatarImageVersion ?? null} size={32} className="profile-avatar" />
|
||||
: <span className="profile-initial" aria-hidden="true">{account.initial}</span>}
|
||||
{showExpandedContent ? <span><b>{account.name}</b></span> : null}
|
||||
{/* BUG-2253 (产品负责人 2026-11-23): the balance on the account row, without opening the menu. */}
|
||||
{showExpandedContent ? <span className="sidebar-account-credits" aria-label={`余额 ${account.credits} 点`}><CreditsValue value={account.credits} className="sidebar-account-credits-value" /> 点</span> : null}
|
||||
</DropdownMenuTrigger>
|
||||
{withRailTooltip(isCollapsedDesktop ? "账户" : null, (
|
||||
<DropdownMenuTrigger
|
||||
className="sidebar-account-trigger"
|
||||
ref={controls ? accountTriggerRef : ownTriggerRef}
|
||||
type="button"
|
||||
aria-label={isCollapsedDesktop ? `账户:${account.name}` : undefined}
|
||||
>
|
||||
{account.avatar
|
||||
? <UserAvatar avatar={account.avatar} imageVersion={account.avatarImageVersion ?? null} size={32} className="profile-avatar" />
|
||||
: <span className="profile-initial" aria-hidden="true">{account.initial}</span>}
|
||||
{showExpandedContent ? <span><b>{account.name}</b></span> : null}
|
||||
{/* BUG-2253 (产品负责人 2026-11-23): the balance on the account row, without opening the menu.
|
||||
BUG-2361: here it only keeps its place; the visible balance is the button drawn over it below. */}
|
||||
{showExpandedContent ? <span className="sidebar-account-credits is-placeholder" aria-hidden="true"><CreditsValue value={account.credits} className="sidebar-account-credits-value" /> 点</span> : null}
|
||||
</DropdownMenuTrigger>
|
||||
))}
|
||||
{/* BUG-2361 (内测用户 2026-11-25「电脑找不到兑换入口,鼠标放过去也没有提示」): the balance is its
|
||||
own button, laid over its place on the row (a button cannot sit inside the menu trigger), and
|
||||
opens 账户与点数, whose first page is 兑换码. */}
|
||||
{showExpandedContent ? withHoverTooltip(isMobile ? null : "点数与兑换码", (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
className="sidebar-account-credits sidebar-account-credits-button"
|
||||
aria-label={`余额 ${account.credits} 点,打开点数与兑换码`}
|
||||
onPointerEnter={prefetchBillingPanel}
|
||||
onClick={() => {
|
||||
if (onOpenBilling) onOpenBilling();
|
||||
else onOpenAccountDialog?.("billing", ownTriggerRef.current);
|
||||
}}
|
||||
>
|
||||
{/* One inline run, so the space before 点 survives the button's flex layout. */}
|
||||
<span><CreditsValue value={account.credits} className="sidebar-account-credits-value" /> 点</span>
|
||||
</Button>
|
||||
)) : null}
|
||||
<DropdownMenuContent
|
||||
className="account-menu-popup w-auto min-w-56"
|
||||
aria-label="账户菜单"
|
||||
@@ -553,6 +601,13 @@ export function AppSidebar({
|
||||
onPointerEnter: () => { prefetchBillingPanel(); if (account.paymentOpen !== false) prefetchPaymentPackages(); },
|
||||
onPointerDown: () => { prefetchBillingPanel(); if (account.paymentOpen !== false) prefetchPaymentPackages(); },
|
||||
})}
|
||||
{/* BUG-2361 (内测用户 2026-11-25「电脑找不到兑换入口」): its own row, straight to the 兑换码 page. */}
|
||||
{accountEntry("billing", onOpenRedeem, "account-menu-item", (
|
||||
<><Ticket aria-hidden="true" /><span>兑换码</span></>
|
||||
), {
|
||||
onPointerEnter: prefetchBillingPanel,
|
||||
onPointerDown: prefetchBillingPanel,
|
||||
}, { tab: "redeem" })}
|
||||
<DropdownMenuItem className="account-menu-item" onClick={() => { onAccountMenuOpenChange?.(false); setFeedbackOpen(true); }}>
|
||||
<MessageSquareWarning aria-hidden="true" /><span>反馈与投诉</span>
|
||||
</DropdownMenuItem>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { ChevronRight } from "lucide-react";
|
||||
import { AppLink } from "@/components/app-link";
|
||||
import { BillingSkeletonRows } from "@/components/billing-balance";
|
||||
@@ -234,6 +234,23 @@ export function BillingPanel({ account: seedAccount, highlightedPlan, initialTab
|
||||
version: ledgerVersion,
|
||||
});
|
||||
const packs = paymentPackages.filter((product) => product.productType === "credit_pack");
|
||||
const redeemInput = useRef<HTMLInputElement>(null);
|
||||
|
||||
// BUG-2361: opened from the menu's 「兑换码」 row, the code box takes the cursor — on a desktop only,
|
||||
// where it does not raise a keyboard over the page. Two frames: the dialog first focuses its
|
||||
// close button (account-dialog-provider), and this must land after it.
|
||||
useEffect(() => {
|
||||
if (initialTab !== "redeem" || highlightedPlan) return;
|
||||
if (typeof window.matchMedia !== "function" || !window.matchMedia("(hover: hover) and (pointer: fine)").matches) return;
|
||||
let second = 0;
|
||||
const first = window.requestAnimationFrame(() => {
|
||||
second = window.requestAnimationFrame(() => redeemInput.current?.focus());
|
||||
});
|
||||
return () => {
|
||||
window.cancelAnimationFrame(first);
|
||||
window.cancelAnimationFrame(second);
|
||||
};
|
||||
}, [initialTab, highlightedPlan]);
|
||||
|
||||
useEffect(() => {
|
||||
if (shownPage === "recharge") requestOrders();
|
||||
@@ -260,6 +277,7 @@ export function BillingPanel({ account: seedAccount, highlightedPlan, initialTab
|
||||
<label className="billing-group-title" htmlFor="billing-redeem-code">兑换码</label>
|
||||
<div className="billing-redeem-line">
|
||||
<Input
|
||||
ref={redeemInput}
|
||||
id="billing-redeem-code"
|
||||
className="billing-code-input"
|
||||
autoComplete="off"
|
||||
|
||||
@@ -302,17 +302,21 @@ export const SidebarTrigger = forwardRef<HTMLButtonElement, SidebarTriggerProps>
|
||||
setRef(ref, element);
|
||||
if (placement === "inset") setInsetTrigger(element);
|
||||
};
|
||||
return (
|
||||
const button = (
|
||||
<button ref={register} type="button" data-sidebar="trigger" data-slot="sidebar-trigger" aria-label={label} aria-expanded={expanded} className={cn("min-h-11 min-w-11", className)} onClick={(event) => { onClick?.(event); if (!event.defaultPrevented) toggleSidebar(); }} {...props}>
|
||||
<PanelLeft aria-hidden="true" />
|
||||
<span className="sidebar-trigger-label" aria-hidden="true">菜单</span>
|
||||
</button>
|
||||
);
|
||||
// BUG-2361: on a desktop the button is the icon alone, so hovering it names it. Phones show 「菜单」.
|
||||
if (isMobile) return button;
|
||||
return <Tooltip.Root><Tooltip.Trigger render={button} /><Tooltip.Portal><Tooltip.Positioner side="bottom" sideOffset={6}><Tooltip.Popup>{label}</Tooltip.Popup></Tooltip.Positioner></Tooltip.Portal></Tooltip.Root>;
|
||||
});
|
||||
|
||||
export function SidebarRail({ className, onClick, ...props }: ComponentProps<"button">) {
|
||||
const { isMobile, open, setOpen } = useSidebar();
|
||||
if (isMobile) return null;
|
||||
const label = open ? "Collapse sidebar" : "Expand sidebar";
|
||||
// BUG-2361 原值 "Collapse sidebar" / "Expand sidebar";新值 中文;原因:读屏念出英文,和 SidebarTrigger 不一致。
|
||||
const label = open ? "收起侧边栏" : "展开侧边栏";
|
||||
return <button type="button" data-sidebar="rail" data-slot="sidebar-rail" aria-label={label} className={cn("min-h-11 min-w-11", className)} onClick={(event) => { onClick?.(event); if (!event.defaultPrevented) setOpen(!open); }} {...props} />;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useEffect, useMemo, useRef, type Dispatch, type RefObject, type SetStat
|
||||
|
||||
import { avatarImageVersion } from "@/lib/avatar-crop";
|
||||
import type { ChatSession } from "@/lib/home-types";
|
||||
import type { Account } from "@/lib/home-types";
|
||||
import type { Account, BillingPaneTab } from "@/lib/home-types";
|
||||
import type { ChartLibraryRecord, Profile } from "@/lib/home-types";
|
||||
import type { PublicLanguageModelCatalog } from "@/lib/public-models";
|
||||
import { toSidebarSessionRow } from "@/lib/session-sidebar-row";
|
||||
@@ -24,7 +24,7 @@ type HomeShellRegistrationParams = {
|
||||
loadMoreSessions: () => void;
|
||||
modalOpen: boolean;
|
||||
modelCatalog: PublicLanguageModelCatalog | null;
|
||||
openAccountDialog: (dialog: AccountDialogName, options?: { source?: string }) => void;
|
||||
openAccountDialog: (dialog: AccountDialogName, options?: { source?: string; tab?: BillingPaneTab }) => void;
|
||||
pendingSessionId: string | null;
|
||||
profile: Profile;
|
||||
registerShellControls: (registration: ShellRegistration | null) => void;
|
||||
@@ -43,7 +43,7 @@ type LatestShellActions = {
|
||||
loadMoreSessions: () => void;
|
||||
selectSession: (sessionId: string) => void;
|
||||
startNewChat: () => void | Promise<unknown>;
|
||||
openAccountDialog: (dialog: AccountDialogName, options?: { source?: string }) => void;
|
||||
openAccountDialog: (dialog: AccountDialogName, options?: { source?: string; tab?: BillingPaneTab }) => void;
|
||||
setAccountMenuOpen: Dispatch<SetStateAction<boolean>>;
|
||||
onSessionDeleted: (session: ChatSession, remaining: ChatSession[]) => void;
|
||||
isSessionSaved: (session: ChatSession) => boolean;
|
||||
@@ -156,6 +156,8 @@ export function useHomeShellRegistration(params: HomeShellRegistrationParams) {
|
||||
onOpenProfile: () => { latestRef.current?.openAccountDialog("profile"); },
|
||||
onOpenGeneral: () => { latestRef.current?.openAccountDialog("general"); },
|
||||
onOpenBilling: () => { latestRef.current?.openAccountDialog("billing", { source: "account-menu" }); },
|
||||
// BUG-2361: the account menu's own 「兑换码」 row opens 账户与点数 on its 兑换码 page, input focused.
|
||||
onOpenRedeem: () => { latestRef.current?.openAccountDialog("billing", { source: "account-menu-redeem", tab: "redeem" }); },
|
||||
onOpenLogout: () => { latestRef.current?.openAccountDialog("logout"); },
|
||||
}), []);
|
||||
|
||||
@@ -221,6 +223,7 @@ export function useHomeShellRegistration(params: HomeShellRegistrationParams) {
|
||||
onOpenProfile: stableControls.onOpenProfile,
|
||||
onOpenGeneral: stableControls.onOpenGeneral,
|
||||
onOpenBilling: stableControls.onOpenBilling,
|
||||
onOpenRedeem: stableControls.onOpenRedeem,
|
||||
onOpenLogout: stableControls.onOpenLogout,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -201,7 +201,10 @@ test("the shell mounts the dialogs once; Home and the sidebar call the same open
|
||||
const provider = read("components/account-dialog-provider.tsx");
|
||||
assert.match(layout, /<SessionListProvider>\s*<AccountDialogProvider>\s*<AppShell>\{children\}<\/AppShell>\s*<\/AccountDialogProvider>\s*<\/SessionListProvider>/);
|
||||
assert.equal(layout.match(/<AccountDialogHost \/>/g)?.length, 1);
|
||||
assert.match(layout, /onOpenAccountDialog=\{\(dialog, returnTarget\) => \{[\s\S]*?accountDialogs\.open\(dialog, \{ returnTarget, source: dialog === "billing" \? "account-menu" : undefined \}\);/);
|
||||
// BUG-2361 原值:`(dialog, returnTarget) => accountDialogs.open(dialog, { returnTarget, source: dialog === "billing" ? "account-menu" : undefined })`
|
||||
// 新值:多一个 `options`(菜单「兑换码」行带 `tab: "redeem"`),来源分 account-menu / account-menu-redeem,tab 原样传给 open
|
||||
// 原因:内测用户在电脑上找不到兑换入口,账户菜单加了直达 兑换码 的一行,站外页也要原地打开到那一页
|
||||
assert.match(layout, /onOpenAccountDialog=\{\(dialog, returnTarget, options\) => \{[\s\S]*?const source = dialog !== "billing" \? undefined : options\?\.tab === "redeem" \? "account-menu-redeem" : "account-menu";\s*accountDialogs\.open\(dialog, \{ returnTarget, source, tab: options\?\.tab \}\);/);
|
||||
// BUG-2072's watcher keeps its place right after the consent gate, with the same condition.
|
||||
assert.match(layout, /<LegalConsentGate signedIn=\{Boolean\(account\) && !list\.signedOut\} \/>\s*\{\/\*[^*]*\*\/\}\s*<ReportReminderWatcher signedIn=\{Boolean\(account\) && !list\.signedOut\} \/>/);
|
||||
// Home draws no overlay of its own and does not read the account for it.
|
||||
|
||||
@@ -66,7 +66,8 @@ test("the four dialog entries open in place on every page; theme stays in place"
|
||||
// 原值:`return onOpen ? (<DropdownMenuItem onClick={onOpen}>) : (<DropdownMenuItem closeOnClick render={<AppLink href={accountDialogHref(dialog)} …/>}>)`
|
||||
// 新值:只有一种 `DropdownMenuItem onClick={openInPlace}`:首页用 Home 的 controls,别的页用外壳的 onOpenAccountDialog
|
||||
// 原因:BUG-2127,站外页点设置会先跳到聊天页再开弹窗;弹窗搬到 (app) 外壳后每页原地打开,不再链到 `/?account=`
|
||||
assert.match(entry, /const openInPlace = onOpen \?\? \(\(\) => \{\s*setOwnMenuOpen\(false\);\s*onOpenAccountDialog\?\.\(dialog, ownTriggerRef\.current\);/);
|
||||
// BUG-2361 原值:`onOpenAccountDialog?.(dialog, ownTriggerRef.current);` / 新值:多传 `options`(兑换码行的 `tab: "redeem"`)/ 原因:菜单加了直达 兑换码 的一行。
|
||||
assert.match(entry, /const openInPlace = onOpen \?\? \(\(\) => \{\s*setOwnMenuOpen\(false\);\s*onOpenAccountDialog\?\.\(dialog, ownTriggerRef\.current, options\);/);
|
||||
assert.match(entry, /<DropdownMenuItem className=\{className\} onClick=\{openInPlace\}/);
|
||||
assert.doesNotMatch(sidebar, /accountDialogHref|closeOnClick\s+render=\{<AppLink/);
|
||||
// Theme is not a dialog: the same ThemePreferenceMenu on every page.
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* BUG-2361 (内测用户 2026-11-25): on a computer the redeem entry was hard to find, and hovering
|
||||
* the icons named nothing. The only way in was avatar → 「账户与点数」 → 兑换码.
|
||||
* Now: the account menu has its own 「兑换码」 row (opens 账户与点数 on 兑换码), the balance on the
|
||||
* account row is a button (opens 账户与点数, whose first page is 兑换码) named on hover, and the
|
||||
* icon-only sidebar toggle and the collapsed rail's avatar are named on hover.
|
||||
* Synthetic account only.
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
import React from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { createClientLifecycleHarness } from "./react-client-lifecycle-test-support.ts";
|
||||
|
||||
Object.assign(globalThis, { React });
|
||||
|
||||
const read = (path: string) => readFileSync(new URL(`../src/${path}`, import.meta.url), "utf8");
|
||||
const ACCOUNT = { name: "示例乙", email: "fictional@example.invalid", credits: 12, initial: "示", avatar: null };
|
||||
|
||||
test("the balance on the account row is its own button that names where it goes", async () => {
|
||||
const { SidebarProvider } = await import("../src/components/ui/sidebar.tsx");
|
||||
const { AppSidebar } = await import("../src/components/app-sidebar.tsx");
|
||||
const markup = renderToStaticMarkup(
|
||||
<SidebarProvider>
|
||||
<AppSidebar sessions={[]} activeSessionId={null} account={ACCOUNT} />
|
||||
</SidebarProvider>,
|
||||
);
|
||||
// A button, outside the menu trigger (a button cannot hold a button).
|
||||
const balanceButton = /<button[^>]*sidebar-account-credits-button[^>]*>/.exec(markup)?.[0] ?? "";
|
||||
assert.match(balanceButton, /aria-label="余额 12 点,打开点数与兑换码"/);
|
||||
assert.match(balanceButton, /class="[^"]*sidebar-account-credits sidebar-account-credits-button"/);
|
||||
// The copy inside the trigger only keeps the width and is hidden from screen readers.
|
||||
assert.match(markup, /<span class="sidebar-account-credits is-placeholder" aria-hidden="true">/);
|
||||
const trigger = markup.slice(markup.indexOf("sidebar-account-trigger"));
|
||||
const triggerEnd = trigger.indexOf("</button>");
|
||||
assert.doesNotMatch(trigger.slice(0, triggerEnd), /sidebar-account-credits-button/);
|
||||
});
|
||||
|
||||
test("clicking the balance opens 账户与点数 off `/`, and the shell's controls on `/`", async () => {
|
||||
const { SidebarProvider } = await import("../src/components/ui/sidebar.tsx");
|
||||
const { AppSidebar } = await import("../src/components/app-sidebar.tsx");
|
||||
|
||||
const offHome: unknown[][] = [];
|
||||
const h = createClientLifecycleHarness();
|
||||
try {
|
||||
await h.render(
|
||||
<SidebarProvider>
|
||||
<AppSidebar
|
||||
sessions={[]}
|
||||
activeSessionId={null}
|
||||
account={ACCOUNT}
|
||||
onOpenAccountDialog={(...args) => { offHome.push(args); }}
|
||||
/>
|
||||
</SidebarProvider>,
|
||||
);
|
||||
const button = h.elements().find((node) => String(node.getAttribute?.("class") ?? "").includes("sidebar-account-credits-button"));
|
||||
assert.ok(button, "the balance button is mounted");
|
||||
await h.event(button);
|
||||
assert.equal(offHome.length, 1);
|
||||
assert.equal(offHome[0][0], "billing");
|
||||
} finally {
|
||||
await h.close();
|
||||
}
|
||||
|
||||
let billingOpened = 0;
|
||||
const onHome = createClientLifecycleHarness();
|
||||
try {
|
||||
await onHome.render(
|
||||
<SidebarProvider>
|
||||
<AppSidebar
|
||||
sessions={[]}
|
||||
activeSessionId={null}
|
||||
account={ACCOUNT}
|
||||
onOpenAccountDialog={() => { throw new Error("on `/` the controls open it"); }}
|
||||
controls={{
|
||||
accountMenuOpen: false,
|
||||
accountTriggerRef: { current: null },
|
||||
newChatDisabled: false,
|
||||
creatingSession: false,
|
||||
onAccountMenuOpenChange: () => {},
|
||||
onNewChat: () => {},
|
||||
onSelectSession: () => {},
|
||||
onOpenProfile: () => {},
|
||||
onOpenGeneral: () => {},
|
||||
onOpenBilling: () => { billingOpened += 1; },
|
||||
onOpenLogout: () => {},
|
||||
}}
|
||||
/>
|
||||
</SidebarProvider>,
|
||||
);
|
||||
const button = onHome.elements().find((node) => String(node.getAttribute?.("class") ?? "").includes("sidebar-account-credits-button"));
|
||||
assert.ok(button);
|
||||
await onHome.event(button);
|
||||
assert.equal(billingOpened, 1);
|
||||
} finally {
|
||||
await onHome.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("the account menu has its own 兑换码 row that opens 账户与点数 on 兑换码", () => {
|
||||
const sidebar = read("components/app-sidebar.tsx");
|
||||
const billingRow = sidebar.indexOf('accountEntry("billing", onOpenBilling,');
|
||||
const redeemRow = sidebar.indexOf('accountEntry("billing", onOpenRedeem,');
|
||||
assert.ok(billingRow > 0 && redeemRow > billingRow, "兑换码 sits right under 账户与点数");
|
||||
assert.match(sidebar.slice(redeemRow, redeemRow + 400), /<Ticket aria-hidden="true" \/><span>兑换码<\/span>/);
|
||||
assert.match(sidebar.slice(redeemRow, redeemRow + 600), /\{ tab: "redeem" \}\)\}/);
|
||||
const home = read("hooks/use-home-shell-registration.ts");
|
||||
assert.match(home, /onOpenRedeem: \(\) => \{ latestRef\.current\?\.openAccountDialog\("billing", \{ source: "account-menu-redeem", tab: "redeem" \}\); \},/);
|
||||
assert.match(home, /onOpenRedeem: stableControls\.onOpenRedeem,/);
|
||||
});
|
||||
|
||||
test("opened on 兑换码 the code box takes the cursor on a desktop, after the dialog's own focus", () => {
|
||||
const panel = read("components/billing-panel.tsx");
|
||||
const effect = panel.slice(panel.indexOf("BUG-2361"), panel.indexOf("BUG-2361") + 1200);
|
||||
assert.match(effect, /if \(initialTab !== "redeem" \|\| highlightedPlan\) return;/);
|
||||
assert.match(effect, /matchMedia\("\(hover: hover\) and \(pointer: fine\)"\)/);
|
||||
// Two frames: account-dialog-provider focuses the close button in one.
|
||||
assert.match(effect, /requestAnimationFrame\(\(\) => \{\s*second = window\.requestAnimationFrame\(\(\) => redeemInput\.current\?\.focus\(\)\);/);
|
||||
assert.match(panel, /<Input\s+ref=\{redeemInput\}\s+id="billing-redeem-code"/);
|
||||
});
|
||||
|
||||
test("icon-only controls are named on hover on a desktop: the sidebar toggle and the collapsed avatar", () => {
|
||||
const ui = read("components/ui/sidebar.tsx");
|
||||
const trigger = ui.slice(ui.indexOf("export const SidebarTrigger"), ui.indexOf("export function SidebarRail"));
|
||||
assert.match(trigger, /if \(isMobile\) return button;/);
|
||||
assert.match(trigger, /<Tooltip\.Popup>\{label\}<\/Tooltip\.Popup>/);
|
||||
// 原值 "Collapse sidebar" / "Expand sidebar":读屏念英文。
|
||||
assert.match(ui, /const label = open \? "收起侧边栏" : "展开侧边栏";/);
|
||||
assert.doesNotMatch(ui, /const label = open \? "Collapse sidebar"/);
|
||||
const sidebar = read("components/app-sidebar.tsx");
|
||||
assert.match(sidebar, /withRailTooltip\(isCollapsedDesktop \? "账户" : null,/);
|
||||
assert.match(sidebar, /withHoverTooltip\(isMobile \? null : "点数与兑换码",/);
|
||||
});
|
||||
@@ -300,7 +300,8 @@ test("the same component renders read-only when `/` is not the one mounting it",
|
||||
// 新值:没有这种链接;弹窗项在每页都是按钮,交给外壳的 onOpenAccountDialog 原地打开
|
||||
// 原因:BUG-2127,账户弹窗从首页搬到 (app) 外壳(components/account-dialog-provider.tsx),每页原地打开,站外页不再先跳回聊天页
|
||||
assert.doesNotMatch(appSidebar, /accountDialogHref/);
|
||||
assert.match(appSidebar, /onOpenAccountDialog\?\.\(dialog, ownTriggerRef\.current\)/);
|
||||
// BUG-2361 原值:`onOpenAccountDialog?.(dialog, ownTriggerRef.current)` / 新值:多传 `options`(兑换码行的 tab)/ 原因:菜单加了直达 兑换码 的一行。
|
||||
assert.match(appSidebar, /onOpenAccountDialog\?\.\(dialog, ownTriggerRef\.current, options\)/);
|
||||
|
||||
// And nothing in read-only mode can write: the write callbacks only exist
|
||||
// inside `controls`, which the secondary layout never passes.
|
||||
|
||||
Reference in New Issue
Block a user