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
@@ -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();
|
||||
expect(screen.queryByTitle("Default · deepseek-v4-pro · DeepSeek")).not.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.queryByLabelText("Default")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -943,10 +949,13 @@ describe("ThreadShell", () => {
|
||||
expect(screen.queryByText("Default")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("deepseek-chat")).toBeInTheDocument();
|
||||
expect(badge).toHaveAttribute("data-fallback", "true");
|
||||
expect(badge).toHaveAttribute(
|
||||
"title",
|
||||
"Default · using deepseek/deepseek-chat",
|
||||
expect(badge).not.toHaveAttribute("title");
|
||||
fireEvent.focus(screen.getByLabelText("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();
|
||||
|
||||
act(() => {
|
||||
@@ -1328,7 +1337,9 @@ describe("ThreadShell", () => {
|
||||
await act(async () => {
|
||||
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(client.sendMessage).not.toHaveBeenCalled();
|
||||
|
||||
|
||||
Reference in new issue
Block a user