fix(webui): use styled tooltips for model presets and activity previews (#5701)
* fix(webui): show effective preset in styled model tooltip * fix(webui): use shared tooltip for activity previews
This commit is contained in:
1 parent
813aaaea05
commit
4c2c4396b0
5 files changed
+236
-125
No files matched your search
@@ -14,6 +14,7 @@ import {
|
|||||||
floatingItemFocusClassName,
|
floatingItemFocusClassName,
|
||||||
} from "@/components/ui/floating-surface";
|
} from "@/components/ui/floating-surface";
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||||
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
||||||
import { inferProviderFromModelName, providerBrand } from "@/lib/provider-brand";
|
import { inferProviderFromModelName, providerBrand } from "@/lib/provider-brand";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@@ -114,6 +115,7 @@ export function ModelPresetBadge({
|
|||||||
}: ModelPresetBadgeProps) {
|
}: ModelPresetBadgeProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const [tooltipOpen, setTooltipOpen] = useState(false);
|
||||||
const [motion, setMotion] = useState<PresetMotion | null>(null);
|
const [motion, setMotion] = useState<PresetMotion | null>(null);
|
||||||
const [motionWidth, setMotionWidth] = useState<number | null>(null);
|
const [motionWidth, setMotionWidth] = useState<number | null>(null);
|
||||||
const gestureRef = useRef<PresetGesture | null>(null);
|
const gestureRef = useRef<PresetGesture | null>(null);
|
||||||
@@ -135,11 +137,14 @@ export function ModelPresetBadge({
|
|||||||
const displayLabel = fallbackDisplayLabel || label;
|
const displayLabel = fallbackDisplayLabel || label;
|
||||||
const displayModelDetail = fallbackPreset
|
const displayModelDetail = fallbackPreset
|
||||||
? fallbackPreset.model
|
? fallbackPreset.model
|
||||||
: fallbackModelName
|
: fallbackModelName || modelDetail;
|
||||||
? null
|
|
||||||
: modelDetail;
|
|
||||||
const displayProvider = fallbackPreset?.provider
|
const displayProvider = fallbackPreset?.provider
|
||||||
|| (fallbackModelName ? inferProviderFromModelName(fallbackModelName) : provider);
|
|| (fallbackModelName ? inferProviderFromModelName(fallbackModelName) : provider);
|
||||||
|
const tooltipLabel = [...new Set([
|
||||||
|
displayLabel,
|
||||||
|
displayModelDetail,
|
||||||
|
fallbackModelName ? null : providerLabel,
|
||||||
|
].filter(Boolean))].join(" · ");
|
||||||
const presets = !activeName
|
const presets = !activeName
|
||||||
? modelPresets
|
? modelPresets
|
||||||
: listedIndex < 0
|
: listedIndex < 0
|
||||||
@@ -278,20 +283,19 @@ export function ModelPresetBadge({
|
|||||||
label={displayLabel}
|
label={displayLabel}
|
||||||
modelDetail={displayModelDetail}
|
modelDetail={displayModelDetail}
|
||||||
provider={displayProvider}
|
provider={displayProvider}
|
||||||
providerLabel={fallbackModelName ? null : providerLabel}
|
|
||||||
needsSetup={needsSetup}
|
needsSetup={needsSetup}
|
||||||
needsAttention={needsSetup && attentionRequest > 0}
|
needsAttention={needsSetup && attentionRequest > 0}
|
||||||
fallbackModelName={fallbackModelName}
|
fallbackModelName={fallbackModelName}
|
||||||
fallbackFromLabel={fallbackModelName ? label : null}
|
|
||||||
isHero={isHero}
|
isHero={isHero}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!canSwitch) {
|
const Container = opensSetup ? "button" : "span";
|
||||||
const Container = opensSetup ? "button" : "span";
|
const badge = !canSwitch ? (
|
||||||
return (
|
<TooltipTrigger asChild>
|
||||||
<Container
|
<Container
|
||||||
aria-label={fallbackModelName ? `${displayLabel} (fallback from ${label})` : label}
|
aria-label={displayLabel}
|
||||||
|
tabIndex={opensSetup ? undefined : 0}
|
||||||
type={opensSetup ? "button" : undefined}
|
type={opensSetup ? "button" : undefined}
|
||||||
onClick={opensSetup ? onClick : undefined}
|
onClick={opensSetup ? onClick : undefined}
|
||||||
className={cn(
|
className={cn(
|
||||||
@@ -302,10 +306,8 @@ export function ModelPresetBadge({
|
|||||||
>
|
>
|
||||||
{pill}
|
{pill}
|
||||||
</Container>
|
</Container>
|
||||||
);
|
</TooltipTrigger>
|
||||||
}
|
) : (
|
||||||
|
|
||||||
return (
|
|
||||||
<Popover
|
<Popover
|
||||||
open={open}
|
open={open}
|
||||||
onOpenChange={(nextOpen) => {
|
onOpenChange={(nextOpen) => {
|
||||||
@@ -314,86 +316,88 @@ export function ModelPresetBadge({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<button
|
<TooltipTrigger asChild>
|
||||||
type="button"
|
<button
|
||||||
data-switching={motion ? "true" : undefined}
|
type="button"
|
||||||
aria-label={label}
|
data-switching={motion ? "true" : undefined}
|
||||||
aria-expanded={open}
|
aria-label={displayLabel}
|
||||||
onPointerDown={handlePointerDown}
|
aria-expanded={open}
|
||||||
onPointerMove={handlePointerMove}
|
onPointerDown={handlePointerDown}
|
||||||
onPointerLeave={(event) => {
|
onPointerMove={handlePointerMove}
|
||||||
const gesture = gestureRef.current;
|
onPointerLeave={(event) => {
|
||||||
if (gesture && gesture.pointerId === event.pointerId && !gesture.active) clearGesture();
|
const gesture = gestureRef.current;
|
||||||
}}
|
if (gesture && gesture.pointerId === event.pointerId && !gesture.active) clearGesture();
|
||||||
onPointerUp={(event) => finishGesture(event, true)}
|
}}
|
||||||
onPointerCancel={(event) => finishGesture(event, false)}
|
onPointerUp={(event) => finishGesture(event, true)}
|
||||||
onLostPointerCapture={(event) => finishGesture(event, false)}
|
onPointerCancel={(event) => finishGesture(event, false)}
|
||||||
onContextMenu={(event) => {
|
onLostPointerCapture={(event) => finishGesture(event, false)}
|
||||||
if (gestureRef.current?.active) event.preventDefault();
|
onContextMenu={(event) => {
|
||||||
}}
|
if (gestureRef.current?.active) event.preventDefault();
|
||||||
onDragStart={(event) => event.preventDefault()}
|
}}
|
||||||
onKeyDown={handleKeyDown}
|
onDragStart={(event) => event.preventDefault()}
|
||||||
onClickCapture={(event) => {
|
onKeyDown={handleKeyDown}
|
||||||
if (!suppressClickRef.current) return;
|
onClickCapture={(event) => {
|
||||||
suppressClickRef.current = false;
|
if (!suppressClickRef.current) return;
|
||||||
event.preventDefault();
|
suppressClickRef.current = false;
|
||||||
event.stopPropagation();
|
event.preventDefault();
|
||||||
}}
|
event.stopPropagation();
|
||||||
style={{
|
}}
|
||||||
touchAction: "manipulation",
|
style={{
|
||||||
width: motionWidth ? `${motionWidth}px` : undefined,
|
touchAction: "manipulation",
|
||||||
}}
|
width: motionWidth ? `${motionWidth}px` : undefined,
|
||||||
className={cn(
|
}}
|
||||||
"thread-composer-model-badge group relative inline-flex w-fit min-w-0 max-w-[min(18rem,44vw)] cursor-pointer appearance-none border-0 bg-transparent p-0 shadow-none focus-visible:outline-none",
|
className={cn(
|
||||||
motion && "z-10 cursor-grabbing",
|
"thread-composer-model-badge group relative inline-flex w-fit min-w-0 max-w-[min(18rem,44vw)] cursor-pointer appearance-none border-0 bg-transparent p-0 shadow-none focus-visible:outline-none",
|
||||||
!motion && "cursor-grab",
|
motion && "z-10 cursor-grabbing",
|
||||||
isHero ? "h-8" : "h-9",
|
!motion && "cursor-grab",
|
||||||
)}
|
isHero ? "h-8" : "h-9",
|
||||||
>
|
)}
|
||||||
{motion ? (
|
>
|
||||||
<>
|
{motion ? (
|
||||||
<span data-testid="composer-model-pill-layout" className="invisible inline-flex h-full shrink-0" aria-hidden>
|
<>
|
||||||
{pill}
|
<span data-testid="composer-model-pill-layout" className="invisible inline-flex h-full shrink-0" aria-hidden>
|
||||||
</span>
|
{pill}
|
||||||
<span
|
|
||||||
data-testid="composer-model-pill-viewport"
|
|
||||||
className={cn(
|
|
||||||
"composer-model-pill-viewport pointer-events-none absolute -left-2 right-0 overflow-hidden bg-transparent",
|
|
||||||
isHero ? "-bottom-2.5 -top-2.5" : "-bottom-3 -top-3",
|
|
||||||
)}
|
|
||||||
aria-hidden
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
data-testid="composer-model-pill-track"
|
|
||||||
data-settling={motion.settling ? "true" : undefined}
|
|
||||||
className="composer-model-pill-track ml-auto flex w-[calc(100%-0.5rem)] flex-col items-end gap-1 will-change-transform"
|
|
||||||
onTransitionEnd={(event) => {
|
|
||||||
if (motion.settling && event.currentTarget === event.target) clearMotion();
|
|
||||||
}}
|
|
||||||
style={{
|
|
||||||
paddingTop: isHero ? "10px" : "12px",
|
|
||||||
transform: `translate3d(0, ${-pillStride * (2 + motion.remainder)}px, 0)`,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{PILL_OFFSETS.map((offset) => {
|
|
||||||
const preset = presets[wrapIndex(motion.index + offset, presets.length)];
|
|
||||||
return (
|
|
||||||
<PresetPill
|
|
||||||
key={motion.index + offset}
|
|
||||||
label={preset.name}
|
|
||||||
modelDetail={preset.model}
|
|
||||||
provider={preset.provider}
|
|
||||||
isHero={isHero}
|
|
||||||
offset={offset}
|
|
||||||
scale={motion.settling ? 1 : dockScale(offset - motion.remainder)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</span>
|
</span>
|
||||||
</span>
|
<span
|
||||||
</>
|
data-testid="composer-model-pill-viewport"
|
||||||
) : pill}
|
className={cn(
|
||||||
</button>
|
"composer-model-pill-viewport pointer-events-none absolute -left-2 right-0 overflow-hidden bg-transparent",
|
||||||
|
isHero ? "-bottom-2.5 -top-2.5" : "-bottom-3 -top-3",
|
||||||
|
)}
|
||||||
|
aria-hidden
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
data-testid="composer-model-pill-track"
|
||||||
|
data-settling={motion.settling ? "true" : undefined}
|
||||||
|
className="composer-model-pill-track ml-auto flex w-[calc(100%-0.5rem)] flex-col items-end gap-1 will-change-transform"
|
||||||
|
onTransitionEnd={(event) => {
|
||||||
|
if (motion.settling && event.currentTarget === event.target) clearMotion();
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
paddingTop: isHero ? "10px" : "12px",
|
||||||
|
transform: `translate3d(0, ${-pillStride * (2 + motion.remainder)}px, 0)`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{PILL_OFFSETS.map((offset) => {
|
||||||
|
const preset = presets[wrapIndex(motion.index + offset, presets.length)];
|
||||||
|
return (
|
||||||
|
<PresetPill
|
||||||
|
key={motion.index + offset}
|
||||||
|
label={preset.name}
|
||||||
|
modelDetail={preset.model}
|
||||||
|
provider={preset.provider}
|
||||||
|
isHero={isHero}
|
||||||
|
offset={offset}
|
||||||
|
scale={motion.settling ? 1 : dockScale(offset - motion.remainder)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
) : pill}
|
||||||
|
</button>
|
||||||
|
</TooltipTrigger>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent
|
<PopoverContent
|
||||||
align="end"
|
align="end"
|
||||||
@@ -448,6 +452,15 @@ export function ModelPresetBadge({
|
|||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TooltipProvider delayDuration={300} skipDelayDuration={80}>
|
||||||
|
<Tooltip open={tooltipOpen && !open && !motion} onOpenChange={setTooltipOpen}>
|
||||||
|
{badge}
|
||||||
|
<TooltipContent side="top">{tooltipLabel}</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function PresetOption({
|
function PresetOption({
|
||||||
@@ -495,11 +508,9 @@ function PresetPill({
|
|||||||
label,
|
label,
|
||||||
modelDetail,
|
modelDetail,
|
||||||
provider,
|
provider,
|
||||||
providerLabel,
|
|
||||||
needsSetup = false,
|
needsSetup = false,
|
||||||
needsAttention = false,
|
needsAttention = false,
|
||||||
fallbackModelName,
|
fallbackModelName,
|
||||||
fallbackFromLabel,
|
|
||||||
isHero,
|
isHero,
|
||||||
offset,
|
offset,
|
||||||
scale,
|
scale,
|
||||||
@@ -507,11 +518,9 @@ function PresetPill({
|
|||||||
label: string;
|
label: string;
|
||||||
modelDetail?: string | null;
|
modelDetail?: string | null;
|
||||||
provider?: string | null;
|
provider?: string | null;
|
||||||
providerLabel?: string | null;
|
|
||||||
needsSetup?: boolean;
|
needsSetup?: boolean;
|
||||||
needsAttention?: boolean;
|
needsAttention?: boolean;
|
||||||
fallbackModelName?: string | null;
|
fallbackModelName?: string | null;
|
||||||
fallbackFromLabel?: string | null;
|
|
||||||
isHero: boolean;
|
isHero: boolean;
|
||||||
offset?: number;
|
offset?: number;
|
||||||
scale?: number;
|
scale?: number;
|
||||||
@@ -521,10 +530,6 @@ function PresetPill({
|
|||||||
const inferredProvider = needsSetup
|
const inferredProvider = needsSetup
|
||||||
? null
|
? null
|
||||||
: provider || inferProviderFromModelName(modelDetail || label);
|
: provider || inferProviderFromModelName(modelDetail || label);
|
||||||
const title = [...new Set([label, modelDetail, providerLabel].filter(Boolean))].join(" · ");
|
|
||||||
const fallbackTitle = fallbackModelName
|
|
||||||
? `${fallbackFromLabel || label} · using ${fallbackModelName}`
|
|
||||||
: title;
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
const node = labelRef.current;
|
const node = labelRef.current;
|
||||||
@@ -541,7 +546,6 @@ function PresetPill({
|
|||||||
data-fallback={fallbackModelName ? "true" : undefined}
|
data-fallback={fallbackModelName ? "true" : undefined}
|
||||||
data-needs-setup={needsSetup ? "true" : undefined}
|
data-needs-setup={needsSetup ? "true" : undefined}
|
||||||
data-preset-offset={offset}
|
data-preset-offset={offset}
|
||||||
title={fallbackTitle || undefined}
|
|
||||||
className={cn(
|
className={cn(
|
||||||
"composer-model-badge composer-model-pill inline-flex h-full max-w-full min-w-0 shrink-0 items-center rounded-full border border-border/55 bg-card font-medium text-foreground/70",
|
"composer-model-badge composer-model-pill inline-flex h-full max-w-full min-w-0 shrink-0 items-center rounded-full border border-border/55 bg-card font-medium text-foreground/70",
|
||||||
"w-fit",
|
"w-fit",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { CSSProperties, ReactNode } from "react";
|
|||||||
import type { LucideIcon } from "lucide-react";
|
import type { LucideIcon } from "lucide-react";
|
||||||
|
|
||||||
import { StreamingLabelSheen } from "@/components/MessageBubble";
|
import { StreamingLabelSheen } from "@/components/MessageBubble";
|
||||||
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
export type ActivityStepTone = "neutral" | "active" | "success" | "error";
|
export type ActivityStepTone = "neutral" | "active" | "success" | "error";
|
||||||
@@ -33,6 +34,25 @@ export function ActivityStep({
|
|||||||
markerClassName,
|
markerClassName,
|
||||||
style,
|
style,
|
||||||
}: ActivityStepProps) {
|
}: ActivityStepProps) {
|
||||||
|
const line = (
|
||||||
|
<div
|
||||||
|
data-testid="activity-line"
|
||||||
|
tabIndex={typeof label === "string" ? 0 : undefined}
|
||||||
|
className="flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap"
|
||||||
|
>
|
||||||
|
<StreamingLabelSheen
|
||||||
|
active={active}
|
||||||
|
className={cn(
|
||||||
|
"min-w-0 flex-1 truncate font-medium",
|
||||||
|
tone === "error" ? "text-destructive/78" : "text-muted-foreground/85",
|
||||||
|
labelClassName,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</StreamingLabelSheen>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
data-testid="activity-step"
|
data-testid="activity-step"
|
||||||
@@ -65,22 +85,16 @@ export function ActivityStep({
|
|||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
<div className={cn("min-w-0", contentClassName)}>
|
<div className={cn("min-w-0", contentClassName)}>
|
||||||
<div
|
{typeof label === "string" ? (
|
||||||
data-testid="activity-line"
|
<TooltipProvider delayDuration={300} skipDelayDuration={80}>
|
||||||
title={typeof label === "string" ? label : undefined}
|
<Tooltip>
|
||||||
className="flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap"
|
<TooltipTrigger asChild>{line}</TooltipTrigger>
|
||||||
>
|
<TooltipContent side="top" className="max-w-[min(32rem,calc(100vw-2rem))] whitespace-pre-wrap break-words">
|
||||||
<StreamingLabelSheen
|
{label}
|
||||||
active={active}
|
</TooltipContent>
|
||||||
className={cn(
|
</Tooltip>
|
||||||
"min-w-0 flex-1 truncate font-medium",
|
</TooltipProvider>
|
||||||
tone === "error" ? "text-destructive/78" : "text-muted-foreground/85",
|
) : line}
|
||||||
labelClassName,
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</StreamingLabelSheen>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
import { ModelPresetBadge } from "@/components/thread/ModelPresetBadge";
|
||||||
|
|
||||||
|
const presets = [
|
||||||
|
{ name: "zhipu", model: "glm-5", provider: "zhipu" },
|
||||||
|
{ name: "codex", model: "openai-codex/gpt-5.5", provider: "openai_codex" },
|
||||||
|
];
|
||||||
|
|
||||||
|
describe("ModelPresetBadge fallback tooltip", () => {
|
||||||
|
it("shows only the effective preset on hover and preserves the preset picker", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
const onPresetChange = vi.fn();
|
||||||
|
const { container } = render(
|
||||||
|
<ModelPresetBadge
|
||||||
|
label="zhipu"
|
||||||
|
modelPreset="zhipu"
|
||||||
|
modelDetail="glm-5"
|
||||||
|
provider="zhipu"
|
||||||
|
modelPresets={presets}
|
||||||
|
fallbackModelName="openai-codex/gpt-5.5"
|
||||||
|
onPresetChange={onPresetChange}
|
||||||
|
isHero={false}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
const trigger = screen.getByRole("button", { name: "codex" });
|
||||||
|
expect(container.querySelector("[title]")).toBeNull();
|
||||||
|
await user.hover(trigger);
|
||||||
|
const tooltip = await screen.findByRole("tooltip");
|
||||||
|
expect(tooltip).toHaveTextContent("codex · openai-codex/gpt-5.5");
|
||||||
|
expect(tooltip).not.toHaveTextContent("zhipu");
|
||||||
|
await user.click(trigger);
|
||||||
|
expect(await screen.findByRole("listbox")).toBeInTheDocument();
|
||||||
|
await waitFor(() => expect(screen.queryByRole("tooltip")).not.toBeInTheDocument());
|
||||||
|
await user.click(screen.getByRole("option", { name: "codex" }));
|
||||||
|
expect(onPresetChange).toHaveBeenCalledWith("codex");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes the current preset to keyboard focus without a picker", async () => {
|
||||||
|
render(
|
||||||
|
<ModelPresetBadge
|
||||||
|
label="zhipu"
|
||||||
|
modelPresets={presets}
|
||||||
|
fallbackModelName="openai-codex/gpt-5.5"
|
||||||
|
isHero
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
const trigger = screen.getByLabelText("codex");
|
||||||
|
expect(trigger).toHaveAttribute("tabindex", "0");
|
||||||
|
fireEvent.focus(trigger);
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent(
|
||||||
|
"codex · openai-codex/gpt-5.5",
|
||||||
|
);
|
||||||
|
fireEvent.keyDown(trigger, { key: "Escape" });
|
||||||
|
await waitFor(() => expect(screen.queryByRole("tooltip")).not.toBeInTheDocument());
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { render, screen } from "@testing-library/react";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
import { expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { ReasoningRow } from "@/components/thread/activity/ReasoningRow";
|
||||||
|
|
||||||
|
it("shows the reasoning preview in the shared tooltip on hover and keyboard focus", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
const text = 'The user is saying "hi" again. I should respond in Chinese, concisely and in a friendly manner.';
|
||||||
|
const { container } = render(<ReasoningRow text={text} streaming={false} />);
|
||||||
|
const line = screen.getByTestId("activity-line");
|
||||||
|
|
||||||
|
expect(container.querySelector("[title]")).toBeNull();
|
||||||
|
await user.hover(line);
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent(text);
|
||||||
|
await user.unhover(line);
|
||||||
|
await user.tab();
|
||||||
|
expect(line).toHaveFocus();
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent(text);
|
||||||
|
await user.keyboard("{Escape}");
|
||||||
|
expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
@@ -784,8 +784,10 @@ describe("ThreadShell", () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(await screen.findByTitle("fast · gpt-5.5 · OpenAI Codex")).toBeInTheDocument();
|
fireEvent.focus(await screen.findByLabelText("fast"));
|
||||||
expect(screen.queryByTitle("Default · deepseek-v4-pro · DeepSeek")).not.toBeInTheDocument();
|
expect(await screen.findByRole("tooltip")).toHaveTextContent("fast · gpt-5.5 · OpenAI Codex");
|
||||||
|
fireEvent.blur(screen.getByLabelText("fast"));
|
||||||
|
expect(screen.queryByLabelText("Default")).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("falls back to the current preset while a renamed session reference is stale", async () => {
|
it("falls back to the current preset while a renamed session reference is stale", async () => {
|
||||||
@@ -809,7 +811,9 @@ describe("ThreadShell", () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(await screen.findByTitle("fast · gpt-5.5 · OpenAI Codex")).toBeInTheDocument();
|
fireEvent.focus(await screen.findByLabelText("fast"));
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent("fast · gpt-5.5 · OpenAI Codex");
|
||||||
|
fireEvent.blur(screen.getByLabelText("fast"));
|
||||||
expect(screen.queryByRole("button", { name: "Choose your AI" })).not.toBeInTheDocument();
|
expect(screen.queryByRole("button", { name: "Choose your AI" })).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -891,7 +895,9 @@ describe("ThreadShell", () => {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(await screen.findByTitle("fast · gpt-4 · Company Proxy")).toBeInTheDocument();
|
fireEvent.focus(await screen.findByLabelText("fast"));
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent("fast · gpt-4 · Company Proxy");
|
||||||
|
fireEvent.blur(screen.getByLabelText("fast"));
|
||||||
expect(screen.queryByRole("button", { name: "Choose your AI" })).not.toBeInTheDocument();
|
expect(screen.queryByRole("button", { name: "Choose your AI" })).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -943,10 +949,13 @@ describe("ThreadShell", () => {
|
|||||||
expect(screen.queryByText("Default")).not.toBeInTheDocument();
|
expect(screen.queryByText("Default")).not.toBeInTheDocument();
|
||||||
expect(screen.getByText("deepseek-chat")).toBeInTheDocument();
|
expect(screen.getByText("deepseek-chat")).toBeInTheDocument();
|
||||||
expect(badge).toHaveAttribute("data-fallback", "true");
|
expect(badge).toHaveAttribute("data-fallback", "true");
|
||||||
expect(badge).toHaveAttribute(
|
expect(badge).not.toHaveAttribute("title");
|
||||||
"title",
|
fireEvent.focus(screen.getByLabelText("deepseek-chat"));
|
||||||
"Default · using deepseek/deepseek-chat",
|
expect(await screen.findByRole("tooltip")).toHaveTextContent(
|
||||||
|
"deepseek-chat · deepseek/deepseek-chat",
|
||||||
);
|
);
|
||||||
|
expect(screen.getByRole("tooltip")).not.toHaveTextContent("Default");
|
||||||
|
fireEvent.blur(screen.getByLabelText("deepseek-chat"));
|
||||||
expect(logo).toBeInTheDocument();
|
expect(logo).toBeInTheDocument();
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
@@ -1328,7 +1337,9 @@ describe("ThreadShell", () => {
|
|||||||
await act(async () => {
|
await act(async () => {
|
||||||
rerender(view(session("chat-new", "fast")));
|
rerender(view(session("chat-new", "fast")));
|
||||||
});
|
});
|
||||||
expect(screen.getByTitle("fast · gpt-5.5 · OpenAI Codex")).toBeInTheDocument();
|
fireEvent.focus(await screen.findByLabelText("fast"));
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent("fast · gpt-5.5 · OpenAI Codex");
|
||||||
|
fireEvent.blur(screen.getByLabelText("fast"));
|
||||||
expect(screen.queryByText("Default")).not.toBeInTheDocument();
|
expect(screen.queryByText("Default")).not.toBeInTheDocument();
|
||||||
expect(client.sendMessage).not.toHaveBeenCalled();
|
expect(client.sendMessage).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user