Files
cc-switch/tests/utils/providerConfigUtils.baseUrl.test.ts
T
Jason c5efe0baaa feat(providers): add a search button to the provider page header
Provider search could only be opened with Cmd/Ctrl+F, so users with many
providers did not know it existed.

- Add a search button next to "Add provider" in the page header. It
  toggles the existing search panel; the panel closes when switching apps
  or leaving the provider page.
- Match the API address as well as name, notes, and website. The address
  is read from every app's settingsConfig shape by a new shared
  extractProviderBaseUrl, which ProviderCard now also uses.
- Only filter while the panel is open. Closing it with Esc used to leave
  the list silently filtered.
- Portal the search panel to document.body. As a child of the list's
  space-y container it counted as a sibling, so opening it pushed every
  provider card down by 1rem.
- Add a "Show provider search" setting (on by default, device-local).
  Hiding the button keeps the Cmd/Ctrl+F shortcut.
2026-10-09 21:50:56 +08:00

54 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { extractProviderBaseUrl } from "@/utils/providerConfigUtils";
describe("extractProviderBaseUrl", () => {
it.each([
[
"claude / claude-desktop",
{ env: { ANTHROPIC_BASE_URL: "https://claude.example.com" } },
"https://claude.example.com",
],
[
"gemini",
{ env: { GOOGLE_GEMINI_BASE_URL: "https://gemini.example.com" } },
"https://gemini.example.com",
],
[
"codex / grokbuild",
{
auth: {},
config: [
'model_provider = "custom"',
"",
"[model_providers.custom]",
'base_url = "https://codex.example.com/v1"',
].join("\n"),
},
"https://codex.example.com/v1",
],
[
"opencode / mcode",
{ options: { baseURL: "https://opencode.example.com/v1" } },
"https://opencode.example.com/v1",
],
[
"openclaw / pi",
{ baseUrl: "https://openclaw.example.com/v1" },
"https://openclaw.example.com/v1",
],
[
"hermes",
{ base_url: "https://hermes.example.com/v1" },
"https://hermes.example.com/v1",
],
])("reads the %s shape", (_app, settingsConfig, expected) => {
expect(extractProviderBaseUrl(settingsConfig)).toBe(expected);
});
it("returns undefined for official providers without an address", () => {
expect(extractProviderBaseUrl({ env: {} })).toBeUndefined();
expect(extractProviderBaseUrl({ auth: {}, config: "" })).toBeUndefined();
expect(extractProviderBaseUrl(undefined)).toBeUndefined();
});
});