дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
Option labels that come from agents, databases, build tools and user settings matched UI catalog keys by accident, so some were translated and others were not (reasoning effort showed 高 next to Extra high; an HTTP client environment named test showed as 测试 while prod stayed English). Mark these labels and descriptions verbatim: agent config values, model names and providers, the approval switch label, HTTP client environments, dependency scopes and Gradle configurations, chart columns, database schemas, data sources, warehouses and roles, custom scopes, and plugin setting options. Option headings stay localized. Fixes #6191
669 рядки
26 KiB
TypeScript
669 рядки
26 KiB
TypeScript
import { fireEvent, render, screen, within } from "@testing-library/react";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { AgentConfigOption } from "@/bindings";
|
|
import { useI18n } from "@/platform/i18n";
|
|
import { ConfigPickers, computeOverflowLayout, configPickerOptions } from "./ConfigPickers";
|
|
import { useAgents } from "./store";
|
|
|
|
beforeEach(() => {
|
|
useAgents.setState({ pinnedModels: [] });
|
|
});
|
|
|
|
const config = (values: AgentConfigOption["values"], category = "model"): AgentConfigOption => ({
|
|
id: "model",
|
|
name: "Model",
|
|
category,
|
|
description: null,
|
|
current: null,
|
|
via: "option",
|
|
values,
|
|
});
|
|
const value = (id: string, name = id, description: string | null = null) => ({ value: id, name, description });
|
|
|
|
describe("configPickerOptions", () => {
|
|
it("groups nested paths by their first provider and preserves the full value and description", () => {
|
|
expect(configPickerOptions(config([value("9router/cmc/Beam", "Beam display", "Fast")]))).toEqual([
|
|
{ value: "9router", label: "9router", verbatim: true, section: true },
|
|
{
|
|
value: "9router/cmc/Beam",
|
|
label: "Beam display",
|
|
verbatim: true,
|
|
detail: "cmc/Beam · Fast",
|
|
verbatimDetail: true,
|
|
keywords: "9router",
|
|
},
|
|
]);
|
|
});
|
|
it("shows the agent-reported model name without the repeated provider prefix and keeps the id as the detail", () => {
|
|
expect(
|
|
configPickerOptions(
|
|
config([
|
|
{ value: "opencode/beam-free", name: "opencode/Beam Free", description: null },
|
|
{ value: "opencode/big-pickle", name: "opencode/Big Pickle", description: null },
|
|
{ value: "opencode/hy4-flash-free", name: "opencode/hy4 flash Free", description: null },
|
|
]),
|
|
),
|
|
).toEqual([
|
|
{ value: "opencode", label: "opencode", verbatim: true, section: true },
|
|
{
|
|
value: "opencode/beam-free",
|
|
label: "Beam Free",
|
|
verbatim: true,
|
|
detail: "beam-free",
|
|
verbatimDetail: true,
|
|
keywords: "opencode",
|
|
},
|
|
{
|
|
value: "opencode/big-pickle",
|
|
label: "Big Pickle",
|
|
verbatim: true,
|
|
detail: "big-pickle",
|
|
verbatimDetail: true,
|
|
keywords: "opencode",
|
|
},
|
|
{
|
|
value: "opencode/hy4-flash-free",
|
|
label: "hy4 flash Free",
|
|
verbatim: true,
|
|
detail: "hy4-flash-free",
|
|
verbatimDetail: true,
|
|
keywords: "opencode",
|
|
},
|
|
]);
|
|
});
|
|
it("falls back to the compact id tail when the agent echoes the id as its name", () => {
|
|
expect(configPickerOptions(config([value("acme/ctx/big")]))).toEqual([
|
|
{ value: "acme", label: "acme", verbatim: true, section: true },
|
|
{
|
|
value: "acme/ctx/big",
|
|
label: "big",
|
|
verbatim: true,
|
|
detail: "ctx/big",
|
|
verbatimDetail: true,
|
|
keywords: "acme",
|
|
},
|
|
]);
|
|
});
|
|
it("keeps plain ids ungrouped even when the display name contains a slash", () => {
|
|
expect(configPickerOptions(config([value("plain", "Local / Beam", "Offline")]))).toEqual([
|
|
{ value: "plain", label: "Local / Beam", verbatim: true, detail: "Offline", verbatimDetail: true, keywords: "" },
|
|
]);
|
|
});
|
|
it("collects several providers in encounter order and preserves order inside each group", () => {
|
|
const options = configPickerOptions(
|
|
config([value("a/One"), value("b/Two"), value("a/Three"), value("plain"), value("__section__:a")]),
|
|
);
|
|
expect(options.map((o) => [o.value, !!o.section])).toEqual([
|
|
["plain", false],
|
|
["__section__:a", false],
|
|
["a", true],
|
|
["a/One", false],
|
|
["a/Three", false],
|
|
["b", true],
|
|
["b/Two", false],
|
|
]);
|
|
expect(options[3]?.detail).toBe("One");
|
|
});
|
|
it("leaves non-model option labels and descriptions intact", () => {
|
|
expect(configPickerOptions(config([value("a/One", "Custom", "Description")], "mode"))).toEqual([
|
|
{ value: "a/One", label: "Custom", verbatim: true, detail: "Description", verbatimDetail: true },
|
|
]);
|
|
});
|
|
it("places pinned models in a top Pinned section and prepends usageMultiplier to detail", () => {
|
|
const options = configPickerOptions(
|
|
config([
|
|
{ value: "gpt-6-sol", name: "GPT-6 Sol", description: "Medium cost", usageMultiplier: "1x" },
|
|
{
|
|
value: "gemini-4-carbon",
|
|
name: "Gemini 4 Carbon",
|
|
description: "Powerful · Medium cost",
|
|
usageMultiplier: "1x",
|
|
},
|
|
]),
|
|
["gemini-4-carbon"],
|
|
);
|
|
expect(options).toEqual([
|
|
{ value: "__pinned__", label: "Pinned", section: true },
|
|
{
|
|
value: "gemini-4-carbon",
|
|
label: "Gemini 4 Carbon",
|
|
verbatim: true,
|
|
detail: "1x · Powerful · Medium cost",
|
|
verbatimDetail: true,
|
|
keywords: "",
|
|
},
|
|
{ value: "__models__", label: "Models", section: true },
|
|
{
|
|
value: "gpt-6-sol",
|
|
label: "GPT-6 Sol",
|
|
verbatim: true,
|
|
detail: "1x · Medium cost",
|
|
verbatimDetail: true,
|
|
keywords: "",
|
|
},
|
|
]);
|
|
});
|
|
});
|
|
|
|
it("tucks Cursor approvals into the mode popup as a switch and sends the choice", () => {
|
|
const option = (id: string, category: string, values: string[]): AgentConfigOption => ({
|
|
id,
|
|
category,
|
|
name: category === "approval" ? "Approvals" : "Mode",
|
|
description: null,
|
|
via: "option",
|
|
current: values[0]!,
|
|
values: values.map((value) => ({
|
|
value,
|
|
name: value === "bypass" ? "Bypass approvals" : value,
|
|
description: null,
|
|
})),
|
|
});
|
|
const onChange = vi.fn();
|
|
const cfg = [
|
|
option("mode", "mode", ["Agent", "Plan", "Ask"]),
|
|
option("openidea.cursor.approval", "approval", ["ask", "bypass"]),
|
|
];
|
|
const { rerender } = render(<ConfigPickers config={cfg} onChange={onChange} />);
|
|
expect(screen.getByRole("button", { name: "Mode" })).toHaveTextContent("Agent");
|
|
expect(screen.queryByRole("button", { name: "Approvals" })).not.toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole("button", { name: "Mode" }));
|
|
fireEvent.click(screen.getByRole("switch", { name: "Bypass approvals" }));
|
|
expect(onChange).toHaveBeenCalledWith("openidea.cursor.approval", "bypass");
|
|
|
|
rerender(<ConfigPickers config={cfg} values={{ "openidea.cursor.approval": "bypass" }} onChange={onChange} />);
|
|
expect(screen.getByRole("button", { name: "Mode" })).toHaveTextContent("AgentBypass");
|
|
});
|
|
|
|
it("shows Allow All as a switch and sends on/off values", () => {
|
|
const onChange = vi.fn();
|
|
render(
|
|
<ConfigPickers
|
|
config={[
|
|
{
|
|
id: "allow_all",
|
|
name: "Allow All",
|
|
category: "permissions",
|
|
description: null,
|
|
current: "off",
|
|
via: "option",
|
|
values: [value("on", "On"), value("off", "Off")],
|
|
},
|
|
]}
|
|
onChange={onChange}
|
|
/>,
|
|
);
|
|
fireEvent.click(screen.getByRole("switch", { name: "Allow All" }));
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith("allow_all", "on");
|
|
});
|
|
|
|
it("shows Allow All inside the mode popup when both options exist", () => {
|
|
const onChange = vi.fn();
|
|
render(
|
|
<ConfigPickers
|
|
config={[
|
|
{
|
|
id: "mode",
|
|
name: "Mode",
|
|
category: "mode",
|
|
description: null,
|
|
current: "agent",
|
|
via: "option",
|
|
values: [value("agent", "Agent"), value("plan", "Plan"), value("autopilot", "Autopilot")],
|
|
},
|
|
{
|
|
id: "allow_all",
|
|
name: "Allow All",
|
|
category: "permissions",
|
|
description: null,
|
|
current: "off",
|
|
via: "option",
|
|
values: [value("on", "On"), value("off", "Off")],
|
|
},
|
|
]}
|
|
onChange={onChange}
|
|
/>,
|
|
);
|
|
fireEvent.click(screen.getByRole("button", { name: "Mode" }));
|
|
fireEvent.click(screen.getByRole("option", { name: "Plan" }));
|
|
expect(onChange).toHaveBeenNthCalledWith(1, "mode", "plan");
|
|
fireEvent.click(screen.getByRole("button", { name: "Mode" }));
|
|
fireEvent.click(screen.getByRole("switch", { name: "Allow All" }));
|
|
expect(onChange).toHaveBeenNthCalledWith(2, "allow_all", "on");
|
|
});
|
|
|
|
it("shows Codex's collaboration mode next to its approval mode and sends Plan", () => {
|
|
const onChange = vi.fn();
|
|
render(
|
|
<ConfigPickers
|
|
config={[
|
|
{
|
|
id: "mode",
|
|
name: "Mode",
|
|
category: "mode",
|
|
description: null,
|
|
current: "workspace-write",
|
|
via: "option",
|
|
values: [value("read-only", "Read-only"), value("workspace-write", "Workspace access")],
|
|
},
|
|
{
|
|
id: "collaboration_mode",
|
|
name: "Collaboration mode",
|
|
category: "collaboration_mode",
|
|
description: null,
|
|
current: "default",
|
|
via: "option",
|
|
values: [value("default", "Default"), value("plan", "Plan")],
|
|
},
|
|
]}
|
|
onChange={onChange}
|
|
/>,
|
|
);
|
|
expect(screen.getByRole("button", { name: "Collaboration mode" })).toHaveTextContent("Default");
|
|
fireEvent.click(screen.getByRole("button", { name: "Collaboration mode" }));
|
|
fireEvent.click(screen.getByRole("option", { name: "Plan" }));
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith("collaboration_mode", "plan");
|
|
});
|
|
|
|
it("sends the complete nested model id through ConfigPickers", () => {
|
|
const onChange = vi.fn();
|
|
render(<ConfigPickers config={[config([value("9router/cmc/Beam")])]} onChange={onChange} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Model" }));
|
|
fireEvent.click(screen.getByRole("option", { name: "Beamcmc/Beam" }));
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith("model", "9router/cmc/Beam");
|
|
});
|
|
|
|
it("lists ACP models by their reported names and sends the complete id", () => {
|
|
const onChange = vi.fn();
|
|
render(
|
|
<ConfigPickers
|
|
config={[
|
|
config([
|
|
{ value: "opencode/beam-free", name: "opencode/Beam Free", description: null },
|
|
{ value: "opencode/big-pickle", name: "opencode/Big Pickle", description: null },
|
|
]),
|
|
]}
|
|
onChange={onChange}
|
|
/>,
|
|
);
|
|
fireEvent.click(screen.getByRole("button", { name: "Model" }));
|
|
expect(screen.getByRole("option", { name: /Beam Free/ })).toHaveTextContent("beam-free");
|
|
fireEvent.click(screen.getByRole("option", { name: /Beam Free/ }));
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith("model", "opencode/beam-free");
|
|
});
|
|
|
|
it("edits secondary settings from the compact popup and restores focus when dismissed", () => {
|
|
const approval: AgentConfigOption = {
|
|
id: "approvals",
|
|
name: "Approvals",
|
|
category: "approval",
|
|
description: null,
|
|
current: "ask",
|
|
via: "option",
|
|
values: [value("ask", "Ask first"), value("bypass", "Bypass approvals")],
|
|
};
|
|
const onChange = vi.fn();
|
|
render(<ConfigPickers config={[approval]} values={{ approvals: "bypass" }} onChange={onChange} />);
|
|
const trigger = screen.getByRole("button", { name: "Agent settings" });
|
|
trigger.focus();
|
|
fireEvent.click(trigger);
|
|
const dialog = screen.getByRole("dialog", { name: "Agent settings" });
|
|
fireEvent.click(within(dialog).getByRole("button", { name: "Approvals" }));
|
|
fireEvent.click(screen.getByRole("option", { name: "Ask first" }));
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith("approvals", "ask");
|
|
expect(dialog).toBeInTheDocument();
|
|
fireEvent.keyDown(document, { key: "Escape" });
|
|
expect(screen.queryByRole("dialog", { name: "Agent settings" })).not.toBeInTheDocument();
|
|
expect(trigger).toHaveFocus();
|
|
});
|
|
|
|
describe("model settings", () => {
|
|
const copilotConfig = (effortLevels: string[] | null = ["low", "medium", "high", "xhigh"]): AgentConfigOption[] => [
|
|
{
|
|
id: "model",
|
|
name: "Model",
|
|
category: "model",
|
|
description: null,
|
|
current: "claude-sonnet-5.5",
|
|
via: "option",
|
|
values: [value("claude-sonnet-5.5", "Claude Sonnet 5.5", "1x"), value("gpt-6-sol", "GPT-6 Sol", "1x")],
|
|
},
|
|
...(effortLevels
|
|
? [
|
|
{
|
|
id: "reasoning_effort",
|
|
name: "Reasoning Effort",
|
|
category: "thought_level",
|
|
description: null,
|
|
current: "medium",
|
|
via: "option" as const,
|
|
values: effortLevels.map((lvl) => value(lvl, lvl === "xhigh" ? "XHigh" : lvl)),
|
|
},
|
|
]
|
|
: []),
|
|
{
|
|
id: "mode",
|
|
name: "Mode",
|
|
category: "mode",
|
|
description: null,
|
|
current: "https://agentclientprotocol.com/protocol/session-modes#agent",
|
|
via: "option",
|
|
values: [
|
|
value("https://agentclientprotocol.com/protocol/session-modes#agent", "Agent"),
|
|
value("https://agentclientprotocol.com/protocol/session-modes#plan", "Plan"),
|
|
],
|
|
},
|
|
{
|
|
id: "allow_all",
|
|
name: "Allow All",
|
|
category: "permissions",
|
|
description: null,
|
|
current: "on",
|
|
via: "option",
|
|
values: [value("on", "On"), value("off", "Off")],
|
|
},
|
|
];
|
|
|
|
it("keeps effort as a standalone setting when no model is available", () => {
|
|
render(
|
|
<ConfigPickers
|
|
config={[
|
|
{
|
|
id: "reasoning_effort",
|
|
name: "Reasoning Effort",
|
|
category: "thought_level",
|
|
description: null,
|
|
current: "medium",
|
|
via: "option",
|
|
values: [value("low"), value("medium")],
|
|
},
|
|
]}
|
|
onChange={vi.fn()}
|
|
/>,
|
|
);
|
|
expect(screen.getByRole("button", { name: "Reasoning Effort" })).toHaveTextContent("medium");
|
|
expect(screen.queryByRole("button", { name: "Agent settings" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("keeps effort with model settings and the mode with Allow All", () => {
|
|
const onChange = vi.fn();
|
|
render(<ConfigPickers config={copilotConfig()} onChange={onChange} />);
|
|
const model = screen.getByRole("button", { name: "Model" });
|
|
expect(model).toHaveTextContent("Claude Sonnet 5.5");
|
|
const settings = screen.getByRole("button", { name: "Model settings: medium" });
|
|
expect(screen.getByRole("button", { name: "Mode" })).toHaveTextContent("AgentAllow All");
|
|
fireEvent.click(settings);
|
|
const dialog = screen.getByRole("dialog", { name: "Model settings" });
|
|
const effort = within(dialog).getByRole("listbox", { name: "Effort Level" });
|
|
expect(within(effort).getByRole("option", { name: "medium" })).toHaveAttribute("aria-selected", "true");
|
|
fireEvent.click(within(effort).getByRole("option", { name: "XHigh" }));
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith("reasoning_effort", "xhigh");
|
|
// The only setting: choosing it closes the popup.
|
|
expect(screen.queryByRole("dialog", { name: "Model settings" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("renders effort levels consistently as a vertical list regardless of option count", () => {
|
|
const onChange = vi.fn();
|
|
const config = copilotConfig().map((o) =>
|
|
o.category === "thought_level"
|
|
? {
|
|
...o,
|
|
values: ["Low", "Medium", "High", "Extra high", "Max", "Ultra"].map((name) =>
|
|
value(name.toLowerCase().replace(" ", "-"), name),
|
|
),
|
|
current: "max",
|
|
}
|
|
: o,
|
|
);
|
|
render(<ConfigPickers config={config} onChange={onChange} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Model settings: Max" }));
|
|
const dialog = screen.getByRole("dialog", { name: "Model settings" });
|
|
expect(within(dialog).queryByRole("radiogroup")).not.toBeInTheDocument();
|
|
expect(within(dialog).queryByRole("button", { name: /Reasoning Effort/ })).not.toBeInTheDocument();
|
|
const levels = within(dialog).getByRole("listbox", { name: "Effort Level" });
|
|
expect(within(levels).getByRole("option", { name: /Max/ })).toHaveAttribute("aria-selected", "true");
|
|
// Clicking the already-selected value in a single-setting popup closes it without emitting a redundant change.
|
|
fireEvent.click(within(levels).getByRole("option", { name: /Max/ }));
|
|
expect(onChange).not.toHaveBeenCalled();
|
|
expect(screen.queryByRole("dialog", { name: "Model settings" })).not.toBeInTheDocument();
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Model settings: Max" }));
|
|
const reopened = screen.getByRole("dialog", { name: "Model settings" });
|
|
fireEvent.click(within(reopened).getByRole("option", { name: /Extra high/ }));
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith("reasoning_effort", "extra-high");
|
|
// The only setting: choosing it is done.
|
|
expect(screen.queryByRole("dialog", { name: "Model settings" })).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("keeps agent effort labels as written in every UI language", () => {
|
|
const previous = useI18n.getState().texts;
|
|
useI18n.setState({ texts: { ...previous, Low: "低", High: "高", Max: "最大值", "Effort Level": "推理强度" } });
|
|
try {
|
|
const config = copilotConfig().map((o) =>
|
|
o.category === "thought_level"
|
|
? {
|
|
...o,
|
|
values: ["Low", "Medium", "High", "Extra high", "Max", "Ultra"].map((name) =>
|
|
value(name.toLowerCase().replace(" ", "-"), name),
|
|
),
|
|
current: "high",
|
|
}
|
|
: o,
|
|
);
|
|
render(<ConfigPickers config={config} onChange={vi.fn()} />);
|
|
fireEvent.click(screen.getByRole("button", { name: /: High$/ }));
|
|
const levels = within(screen.getByRole("dialog")).getByRole("listbox", { name: "推理强度" });
|
|
expect(within(levels).getByRole("option", { name: "High" })).toHaveAttribute("aria-selected", "true");
|
|
for (const name of ["Low", "Medium", "Extra high", "Max", "Ultra"])
|
|
expect(within(levels).getByRole("option", { name })).toBeInTheDocument();
|
|
expect(within(levels).queryByText(/低|高|最大值/)).not.toBeInTheDocument();
|
|
} finally {
|
|
useI18n.setState({ texts: previous });
|
|
}
|
|
});
|
|
|
|
it("tucks Fast into the model popup", () => {
|
|
const config = [
|
|
...copilotConfig().filter((o) => o.category !== "thought_level"),
|
|
{
|
|
id: "fast",
|
|
name: "Fast",
|
|
category: "model_config",
|
|
description: null,
|
|
current: "false",
|
|
via: "option" as const,
|
|
values: [value("false", "Off"), value("true", "On")],
|
|
},
|
|
];
|
|
render(<ConfigPickers config={config} onChange={vi.fn()} />);
|
|
expect(screen.queryByRole("switch", { name: "Fast" })).not.toBeInTheDocument();
|
|
fireEvent.click(screen.getByRole("button", { name: "Model settings: Fast: Off" }));
|
|
const dialog = screen.getByRole("dialog", { name: "Model settings" });
|
|
expect(within(dialog).getByRole("switch", { name: "Fast" })).toHaveAttribute("aria-checked", "false");
|
|
});
|
|
|
|
it("keeps the model list to models and the settings chip to every model setting", () => {
|
|
const onChange = vi.fn();
|
|
const cfg = copilotConfig().map((o) =>
|
|
o.id === "model"
|
|
? {
|
|
...o,
|
|
values: o.values.map((v) =>
|
|
v.value === "claude-sonnet-5.5" ? { ...v, costCategory: "medium", description: "Balanced" } : v,
|
|
),
|
|
}
|
|
: o,
|
|
);
|
|
cfg.push({
|
|
id: "contextTier",
|
|
name: "Context Size",
|
|
category: "model_config",
|
|
description: null,
|
|
current: "long_context",
|
|
defaultValue: "default",
|
|
via: "option",
|
|
values: [value("default", "200K"), value("long_context", "1M")],
|
|
});
|
|
render(<ConfigPickers config={cfg} onChange={onChange} />);
|
|
const model = screen.getByRole("button", { name: "Model" });
|
|
expect(model).toHaveTextContent("Claude Sonnet 5.5");
|
|
const settings = screen.getByRole("button", { name: /^Model settings:/ });
|
|
expect(settings).toHaveTextContent("medium · 1M");
|
|
|
|
fireEvent.click(model);
|
|
const models = screen.getByRole("dialog", { name: "Model" });
|
|
expect(within(models).queryByText("Balanced")).not.toBeInTheDocument();
|
|
expect(within(models).getByText("Medium cost")).toBeVisible();
|
|
expect(within(models).queryByRole("radio")).not.toBeInTheDocument();
|
|
expect(within(models).queryByRole("button", { name: /^Configure/ })).not.toBeInTheDocument();
|
|
fireEvent.click(within(models).getAllByRole("button", { name: "Pin model" })[0]!);
|
|
const listbox = within(models).getByRole("listbox", { name: "Model" });
|
|
expect(within(listbox).getByText("Pinned")).toBeVisible();
|
|
expect(within(listbox).getByText("Models")).toBeVisible();
|
|
fireEvent.click(within(models).getByRole("option", { name: /GPT-6 Sol/ }));
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith("model", "gpt-6-sol");
|
|
expect(screen.queryByRole("dialog", { name: "Model" })).not.toBeInTheDocument();
|
|
|
|
onChange.mockClear();
|
|
fireEvent.click(settings);
|
|
const dialog = screen.getByRole("dialog", { name: "Model settings" });
|
|
expect(within(dialog).queryByRole("button", { name: "Back to models" })).not.toBeInTheDocument();
|
|
const effortList = within(dialog).getByRole("listbox", { name: "Effort Level" });
|
|
expect(within(effortList).getByRole("option", { name: "medium" })).toHaveAttribute("aria-selected", "true");
|
|
const contextList = within(dialog).getByRole("listbox", { name: "Context Size" });
|
|
expect(within(contextList).getByRole("option", { name: "1M" })).toHaveAttribute("aria-selected", "true");
|
|
fireEvent.click(within(contextList).getByRole("option", { name: "200K" }));
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith("contextTier", "default");
|
|
// Several settings: the popup stays for the next one.
|
|
expect(screen.getByRole("dialog", { name: "Model settings" })).toBeInTheDocument();
|
|
});
|
|
|
|
it("filters the model list and picks the highlighted model with the keyboard", () => {
|
|
const onChange = vi.fn();
|
|
render(<ConfigPickers config={copilotConfig()} onChange={onChange} />);
|
|
fireEvent.click(screen.getByRole("button", { name: "Model" }));
|
|
const search = screen.getByPlaceholderText("Search…");
|
|
expect(search).toHaveFocus();
|
|
fireEvent.change(search, { target: { value: "sol" } });
|
|
expect(screen.getAllByRole("option")).toHaveLength(1);
|
|
fireEvent.keyDown(search, { key: "ArrowDown" });
|
|
fireEvent.keyDown(search, { key: "Enter" });
|
|
expect(onChange).toHaveBeenLastCalledWith("model", "gpt-6-sol");
|
|
});
|
|
|
|
it("treats Cursor context option id as Context Size in chip summary and popup", () => {
|
|
const onChange = vi.fn();
|
|
const cfg = copilotConfig();
|
|
cfg.push({
|
|
id: "context",
|
|
name: "Context",
|
|
category: "model_config",
|
|
description: null,
|
|
current: "1m",
|
|
defaultValue: "300k",
|
|
via: "option",
|
|
values: [value("300k", "300K"), value("1m", "1M")],
|
|
});
|
|
render(<ConfigPickers config={cfg} onChange={onChange} />);
|
|
const settings = screen.getByRole("button", { name: /^Model settings:/ });
|
|
expect(settings).toHaveTextContent("medium · 1M");
|
|
fireEvent.click(settings);
|
|
const dialog = screen.getByRole("dialog", { name: "Model settings" });
|
|
const contextList = within(dialog).getByRole("listbox", { name: "Context Size" });
|
|
fireEvent.click(within(contextList).getByRole("option", { name: "300K" }));
|
|
expect(onChange).toHaveBeenCalledExactlyOnceWith("context", "300k");
|
|
});
|
|
|
|
it("keeps a plain model picker when the agent has no effort option", () => {
|
|
render(<ConfigPickers config={copilotConfig(null)} onChange={vi.fn()} />);
|
|
expect(screen.getByRole("button", { name: "Model" })).toHaveAttribute("aria-haspopup", "listbox");
|
|
});
|
|
|
|
it("omits off switches from multi-setting summaries and shows them concisely when on", () => {
|
|
const cfg = copilotConfig();
|
|
cfg.push(
|
|
{
|
|
id: "context",
|
|
name: "Context",
|
|
category: "model_config",
|
|
description: null,
|
|
current: "500k",
|
|
via: "option",
|
|
values: [value("500k", "500K")],
|
|
},
|
|
{
|
|
id: "fast",
|
|
name: "Fast",
|
|
category: "model_config",
|
|
description: null,
|
|
current: "false",
|
|
via: "option",
|
|
values: [value("false", "Off"), value("true", "Fast")],
|
|
},
|
|
);
|
|
const { rerender } = render(<ConfigPickers config={cfg} onChange={vi.fn()} />);
|
|
const settings = screen.getByRole("button", { name: /^Model settings:/ });
|
|
expect(settings).toHaveTextContent("medium · 500K");
|
|
expect(settings).toHaveAttribute("title", expect.stringContaining("Fast: Off"));
|
|
|
|
rerender(<ConfigPickers config={cfg} values={{ fast: "true" }} onChange={vi.fn()} />);
|
|
expect(screen.getByRole("button", { name: /^Model settings:/ })).toHaveTextContent("medium · 500K · Fast");
|
|
});
|
|
});
|
|
|
|
describe("computeOverflowLayout", () => {
|
|
const base = {
|
|
gap: 2,
|
|
fixedWidths: [38, 220], // agent icon + model/settings
|
|
secondaryWidths: [120, 90], // mode (with detail) + collaboration mode
|
|
detailWidth: 45,
|
|
detailIndex: 0,
|
|
menuWidth: 24,
|
|
};
|
|
|
|
it("keeps everything visible when the toolbar fits", () => {
|
|
// 38 + 220 + 120 + 90 + 3*2 = 474
|
|
expect(computeOverflowLayout({ ...base, available: 500 })).toEqual({
|
|
compactDetail: false,
|
|
collapsedCount: 0,
|
|
});
|
|
});
|
|
|
|
it("hides chip detail before collapsing any secondary picker", () => {
|
|
// 474 - 45 = 429
|
|
expect(computeOverflowLayout({ ...base, available: 440 })).toEqual({
|
|
compactDetail: true,
|
|
collapsedCount: 0,
|
|
});
|
|
});
|
|
|
|
it("collapses trailing secondary pickers one by one as space shrinks", () => {
|
|
// Keep mode (full 120) + menu (24): 38 + 220 + 120 + 24 + 3*2 = 408
|
|
expect(computeOverflowLayout({ ...base, available: 410 })).toEqual({
|
|
compactDetail: false,
|
|
collapsedCount: 1,
|
|
});
|
|
// Keep mode (compact 75) + menu (24): 38 + 220 + 75 + 24 + 3*2 = 363
|
|
expect(computeOverflowLayout({ ...base, available: 370 })).toEqual({
|
|
compactDetail: true,
|
|
collapsedCount: 1,
|
|
});
|
|
// Collapse all secondary pickers into the menu:
|
|
expect(computeOverflowLayout({ ...base, available: 320 })).toEqual({
|
|
compactDetail: false,
|
|
collapsedCount: 2,
|
|
});
|
|
});
|
|
|
|
it("does nothing when unmeasured (available <= 0) or when there are no secondary items", () => {
|
|
expect(computeOverflowLayout({ ...base, available: 0 })).toEqual({
|
|
compactDetail: false,
|
|
collapsedCount: 0,
|
|
});
|
|
expect(computeOverflowLayout({ ...base, available: 100, secondaryWidths: [] })).toEqual({
|
|
compactDetail: false,
|
|
collapsedCount: 0,
|
|
});
|
|
});
|
|
});
|